Lots of stuff around user.profile.has_pro, and further work on Teams.
parent
ee37f0479c
commit
aef665c14f
|
@ -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])
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
<li ng-class="{active: route.current.scope.section == 'Editor'}">
|
||||
<a href="/account/editor/">Editor</a>
|
||||
</li>
|
||||
<li ng-show="user.is_pro && user.stripe_id && user.stripe_id != 'COMP'" ng-class="{active: route.current.scope.section == 'Billing'}">
|
||||
<li ng-show="user.has_pro && user.stripe_id && user.stripe_id != 'COMP'" ng-class="{active: route.current.scope.section == 'Billing'}">
|
||||
<a href="/account/billing/">Billing</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -77,7 +77,7 @@
|
|||
<script type="text/javascript" src="//pagead2.googlesyndication.com/pagead/show_ads.js"></script>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if not blog_user.profile.is_pro %}
|
||||
{% if not blog_user.profile.has_pro %}
|
||||
<nav class="footer {% if sidebar %}with-sidebar{% endif %}">
|
||||
<ul class="powered">
|
||||
<li class="snipt"><a href="https://snipt.net/blogging/">Blog powered by Snipt</a></li>
|
||||
|
|
|
@ -174,7 +174,7 @@ if (typeof angular !== 'undefined') {
|
|||
AccountStorage.getAccount().then(function(response) {
|
||||
$scope.user = response.data;
|
||||
|
||||
if ($scope.user.is_pro && $scope.user.stripe_id && $scope.user.stripe_id !== 'COMP') {
|
||||
if ($scope.user.has_pro && $scope.user.stripe_id && $scope.user.stripe_id !== 'COMP') {
|
||||
AccountStorage.getStripeAccount().then(function(response) {
|
||||
$scope.user.stripeAccount = response.data;
|
||||
});
|
||||
|
|
|
@ -15,13 +15,13 @@
|
|||
</div>
|
||||
</div>
|
||||
<div ng-show="!cancelled">
|
||||
<div ng-show="!user.is_pro">
|
||||
<div ng-show="!user.has_pro">
|
||||
<p class="alert alert-info">
|
||||
You're not a Pro yet, so we have nothing to show you here.<br />
|
||||
<br /><a class="btn btn-success" href="/pro/">Signup for Pro »</a>
|
||||
</p>
|
||||
</div>
|
||||
<div ng-show="user.is_pro">
|
||||
<div ng-show="user.has_pro">
|
||||
<div class="def" data-title="Plan" ng-show="user.stripeAccount.status != 'inactive'">
|
||||
{[{ user.stripeAccount.name || 'Loading...' }]}
|
||||
</div>
|
||||
|
|
|
@ -17,9 +17,9 @@
|
|||
<div class="control-group" ng-class="{error: errors.blog_domain}">
|
||||
<label class="control-label" for="id_blog_domain">Blog domain:</label>
|
||||
<div class="controls">
|
||||
<input ng-disabled="!user.is_pro" id="id_blog_domain" type="text" ng-model="user.blog_domain" maxlength="250">
|
||||
<span ng-show="user.is_pro" class="help-block">Like 'snipt.nicksergeant.com' or 'nicksergeant.com' (without quotes). Set your CNAME to `snipt.net` or A-record to `96.126.110.160`. You can use multiple domains here: separate each domain with a space. The first domain will be your primary domain. All other domains will redirect to your primary domain.</span>
|
||||
<span ng-show="!user.is_pro" class="help-block"><a href="https://snipt.net/pro/">Go Pro</a> to enable a custom domain for your <a href="https://snipt.net/blogging/">Snipt blog</a>.</span>
|
||||
<input ng-disabled="!user.has_pro" id="id_blog_domain" type="text" ng-model="user.blog_domain" maxlength="250">
|
||||
<span ng-show="user.has_pro" class="help-block">Like 'snipt.nicksergeant.com' or 'nicksergeant.com' (without quotes). Set your CNAME to `snipt.net` or A-record to `96.126.110.160`. You can use multiple domains here: separate each domain with a space. The first domain will be your primary domain. All other domains will redirect to your primary domain.</span>
|
||||
<span ng-show="!user.has_pro" class="help-block"><a href="https://snipt.net/pro/">Go Pro</a> to enable a custom domain for your <a href="https://snipt.net/blogging/">Snipt blog</a>.</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -134,10 +134,10 @@
|
|||
$('div.alert-not-pro').hide();
|
||||
if ($checkbox.is(':checked')) {
|
||||
$label.removeClass('is-private').addClass('is-public');
|
||||
if (!window.user_is_pro) $('div.alert-not-pro').hide();
|
||||
if (!window.user_has_pro) $('div.alert-not-pro').hide();
|
||||
} else {
|
||||
$label.addClass('is-private').removeClass('is-public');
|
||||
if (!window.user_is_pro) $('div.alert-not-pro').show();
|
||||
if (!window.user_has_pro) $('div.alert-not-pro').show();
|
||||
}
|
||||
return false;
|
||||
}).change();
|
||||
|
@ -623,7 +623,7 @@
|
|||
};
|
||||
}
|
||||
|
||||
var is_pro = $user.siblings('span.pro').length ? true : false;
|
||||
var has_pro = $user.siblings('span.pro').length ? true : false;
|
||||
|
||||
var data = {
|
||||
code: $('textarea.raw', $el).text(),
|
||||
|
@ -651,7 +651,7 @@
|
|||
absolute_url: $user.attr('href'),
|
||||
username: $user.text(),
|
||||
profile: {
|
||||
is_pro: is_pro
|
||||
has_pro: has_pro
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -689,7 +689,7 @@
|
|||
user: {
|
||||
username: '',
|
||||
profile: {
|
||||
is_pro: window.user_is_pro
|
||||
has_pro: window.user_has_pro
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -145,7 +145,7 @@ class SniptValidation(Validation):
|
|||
def is_valid(self, bundle, request=None):
|
||||
errors = {}
|
||||
|
||||
if request.user.profile.is_pro is False:
|
||||
if request.user.profile.has_pro is False:
|
||||
if ('public' not in bundle.data or bundle.data['public'] is False):
|
||||
errors['not-pro'] = ("You'll need to go Pro "
|
||||
"(https://snipt.net/pro/) "
|
||||
|
@ -302,7 +302,7 @@ class PrivateUserProfileResource(ModelResource):
|
|||
bundle.data['username'] = bundle.obj.user.username
|
||||
bundle.data['user_id'] = bundle.obj.user.id
|
||||
bundle.data['api_key'] = bundle.obj.user.api_key.key
|
||||
bundle.data['is_pro'] = bundle.obj.user.profile.is_pro
|
||||
bundle.data['has_pro'] = bundle.obj.user.profile.has_pro
|
||||
return bundle
|
||||
|
||||
|
||||
|
@ -327,7 +327,7 @@ class PrivateUserResource(ModelResource):
|
|||
bundle.data['email_md5'] = hashlib \
|
||||
.md5(bundle.obj.email.lower()) \
|
||||
.hexdigest()
|
||||
bundle.data['is_pro'] = bundle.obj.profile.is_pro
|
||||
bundle.data['has_pro'] = bundle.obj.profile.has_pro
|
||||
bundle.data['stats'] = {
|
||||
'public_snipts': Snipt.objects.filter(user=bundle.obj.id,
|
||||
public=True).count(),
|
||||
|
|
|
@ -307,7 +307,7 @@ class Snipt(models.Model):
|
|||
if self.user == user:
|
||||
return True
|
||||
if self.user.profile.is_a_team:
|
||||
team = Team.objects.get(user=self.user)
|
||||
team = Team.objects.get(user=self.user, disabled=False)
|
||||
return team.user_is_member(user)
|
||||
return False
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@
|
|||
<section class="snipts" id="snipts">
|
||||
{% if not request.user.is_authenticated %}
|
||||
{% include 'ad-leaderboard-pro.html' %}
|
||||
{% elif not request.user.profile.teams_beta_seen and not request.user.team %}
|
||||
{% elif not request.user.profile.teams_beta_seen and not request.user.team and not request.user.profile.has_teams %}
|
||||
{% include 'ad-leaderboard-teams.html' %}
|
||||
{% endif %}
|
||||
{% with 'true' as detail %}
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
{% endif %}>
|
||||
{% if not request.user.is_authenticated %}
|
||||
{% include 'ad-leaderboard-pro.html' %}
|
||||
{% elif not request.user.profile.teams_beta_seen and not request.user.team %}
|
||||
{% elif not request.user.profile.teams_beta_seen and not request.user.team and not request.user.profile.has_teams %}
|
||||
{% include 'ad-leaderboard-teams.html' %}
|
||||
{% endif %}
|
||||
{% autopaginate snipts 10 %}
|
||||
|
|
|
@ -72,7 +72,7 @@
|
|||
<a href="<%= snipt.user.absolute_url %>">
|
||||
<%= snipt.user.username %>
|
||||
</a>
|
||||
<% if (window.user_is_pro) { %>
|
||||
<% if (window.user_has_pro) { %>
|
||||
<span class="pro"><a href="/pro/">Pro</a></span>
|
||||
<% } %>
|
||||
</li>
|
||||
|
|
|
@ -180,7 +180,7 @@
|
|||
<a href="{{ snipt.user.get_absolute_url }}">{{ snipt.user.username }}</a>
|
||||
{% if snipt.user.profile.is_a_team %}
|
||||
<span class="pro"><a href="/for-teams/">Team</a></span>
|
||||
{% elif snipt.user.profile.is_pro %}
|
||||
{% elif snipt.user.profile.has_pro %}
|
||||
<span class="pro"><a href="/pro/">Pro</a></span>
|
||||
{% endif %}
|
||||
{% if snipt.user.profile.gittip_username %}
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('teams', '0006_team_plan'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='team',
|
||||
name='disabled',
|
||||
field=models.BooleanField(default=False),
|
||||
),
|
||||
]
|
|
@ -0,0 +1,19 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('teams', '0007_team_disabled'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='team',
|
||||
name='plan',
|
||||
field=models.CharField(default=b'snipt-teams-25-monthly', max_length=100, null=True, blank=True, choices=[(b'snipt-teams-25-monthly', b'25 users, monthly'), (b'snipt-teams-100-monthly', b'100 users, monthly'), (b'snipt-teams-250-monthly', b'250 users, monthly'), (b'snipt-teams-unlimited-monthly', b'Unlimited users, monthly'), (b'snipt-teams-25-yearly', b'25 users, yearly'), (b'snipt-teams-100-yearly', b'100 users, yearly'), (b'snipt-teams-250-yearly', b'250 users, yearly'), (b'snipt-teams-unlimited-yearly', b'Unlimited users, yearly')]),
|
||||
),
|
||||
]
|
|
@ -24,7 +24,8 @@ class Team(models.Model):
|
|||
stripe_id = models.CharField(max_length=100, null=True, blank=True)
|
||||
user = models.OneToOneField(User, blank=True, null=True)
|
||||
plan = models.CharField(max_length=100, default='snipt-teams-25-monthly',
|
||||
choices=PLANS)
|
||||
choices=PLANS, blank=True, null=True)
|
||||
disabled = models.BooleanField(default=False)
|
||||
|
||||
created = models.DateTimeField(auto_now_add=True, editable=False)
|
||||
modified = models.DateTimeField(auto_now=True, editable=False)
|
||||
|
|
|
@ -24,9 +24,11 @@
|
|||
<li class="active">
|
||||
<a href="/{{ team.slug }}/members/">Members</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="/{{ team.slug }}/billing/">Billing</a>
|
||||
</li>
|
||||
{% if team.owner == request.user %}
|
||||
<li>
|
||||
<a href="/{{ team.slug }}/billing/">Billing</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</aside>
|
||||
<section class="content">
|
||||
|
|
|
@ -23,7 +23,7 @@ def for_teams(request):
|
|||
@login_required
|
||||
@render_to('teams/team-billing.html')
|
||||
def team_billing(request, username):
|
||||
team = get_object_or_404(Team, slug=username)
|
||||
team = get_object_or_404(Team, slug=username, disabled=False)
|
||||
if team.owner != request.user:
|
||||
raise Http404
|
||||
return {
|
||||
|
@ -34,7 +34,7 @@ def team_billing(request, username):
|
|||
@login_required
|
||||
@render_to('teams/team-members.html')
|
||||
def team_members(request, username):
|
||||
team = get_object_or_404(Team, slug=username)
|
||||
team = get_object_or_404(Team, slug=username, disabled=False)
|
||||
if not team.user_is_member(request.user):
|
||||
raise Http404
|
||||
return {
|
||||
|
@ -44,7 +44,7 @@ def team_members(request, username):
|
|||
|
||||
@login_required
|
||||
def add_team_member(request, username, member):
|
||||
team = get_object_or_404(Team, slug=username)
|
||||
team = get_object_or_404(Team, slug=username, disabled=False)
|
||||
user = get_object_or_404(User, username=member)
|
||||
|
||||
if (team.owner != request.user):
|
||||
|
@ -60,7 +60,7 @@ def add_team_member(request, username, member):
|
|||
|
||||
@login_required
|
||||
def remove_team_member(request, username, member):
|
||||
team = get_object_or_404(Team, slug=username)
|
||||
team = get_object_or_404(Team, slug=username, disabled=False)
|
||||
user = get_object_or_404(User, username=member)
|
||||
|
||||
if (team.owner != request.user):
|
||||
|
|
|
@ -68,7 +68,7 @@
|
|||
<script src="https://www.google.com/recaptcha/api.js"></script>
|
||||
|
||||
</head>
|
||||
<body class="{% block body-class %}{% endblock %} {% if request.user.profile.is_pro %}is-pro{% endif %}" ng-controller="AppController">
|
||||
<body class="{% block body-class %}{% endblock %} {% if request.user.profile.has_pro %}is-pro{% endif %}" ng-controller="AppController">
|
||||
|
||||
{% block header %}
|
||||
<header class="main">
|
||||
|
@ -141,7 +141,7 @@
|
|||
<span class="username">{{ request.user.username }}</span>
|
||||
<i class="icon-cog icon-white"></i>
|
||||
<span class="type">
|
||||
{% if request.user.profile.is_pro %}
|
||||
{% if request.user.profile.has_pro %}
|
||||
<span class="is-pro">Pro</span>
|
||||
{% else %}
|
||||
Basic member
|
||||
|
@ -168,7 +168,7 @@
|
|||
Account
|
||||
</a>
|
||||
</li>
|
||||
{% if not request.user.profile.is_pro %}
|
||||
{% if not request.user.profile.has_pro %}
|
||||
<li>
|
||||
<a href="/pro/">
|
||||
<i class="icon-star-empty icon-white"></i>
|
||||
|
@ -220,7 +220,7 @@
|
|||
{% block aside %}
|
||||
<aside class="main">
|
||||
{% block ad %}
|
||||
{% if not request.user.profile.is_pro %}
|
||||
{% if not request.user.profile.has_pro %}
|
||||
{% include 'ad-sidebar.html' %}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
@ -234,7 +234,7 @@
|
|||
<li class="twitter">
|
||||
<a href="https://twitter.com/#!/snipt"><span>@snipt</span></a>
|
||||
</li>
|
||||
{% if not request.user.profile.is_pro %}
|
||||
{% if not request.user.profile.has_pro %}
|
||||
<li class="pro">
|
||||
<a href="/pro/"><span>Go Pro</span></a>
|
||||
</li>
|
||||
|
@ -395,10 +395,10 @@
|
|||
|
||||
window.api_key = '{{ request.user.api_key.key }}';
|
||||
{% endblock %}
|
||||
{% if request.user.profile.is_pro %}
|
||||
window.user_is_pro = true;
|
||||
{% if request.user.profile.has_pro %}
|
||||
window.user_has_pro = true;
|
||||
{% else %}
|
||||
window.user_is_pro = false;
|
||||
window.user_has_pro = false;
|
||||
{% endif %}
|
||||
window.default_editor = '{{ request.user.profile.get_default_editor_display|lower }}';
|
||||
window.editor_theme = '{{ request.user.profile.editor_theme }}';
|
||||
|
@ -456,7 +456,7 @@
|
|||
custom_data: {
|
||||
'snipts count': {% snipts_count_for_user %},
|
||||
'profile link': 'https://snipt.net/{{ request.user.username }}/',
|
||||
'is pro': window.user_is_pro,
|
||||
'is pro': window.user_has_pro,
|
||||
'blog domain': '{{ request.user.profile.blog_domain }}',
|
||||
'pro date': {% firstof request.user.profile.pro_date|date:"U" 'null' %},
|
||||
'username': '{{ request.user.username }}'
|
||||
|
@ -493,7 +493,7 @@
|
|||
userId: {{ request.user.id }},
|
||||
createdAt: '{{ request.user.date_joined }}',
|
||||
sniptsCount: {% snipts_count_for_user %},
|
||||
isPro: window.user_is_pro,
|
||||
isPro: window.user_has_pro,
|
||||
blogDomain: '{{ request.user.profile.blog_domain }}',
|
||||
proDate: '{% firstof request.user.profile.pro_date 'null' %}'
|
||||
});
|
||||
|
|
|
@ -46,7 +46,7 @@
|
|||
To go <span class="pro">Pro</span>, <a href="/signup/?next=/pro/">sign up</a> or <a href="/login/?next=/pro/">log in</a>.
|
||||
</span>
|
||||
</div>
|
||||
{% elif request.user.profile.is_pro %}
|
||||
{% elif request.user.profile.has_pro %}
|
||||
<div class="login-first">
|
||||
<span>
|
||||
You're already a <span class="pro">Pro</span>.
|
||||
|
|
|
@ -65,7 +65,7 @@
|
|||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% if user.profile.is_pro %}
|
||||
{% if user.profile.has_pro %}
|
||||
<a class="pro" href="/pro/">Pro</a>
|
||||
{% endif %}
|
||||
{% if user.profile.gittip_username %}
|
||||
|
|
Loading…
Reference in New Issue