2012-07-28 21:05:01 +00:00
|
|
|
import datetime
|
|
|
|
|
|
|
|
from django.db import models
|
|
|
|
|
|
|
|
import reversion
|
|
|
|
|
|
|
|
from django.contrib.auth.models import Permission, User
|
|
|
|
|
|
|
|
|
|
|
|
TEAM_ACCESS_CHOICES = [
|
2012-07-28 22:10:15 +00:00
|
|
|
("open", "open"),
|
|
|
|
("application", "by application"),
|
|
|
|
("invitation", "by invitation")
|
2012-07-28 21:05:01 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
class Team(models.Model):
|
|
|
|
|
|
|
|
slug = models.SlugField(unique=True)
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
description = models.TextField(blank=True)
|
2012-07-28 22:10:15 +00:00
|
|
|
access = models.CharField(max_length=20, choices=TEAM_ACCESS_CHOICES)
|
2012-07-28 21:05:01 +00:00
|
|
|
permissions = models.ManyToManyField(Permission, blank=True)
|
|
|
|
created = models.DateTimeField(default=datetime.datetime.now, editable=False)
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return self.name
|
|
|
|
|
2012-07-28 22:29:19 +00:00
|
|
|
def get_state_for_user(self, user):
|
|
|
|
try:
|
|
|
|
return self.memberships.get(user=user).state
|
|
|
|
except Membership.DoesNotExist:
|
|
|
|
return None
|
|
|
|
|
2012-07-28 21:05:01 +00:00
|
|
|
|
|
|
|
MEMBERSHIP_STATE_CHOICES = [
|
2012-07-28 22:10:15 +00:00
|
|
|
("applied", "applied"),
|
|
|
|
("invited", "invited"),
|
|
|
|
("declined", "declined"),
|
|
|
|
("rejected", "rejected"),
|
|
|
|
("member", "member"),
|
|
|
|
("manager", "manager"),
|
2012-07-28 21:05:01 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
class Membership(models.Model):
|
|
|
|
|
2012-07-28 22:10:15 +00:00
|
|
|
user = models.ForeignKey(User, related_name="memberships")
|
|
|
|
team = models.ForeignKey(Team, related_name="memberships")
|
|
|
|
state = models.CharField(max_length=20, choices=MEMBERSHIP_STATE_CHOICES)
|
2012-07-28 21:05:01 +00:00
|
|
|
message = models.TextField(blank=True)
|
|
|
|
|
|
|
|
|
|
|
|
reversion.register(Membership)
|