Return-Path: X-Original-To: apmail-incubator-allura-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-allura-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id F0396E872 for ; Tue, 5 Mar 2013 22:42:11 +0000 (UTC) Received: (qmail 56113 invoked by uid 500); 5 Mar 2013 22:42:11 -0000 Delivered-To: apmail-incubator-allura-commits-archive@incubator.apache.org Received: (qmail 56064 invoked by uid 500); 5 Mar 2013 22:42:11 -0000 Mailing-List: contact allura-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: allura-dev@incubator.apache.org Delivered-To: mailing list allura-commits@incubator.apache.org Received: (qmail 55915 invoked by uid 99); 5 Mar 2013 22:42:11 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 05 Mar 2013 22:42:11 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 317BA83042A; Tue, 5 Mar 2013 22:42:11 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: tvansteenburgh@apache.org To: allura-commits@incubator.apache.org X-Mailer: ASF-Git Admin Mailer Subject: [42/50] [abbrv] git commit: [5453] Allowing to hide stats Message-Id: <20130305224211.317BA83042A@tyr.zones.apache.org> Date: Tue, 5 Mar 2013 22:42:11 +0000 (UTC) [5453] Allowing to hide stats Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/efc769c6 Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/efc769c6 Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/efc769c6 Branch: refs/heads/si/5453 Commit: efc769c69e0a0ab5f20b3191ed1814b53b135b08 Parents: 99814f4 Author: Stefano Invernizzi Authored: Sat Feb 16 13:01:52 2013 +0100 Committer: Tim Van Steenburgh Committed: Tue Mar 5 21:39:31 2013 +0000 ---------------------------------------------------------------------- Allura/allura/controllers/auth.py | 10 +++++++++ Allura/allura/ext/user_profile/user_main.py | 2 +- Allura/allura/lib/plugin.py | 8 +++++++ Allura/allura/lib/widgets/forms.py | 16 +++++++++++++++ Allura/allura/model/contrib_stats.py | 1 + Allura/allura/templates/user_preferences.html | 8 +++++++ .../forgeuserstats/controllers/userstats.py | 11 ++++++++++ .../forgeuserstats/templates/artifacts.html | 15 +++++++++++++- .../forgeuserstats/templates/commits.html | 15 +++++++++++++- ForgeUserStats/forgeuserstats/templates/index.html | 15 ++++++++++++- .../forgeuserstats/templates/tickets.html | 15 +++++++++++++- 11 files changed, 110 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/efc769c6/Allura/allura/controllers/auth.py ---------------------------------------------------------------------- diff --git a/Allura/allura/controllers/auth.py b/Allura/allura/controllers/auth.py index 8b0be12..e7031d0 100644 --- a/Allura/allura/controllers/auth.py +++ b/Allura/allura/controllers/auth.py @@ -58,6 +58,7 @@ class F(object): remove_inactive_period_form = forms.RemoveInactivePeriodForm() save_skill_form = forms.AddUserSkillForm() remove_skill_form = forms.RemoveSkillForm() + set_statistics = forms.StatsPreferencesForm() class AuthController(BaseController): @@ -657,6 +658,15 @@ class PreferencesController(BaseController): @expose() @require_post() + @validate(F.set_statistics, error_handler=index) + def set_statistics(self, **kw): + require_authenticated() + c.user.stats.visible = kw.get('visible', True) + flash('Your preferences about statistics were successfully updated!') + redirect('.#Statistics') + + @expose() + @require_post() def upload_sshkey(self, key=None): ap = plugin.AuthenticationProvider.get(request) try: http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/efc769c6/Allura/allura/ext/user_profile/user_main.py ---------------------------------------------------------------------- diff --git a/Allura/allura/ext/user_profile/user_main.py b/Allura/allura/ext/user_profile/user_main.py index 759f3f3..f3c3331 100644 --- a/Allura/allura/ext/user_profile/user_main.py +++ b/Allura/allura/ext/user_profile/user_main.py @@ -64,7 +64,7 @@ class UserProfileController(BaseController): user = c.project.user_project_of if not user: raise exc.HTTPNotFound() - if g.show_userstats: + if g.show_userstats and user.stats.visible: from forgeuserstats.main import ForgeUserStatsApp link, description = ForgeUserStatsApp.createlink(user) else: http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/efc769c6/Allura/allura/lib/plugin.py ---------------------------------------------------------------------- diff --git a/Allura/allura/lib/plugin.py b/Allura/allura/lib/plugin.py index dcbc36e..4ec29de 100644 --- a/Allura/allura/lib/plugin.py +++ b/Allura/allura/lib/plugin.py @@ -725,6 +725,14 @@ class ThemeProvider(object): return RemoveInactivePeriodForm() @LazyProperty + def statistics_form(self): + ''' + :return: None, or an easywidgets Form to render on the user preferences page + ''' + from allura.lib.widgets.forms import StatsPreferencesForm + return StatsPreferencesForm(action='/auth/prefs/set_statistics') + + @LazyProperty def add_trove_category(self): ''' :return: None, or an easywidgets Form to render on the page to create a http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/efc769c6/Allura/allura/lib/widgets/forms.py ---------------------------------------------------------------------- diff --git a/Allura/allura/lib/widgets/forms.py b/Allura/allura/lib/widgets/forms.py index f76eff3..c1a1d75 100644 --- a/Allura/allura/lib/widgets/forms.py +++ b/Allura/allura/lib/widgets/forms.py @@ -451,6 +451,22 @@ class RemoveTimeSlotForm(ForgeForm): d['endtime'] = V.convertTime(kw.get('endtime','')) return d + +class StatsPreferencesForm(ForgeForm): + defaults=dict(ForgeForm.defaults) + + class fields(ew_core.NameList): + visible = ew.Checkbox( + label='Make my personal statistics visible to other users.') + + def display(self, **kw): + if kw.get('user').stats.visible: + self.fields['visible'].attrs = {'checked':'true'} + else: + self.fields['visible'].attrs = {} + return super(ForgeForm, self).display(**kw) + + class RemoveTroveCategoryForm(ForgeForm): defaults=dict(ForgeForm.defaults, submit_text=None, show_errors=False) http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/efc769c6/Allura/allura/model/contrib_stats.py ---------------------------------------------------------------------- diff --git a/Allura/allura/model/contrib_stats.py b/Allura/allura/model/contrib_stats.py index 8a71d86..d9cada2 100644 --- a/Allura/allura/model/contrib_stats.py +++ b/Allura/allura/model/contrib_stats.py @@ -21,6 +21,7 @@ class Stats(MappedClass): _id=FieldProperty(S.ObjectId) + visible = FieldProperty(bool, if_missing = True) registration_date = FieldProperty(datetime) general = FieldProperty([dict( category = S.ObjectId, http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/efc769c6/Allura/allura/templates/user_preferences.html ---------------------------------------------------------------------- diff --git a/Allura/allura/templates/user_preferences.html b/Allura/allura/templates/user_preferences.html index be4dfe6..9947eff 100644 --- a/Allura/allura/templates/user_preferences.html +++ b/Allura/allura/templates/user_preferences.html @@ -129,6 +129,14 @@ + {% if g.show_userstats %} + +
+

Contribution statistics

+ {{g.theme.statistics_form.display(user=c.user)}} +
+ {% endif %} + {% if g.theme.password_change_form %}

Change Password

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/efc769c6/ForgeUserStats/forgeuserstats/controllers/userstats.py ---------------------------------------------------------------------- diff --git a/ForgeUserStats/forgeuserstats/controllers/userstats.py b/ForgeUserStats/forgeuserstats/controllers/userstats.py index b84eb0f..3944557 100644 --- a/ForgeUserStats/forgeuserstats/controllers/userstats.py +++ b/ForgeUserStats/forgeuserstats/controllers/userstats.py @@ -5,6 +5,7 @@ from allura.controllers import BaseController import allura.model as M from allura.lib.graphics.graphic_methods import create_histogram, create_progress_bar from forgeuserstats.model.stats import UserStats +from pylons import c class ForgeUserStatsController(BaseController): @@ -33,6 +34,8 @@ class ForgeUserStatsController(BaseController): if not self.user: return dict(user=None) stats = self.user.stats + if (not stats.visible) and (c.user != self.user): + return dict(user=self.user) ret_dict = _getDataForCategory(None, stats) ret_dict['user'] = self.user @@ -133,6 +136,8 @@ class ForgeUserStatsCatController(BaseController): if not self.user: return dict(user=None) stats = self.user.stats + if (not stats.visible) and (c.user != self.user): + return dict(user=self.user) cat_id = None if self.category: @@ -156,6 +161,8 @@ class ForgeUserStatsMetricController(BaseController): if not self.user: return dict(user=None) stats = self.user.stats + if (not stats.visible) and (c.user != self.user): + return dict(user=self.user) commits = stats.getCommitsByCategory() return dict(user = self.user, @@ -166,6 +173,8 @@ class ForgeUserStatsMetricController(BaseController): def artifacts(self, **kw): if not self.user: return dict(user=None) + if (not stats.visible) and (c.user != self.user): + return dict(user=self.user) stats = self.user.stats artifacts = stats.getArtifactsByCategory(detailed=True) @@ -176,6 +185,8 @@ class ForgeUserStatsMetricController(BaseController): def tickets(self, **kw): if not self.user: return dict(user=None) + if (not stats.visible) and (c.user != self.user): + return dict(user=self.user) artifacts = self.user.stats.getTicketsByCategory() return dict(user = self.user, data = artifacts) http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/efc769c6/ForgeUserStats/forgeuserstats/templates/artifacts.html ---------------------------------------------------------------------- diff --git a/ForgeUserStats/forgeuserstats/templates/artifacts.html b/ForgeUserStats/forgeuserstats/templates/artifacts.html index 9492628..d6a01d6 100644 --- a/ForgeUserStats/forgeuserstats/templates/artifacts.html +++ b/ForgeUserStats/forgeuserstats/templates/artifacts.html @@ -9,7 +9,7 @@ {% block content %} - {% if user %} + {% if user and (user.stats.visible or (c.user == user)) %} @@ -47,6 +47,19 @@
{% endif %} + {% else %} + {% if not user.stats.visible %} +

Statistics not available

+
+ This user has set his or her preferences so that personal statistics are not visible + to other users of the forge. +
+ {% else %} +

Invalid user

+
+ You are looking for personal statistics of a user which doesn't exist on this forge. Check your url. +
+ {% endif %} {% endif %} {% endblock %} http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/efc769c6/ForgeUserStats/forgeuserstats/templates/commits.html ---------------------------------------------------------------------- diff --git a/ForgeUserStats/forgeuserstats/templates/commits.html b/ForgeUserStats/forgeuserstats/templates/commits.html index 12f9712..cec0ab7 100644 --- a/ForgeUserStats/forgeuserstats/templates/commits.html +++ b/ForgeUserStats/forgeuserstats/templates/commits.html @@ -9,7 +9,7 @@ {% block content %} - {% if user %} + {% if user and (user.stats.visible or (c.user == user)) %} @@ -37,5 +37,18 @@ {% endif %} + {% else %} + {% if not user.stats.visible %} +

Statistics not available

+
+ This user has set his or her preferences so that personal statistics are not visible + to other users of the forge. +
+ {% else %} +

Invalid user

+
+ You are looking for personal statistics of a user which doesn't exist on this forge. Check your url. +
+ {% endif %} {% endif %} {% endblock %} http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/efc769c6/ForgeUserStats/forgeuserstats/templates/index.html ---------------------------------------------------------------------- diff --git a/ForgeUserStats/forgeuserstats/templates/index.html b/ForgeUserStats/forgeuserstats/templates/index.html index 37cd5da..4a8f504 100644 --- a/ForgeUserStats/forgeuserstats/templates/index.html +++ b/ForgeUserStats/forgeuserstats/templates/index.html @@ -11,7 +11,7 @@ {% endblock %} {% block content %} - {% if user %} + {% if user and (user.stats.visible or (c.user == user)) %} {% if category %}
    @@ -418,7 +418,18 @@

    {% endif %} {% else %} - Invalid user! + {% if not user.stats.visible %} +

    Statistics not available

    +
    + This user has set his or her preferences so that personal statistics are not visible + to other users of the forge. +
    + {% else %} +

    Invalid user

    +
    + You are looking for personal statistics of a user which doesn't exist on this forge. Check your url. +
    + {% endif %} {% endif %} {% endblock %} http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/efc769c6/ForgeUserStats/forgeuserstats/templates/tickets.html ---------------------------------------------------------------------- diff --git a/ForgeUserStats/forgeuserstats/templates/tickets.html b/ForgeUserStats/forgeuserstats/templates/tickets.html index 4604c16..6ee66d4 100644 --- a/ForgeUserStats/forgeuserstats/templates/tickets.html +++ b/ForgeUserStats/forgeuserstats/templates/tickets.html @@ -9,7 +9,7 @@ {% block content %} - {% if user %} + {% if user and (user.stats.visible or (c.user == user)) %} @@ -47,5 +47,18 @@ {% endif %} + {% else %} + {% if not user.stats.visible %} +

    Statistics not available

    +
    + This user has set his or her preferences so that personal statistics are not visible + to other users of the forge. +
    + {% else %} +

    Invalid user

    +
    + You are looking for personal statistics of a user which doesn't exist on this forge. Check your url. +
    + {% endif %} {% endif %} {% endblock %}