Browse Source

Base work for teams.

master
Nick Sergeant 6 years ago
parent
commit
29fed4e6eb
9 changed files with 109 additions and 52 deletions
  1. +1
    -0
      settings.py
  2. +0
    -0
      teams/__init__.py
  3. +9
    -0
      teams/admin.py
  4. +28
    -0
      teams/migrations/0001_initial.py
  5. +20
    -0
      teams/migrations/0002_team_email.py
  6. +20
    -0
      teams/migrations/0003_auto_20150818_0057.py
  7. +0
    -0
      teams/migrations/__init__.py
  8. +23
    -0
      teams/models.py
  9. +8
    -52
      views.py

+ 1
- 0
settings.py View File

@@ -108,6 +108,7 @@ INSTALLED_APPS = (
'storages',
'taggit',
'tastypie',
'teams',
'typogrify',
'user-admin',
'utils',


+ 0
- 0
teams/__init__.py View File


+ 9
- 0
teams/admin.py View File

@@ -0,0 +1,9 @@
from django.contrib import admin
from teams.models import Team


class TeamAdmin(admin.ModelAdmin):
list_display = ('name', 'owner', 'created', 'modified')
ordering = ('-created',)

admin.site.register(Team, TeamAdmin)

+ 28
- 0
teams/migrations/0001_initial.py View File

@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations
from django.conf import settings


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name='Team',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('name', models.CharField(max_length=255)),
('slug', models.SlugField(max_length=255, blank=True)),
('created', models.DateTimeField(auto_now_add=True)),
('modified', models.DateTimeField(auto_now=True)),
('members', models.ManyToManyField(related_name='member', to=settings.AUTH_USER_MODEL)),
('owner', models.ForeignKey(related_name='owner', to=settings.AUTH_USER_MODEL)),
('user', models.OneToOneField(to=settings.AUTH_USER_MODEL)),
],
),
]

+ 20
- 0
teams/migrations/0002_team_email.py View File

@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

dependencies = [
('teams', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='team',
name='email',
field=models.EmailField(default='nick@snipt.net', max_length=255),
preserve_default=False,
),
]

+ 20
- 0
teams/migrations/0003_auto_20150818_0057.py View File

@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations
from django.conf import settings


class Migration(migrations.Migration):

dependencies = [
('teams', '0002_team_email'),
]

operations = [
migrations.AlterField(
model_name='team',
name='user',
field=models.OneToOneField(null=True, blank=True, to=settings.AUTH_USER_MODEL),
),
]

+ 0
- 0
teams/migrations/__init__.py View File


+ 23
- 0
teams/models.py View File

@@ -0,0 +1,23 @@
from django.contrib.auth.models import User
from django.db import models
from snipts.utils import slugify_uniquely


class Team(models.Model):
user = models.OneToOneField(User, blank=True, null=True)
owner = models.ForeignKey(User, related_name='owner')
name = models.CharField(max_length=255)
email = models.EmailField(max_length=255)
slug = models.SlugField(max_length=255, blank=True)
members = models.ManyToManyField(User, related_name='member')

created = models.DateTimeField(auto_now_add=True, editable=False)
modified = models.DateTimeField(auto_now=True, editable=False)

def save(self, *args, **kwargs):
if not self.slug:
self.slug = slugify_uniquely(self.name, User, 'username')
return super(Team, self).save(*args, **kwargs)

def __unicode__(self):
return self.name

+ 8
- 52
views.py View File

@@ -2,7 +2,6 @@ import datetime
import hashlib
import os
import stripe
import requests

from accounts.models import UserProfile
from annoying.decorators import ajax_request, render_to
@@ -10,7 +9,6 @@ from blogs.views import blog_list
from django.conf import settings
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
from django.core.mail import send_mail
from django.db.models import Count
from django.http import HttpResponseRedirect, HttpResponseBadRequest
from django.shortcuts import render_to_response
@@ -18,6 +16,7 @@ from django.template import RequestContext
from snipts.models import Snipt
from snipts.utils import get_lexers_list
from taggit.models import Tag
from teams.models import Team


@render_to('for-teams.html')
@@ -31,59 +30,16 @@ def for_teams(request):

@render_to('for-teams-complete.html')
def for_teams_complete(request):
if request.method == 'POST' and request.user.is_authenticated():

if request.method == 'POST':

if 'g-recaptcha-response' not in request.POST:
return HttpResponseBadRequest()

payload = {
'secret': settings.RECAPTCHA_SECRET,
'response': request.POST['g-recaptcha-response'],
'remoteip': request.META.get('REMOTE_ADDR')
}
r = requests.post('https://www.google.com/recaptcha/api/siteverify',
data=payload)

if not r.json()['success']:
return HttpResponseBadRequest()

if request.user.is_authenticated():
name = request.POST['name']
members = request.POST['members']
info = request.POST['info']
send_mail('[Snipt] New Snipt for Teams beta request.', """
User: %s (%s)
Team name: %s
Team members: %s
Info:

%s
""" % (request.user.username, request.user.email, name, members,
info), 'support@snipt.net',
['nick@nicksergeant.com'], fail_silently=False)

profile = request.user.profile
profile.teams_beta_applied = True
profile.save()
else:
username = request.POST['username']
email = request.POST['email']
name = request.POST['name']
members = request.POST['members']
info = request.POST['info']
send_mail('[Snipt] New Snipt for Teams beta request.', """
User: %s (%s) (not authenticated)
Team name: %s
Team members: %s
Info:

%s
""" % (username, email, name, members, info), 'support@snipt.net',
['nick@nicksergeant.com'], fail_silently=False)
team = Team(name=request.POST['name'],
email='nick@snipt.net',
owner=request.user)
user = User.objects.create_user(team.slug, team.email, 'password')
team.user = user
team.save()

return {}

else:
return HttpResponseBadRequest()



Loading…
Cancel
Save