diff --git a/Makefile b/Makefile index 42da033..7e868da 100644 --- a/Makefile +++ b/Makefile @@ -34,9 +34,9 @@ assets: > media/css/snipt.css @cat media/js/src/account.js > media/js/src/account.min.js @cat media/js/src/snipts.js > media/js/src/snipts.min.js - @cat media/js/src/search.js > media/js/src/search.min.js @cat media/js/src/jobs.js > media/js/src/jobs.min.js @cat media/js/src/application.js > media/js/src/application.min.js + @cat media/js/src/team.js > media/js/src/team.min.js @cat media/js/src/modules/site.js > media/js/src/modules/site.min.js @cat media/js/src/modules/snipt.js > media/js/src/modules/snipt.min.js @cat media/js/src/pro.js > media/js/src/pro.min.js @@ -146,13 +146,16 @@ vagrant: @$(ssh-vagrant) '$(pm) rebuild_index --noinput;' pulldb: - # @ssh nick@snipt.net -p 55555 'sudo su -c "pg_dump snipt|gzip > /tmp/snipt.dump" postgres' - # @scp -q -P 55555 nick@snipt.net:/tmp/snipt.dump snipt.dump.gz - # @dropdb snipt + @ssh nick@snipt.net -p 55555 'sudo su -c "pg_dump snipt|gzip > /tmp/snipt.dump" postgres' + @scp -q -P 55555 nick@snipt.net:/tmp/snipt.dump snipt.dump.gz + @dropdb snipt @createdb snipt @cat snipt.dump.gz | gunzip | psql snipt @rm snipt.dump.gz +sass: + sass --sourcemap=none --watch -t compressed --scss media/css/style.scss:media/css/style.css + .PHONY: assets, \ db, \ deploy, \ @@ -162,5 +165,6 @@ pulldb: provision-vagrant, \ salt-server, \ salt-vagrant, \ + sass, \ server, \ vagrant diff --git a/accounts/models.py b/accounts/models.py index 1180607..1c242e6 100644 --- a/accounts/models.py +++ b/accounts/models.py @@ -1,7 +1,10 @@ +from annoying.functions import get_object_or_None from datetime import datetime from django.contrib.auth.models import User from django.db import models +from itertools import chain from snipts.models import Snipt +from teams.models import Team class UserProfile(models.Model): @@ -110,9 +113,37 @@ class UserProfile(models.Model): public=True).count() > 0 \ else False + @property + def is_a_team(self): + 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, 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/accounts/views.py b/accounts/views.py index d322c12..3446670 100644 --- a/accounts/views.py +++ b/accounts/views.py @@ -4,6 +4,7 @@ import stripe from annoying.decorators import ajax_request, render_to from django.conf import settings from django.contrib.auth.decorators import login_required +from django.core.mail import send_mail from snipts.models import Snipt @@ -30,6 +31,15 @@ def cancel_subscription(request): profile.stripe_id = None profile.save() + send_mail('[Snipt] User cancelled Pro: {}'.format(request.user.username), + """ + User: https://snipt.net/{} + Email: {} + """.format(request.user.username, request.user.email), + 'support@snipt.net', + ['nick@snipt.net'], + fail_silently=False) + return {'deleted': True} 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 %} {% if request.user.is_authenticated %} @@ -119,7 +143,7 @@ {{ request.user.username }} - {% if request.user.profile.is_pro %} + {% if request.user.profile.has_pro %} Pro {% else %} Basic member @@ -146,7 +170,7 @@ Account - {% if not request.user.profile.is_pro %} + {% if not request.user.profile.has_pro %}
  • @@ -198,7 +222,7 @@ {% block aside %}