From aef665c14f589f81833004e760759ab6ab88d2e3 Mon Sep 17 00:00:00 2001 From: Nick Sergeant Date: Sun, 18 Oct 2015 21:07:01 -0400 Subject: [PATCH] Lots of stuff around user.profile.has_pro, and further work on Teams. --- accounts/models.py | 25 ++++++++++++++++--- accounts/templates/account.html | 2 +- blogs/middleware.py | 1 + .../templates/blogs/themes/default/base.html | 2 +- media/js/src/account.js | 2 +- media/js/src/modules/partials/billing.html | 4 +-- media/js/src/modules/partials/blogging.html | 6 ++--- media/js/src/modules/snipt.js | 10 ++++---- snipts/api.py | 6 ++--- snipts/models.py | 2 +- snipts/templates/snipts/detail.html | 2 +- snipts/templates/snipts/list.html | 2 +- .../templates/snipts/snipt-js-template.html | 2 +- snipts/templates/snipts/snipt-list.html | 2 +- teams/migrations/0007_team_disabled.py | 19 ++++++++++++++ teams/migrations/0008_auto_20151018_2053.py | 19 ++++++++++++++ teams/models.py | 3 ++- teams/templates/teams/team-members.html | 8 +++--- teams/views.py | 8 +++--- templates/base.html | 20 +++++++-------- templates/pro.html | 2 +- templates/profile.html | 2 +- 22 files changed, 105 insertions(+), 44 deletions(-) create mode 100644 teams/migrations/0007_team_disabled.py create mode 100644 teams/migrations/0008_auto_20151018_2053.py diff --git a/accounts/models.py b/accounts/models.py index b9cd09b..1c242e6 100644 --- a/accounts/models.py +++ b/accounts/models.py @@ -115,16 +115,35 @@ class UserProfile(models.Model): @property def is_a_team(self): - return True if get_object_or_None(Team, user=self.user) else False + if get_object_or_None(Team, user=self.user, disabled=False): + return True + else: + return False def teams(self): - teams_owned = Team.objects.filter(owner=self.user) - teams_in = Team.objects.filter(members=self.user) + teams_owned = Team.objects.filter(owner=self.user, disabled=False) + teams_in = Team.objects.filter(members=self.user, disabled=False) return list(chain(teams_owned, teams_in)) + @property + def has_teams(self): + if (len(self.teams()) > 0): + return True + else: + return False + def get_account_age(self): delta = datetime.now().replace(tzinfo=None) - \ self.user.date_joined.replace(tzinfo=None) return delta.days + @property + def has_pro(self): + if (self.is_pro or + self.has_teams or + self.is_a_team): + return True + else: + return False + User.profile = property(lambda u: UserProfile.objects.get_or_create(user=u)[0]) diff --git a/accounts/templates/account.html b/accounts/templates/account.html index 29a9377..5dbab94 100644 --- a/accounts/templates/account.html +++ b/accounts/templates/account.html @@ -26,7 +26,7 @@
  • Editor
  • -
  • +
  • Billing
  • diff --git a/blogs/middleware.py b/blogs/middleware.py index 644032c..f630740 100644 --- a/blogs/middleware.py +++ b/blogs/middleware.py @@ -34,6 +34,7 @@ class BlogMiddleware: get_object_or_404(User, username__iexact=blog_user) if request.blog_user is None: + # TODO: This needs to check profile.has_pro() instead. pro_users = User.objects.filter(userprofile__is_pro=True) for pro_user in pro_users: diff --git a/blogs/templates/blogs/themes/default/base.html b/blogs/templates/blogs/themes/default/base.html index 4ca2dea..8e348af 100644 --- a/blogs/templates/blogs/themes/default/base.html +++ b/blogs/templates/blogs/themes/default/base.html @@ -77,7 +77,7 @@ {% endif %} - {% if not blog_user.profile.is_pro %} + {% if not blog_user.profile.has_pro %}