From ae1d532c063e38cd600813b375a829c1da0c051e Mon Sep 17 00:00:00 2001 From: Nick Sergeant Date: Thu, 15 Oct 2015 22:37:54 -0400 Subject: [PATCH] Teams work. --- teams/migrations/0006_team_plan.py | 19 +++++++++ teams/models.py | 32 ++++++++++++++ teams/templates/teams/for-teams.html | 10 ++--- teams/templates/teams/team-billing.html | 56 +++++++++++++++++++++++++ teams/templates/teams/team-members.html | 29 ++++++++++++- teams/urls.py | 5 ++- teams/views.py | 13 +++++- 7 files changed, 155 insertions(+), 9 deletions(-) create mode 100644 teams/migrations/0006_team_plan.py create mode 100644 teams/templates/teams/team-billing.html diff --git a/teams/migrations/0006_team_plan.py b/teams/migrations/0006_team_plan.py new file mode 100644 index 0000000..7bf5c10 --- /dev/null +++ b/teams/migrations/0006_team_plan.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('teams', '0005_auto_20150930_2124'), + ] + + operations = [ + migrations.AddField( + model_name='team', + name='plan', + field=models.CharField(default=b'snipt-teams-25-monthly', max_length=100, 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')]), + ), + ] diff --git a/teams/models.py b/teams/models.py index 1e9cc53..754e44b 100644 --- a/teams/models.py +++ b/teams/models.py @@ -4,6 +4,18 @@ from snipts.utils import slugify_uniquely class Team(models.Model): + + PLANS = ( + ('snipt-teams-25-monthly', '25 users, monthly'), + ('snipt-teams-100-monthly', '100 users, monthly'), + ('snipt-teams-250-monthly', '250 users, monthly'), + ('snipt-teams-unlimited-monthly', 'Unlimited users, monthly'), + ('snipt-teams-25-yearly', '25 users, yearly'), + ('snipt-teams-100-yearly', '100 users, yearly'), + ('snipt-teams-250-yearly', '250 users, yearly'), + ('snipt-teams-unlimited-yearly', 'Unlimited users, yearly'), + ) + email = models.EmailField(max_length=255) members = models.ManyToManyField(User, related_name='member', blank=True) name = models.CharField(max_length=30) @@ -11,6 +23,8 @@ class Team(models.Model): slug = models.SlugField(max_length=255, blank=True) 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) created = models.DateTimeField(auto_now_add=True, editable=False) modified = models.DateTimeField(auto_now=True, editable=False) @@ -22,3 +36,21 @@ class Team(models.Model): def __unicode__(self): return self.name + + @property + def member_limit(self): + plan_map = { + 'snipt-teams-25-monthly': 25, + 'snipt-teams-100-monthly': 100, + 'snipt-teams-250-monthly': 250, + 'snipt-teams-unlimited-monthly': float('inf'), + 'snipt-teams-25-yearly': 25, + 'snipt-teams-100-yearly': 100, + 'snipt-teams-250-yearly': 250, + 'snipt-teams-unlimited-yearly': float('inf') + } + + if plan_map[self.plan] == float('inf'): + return 'Unlimited' + else: + return plan_map[self.plan] diff --git a/teams/templates/teams/for-teams.html b/teams/templates/teams/for-teams.html index e85f462..ef8e24e 100644 --- a/teams/templates/teams/for-teams.html +++ b/teams/templates/teams/for-teams.html @@ -37,7 +37,7 @@
  • Public team posts are public to the world, as they are now.
  • Private team posts are editable by all team members.
  • All team members are automatically granted personal Pro accounts.
  • -
  • Plans from $49/month, all with a 7-day free trial.
  • +
  • Plans from $49/month, all with a 14-day free trial.
  • {% if not request.user.is_authenticated %} @@ -61,7 +61,7 @@
    - +

    For billing and your team's Gravatar. Will remain private.

    @@ -72,12 +72,12 @@
    diff --git a/teams/templates/teams/team-billing.html b/teams/templates/teams/team-billing.html new file mode 100644 index 0000000..1ef1158 --- /dev/null +++ b/teams/templates/teams/team-billing.html @@ -0,0 +1,56 @@ +{% extends "base.html" %} + +{% block page-title %}Team Billing{% endblock %} + +{% block body-class %}account {{ block.super }}{% endblock %} + +{% block breadcrumb %} +
  • {{ team.user.username }}
  • + /
  • Billing
  • +{% endblock %} + +{% block content %} +
    +
    + +
    +
    + 25 users +
    +
    + $49.00 USD / month +
    +
    + xxxx-xxxx-xxxx-4242 +
    +
    + Active +
    +
    + August 29, 2015 +
    +
    + November 29, 2015 +
    +

    + Cancel subscription +

    +
    +
    +{% endblock %} + +{% block analytics %} + {% if not debug %} + window.ll('tagScreen', 'Team billing view'); + {% endif %} +{% endblock %} diff --git a/teams/templates/teams/team-members.html b/teams/templates/teams/team-members.html index da10f2a..cfc9fee 100644 --- a/teams/templates/teams/team-members.html +++ b/teams/templates/teams/team-members.html @@ -2,7 +2,7 @@ {% block page-title %}Team Members{% endblock %} -{% block body-class %}{{ block.super }}{% endblock %} +{% block body-class %}account {{ block.super }}{% endblock %} {% block breadcrumb %}
  • {{ team.user.username }}
  • @@ -10,7 +10,32 @@ {% endblock %} {% block content %} - +
    +
    + +
    +
    + {{ team.owner }} +
    +
    +
      + {% for member in team.members.all %} +
    • {{ member }}
    • + {% endfor %} +
    +
    +
    +
    {% endblock %} {% block analytics %} diff --git a/teams/urls.py b/teams/urls.py index e576e85..6e05f3a 100644 --- a/teams/urls.py +++ b/teams/urls.py @@ -8,4 +8,7 @@ urlpatterns = \ url(r'^for-teams/complete/$', views.for_teams_complete), url(r'^(?P[^/]+)/members/$', views.team_members, - name='team-members')) + name='team-members'), + url(r'^(?P[^/]+)/billing/$', + views.team_billing, + name='team-billing')) diff --git a/teams/views.py b/teams/views.py index b225038..12fa0b2 100644 --- a/teams/views.py +++ b/teams/views.py @@ -5,7 +5,7 @@ import uuid from annoying.decorators import render_to from django.conf import settings from django.contrib.auth.models import User -from django.http import HttpResponseRedirect, HttpResponseBadRequest +from django.http import Http404, HttpResponseRedirect, HttpResponseBadRequest from django.shortcuts import get_object_or_404 from teams.models import Team @@ -19,9 +19,19 @@ def for_teams(request): return {} +@render_to('teams/team-billing.html') +def team_billing(request, username): + team = get_object_or_404(Team, slug=username) + return { + 'team': team + } + + @render_to('teams/team-members.html') def team_members(request, username): team = get_object_or_404(Team, slug=username) + if team.owner != request.user: + raise Http404 return { 'team': team } @@ -49,6 +59,7 @@ def for_teams_complete(request): team = Team(name=request.POST['team-name'], email=request.POST['email'], + plan=plan, owner=request.user) team.stripe_id = customer.id team.save()