2016-06-11 13:42:40 +00:00
|
|
|
from enum import IntEnum
|
|
|
|
|
|
|
|
from django.contrib.auth.models import User
|
2016-06-11 13:47:08 +00:00
|
|
|
from django.contrib.sites.managers import CurrentSiteManager
|
|
|
|
from django.contrib.sites.models import Site
|
2016-06-12 19:09:52 +00:00
|
|
|
from django.core.urlresolvers import reverse
|
2016-06-11 13:47:08 +00:00
|
|
|
from django.db import models
|
2016-06-07 20:59:13 +00:00
|
|
|
|
2016-06-25 11:39:28 +00:00
|
|
|
from ponyconf.utils import PonyConfModel, enum_to_choices
|
2016-06-07 20:59:13 +00:00
|
|
|
|
2016-06-19 23:00:08 +00:00
|
|
|
from .utils import generate_user_uid
|
2016-06-07 20:59:13 +00:00
|
|
|
|
2016-06-14 21:58:04 +00:00
|
|
|
__all__ = ['Profile']
|
2016-06-14 19:39:04 +00:00
|
|
|
|
2016-06-11 13:47:08 +00:00
|
|
|
|
2016-06-25 11:39:28 +00:00
|
|
|
class Profile(PonyConfModel):
|
2016-06-07 20:59:13 +00:00
|
|
|
|
2016-06-11 13:42:40 +00:00
|
|
|
user = models.OneToOneField(User)
|
2016-06-07 20:59:13 +00:00
|
|
|
biography = models.TextField(blank=True, verbose_name='Biography')
|
2016-06-15 20:31:03 +00:00
|
|
|
email_token = models.CharField(max_length=12, default=generate_user_uid, unique=True)
|
2016-06-11 13:42:40 +00:00
|
|
|
|
2016-06-12 19:09:52 +00:00
|
|
|
def __str__(self):
|
|
|
|
return self.user.get_full_name() or self.user.username
|
|
|
|
|
|
|
|
def get_absolute_url(self):
|
|
|
|
return reverse('profile')
|
|
|
|
|
2016-06-11 13:42:40 +00:00
|
|
|
|
2016-06-25 11:39:28 +00:00
|
|
|
class Participation(PonyConfModel):
|
2016-06-11 13:42:40 +00:00
|
|
|
|
2016-06-15 20:31:03 +00:00
|
|
|
TRANSPORTS = IntEnum('Transport', 'train plane others')
|
2016-06-11 13:42:40 +00:00
|
|
|
CONNECTORS = IntEnum('Connector', 'VGA HDMI miniDP')
|
|
|
|
|
|
|
|
site = models.ForeignKey(Site, on_delete=models.CASCADE)
|
2016-06-12 14:40:23 +00:00
|
|
|
user = models.ForeignKey(User)
|
2016-06-14 19:39:04 +00:00
|
|
|
|
2016-06-11 13:42:40 +00:00
|
|
|
arrival = models.DateTimeField(blank=True, null=True)
|
|
|
|
departure = models.DateTimeField(blank=True, null=True)
|
2016-06-14 19:39:04 +00:00
|
|
|
# TODO: These should multi-choice fields
|
2016-06-11 13:42:40 +00:00
|
|
|
transport = models.IntegerField(choices=enum_to_choices(TRANSPORTS), blank=True, null=True)
|
|
|
|
connector = models.IntegerField(choices=enum_to_choices(CONNECTORS), blank=True, null=True)
|
2016-06-12 21:39:04 +00:00
|
|
|
constraints = models.TextField(blank=True)
|
2016-06-25 10:41:08 +00:00
|
|
|
sound = models.BooleanField("I need sound", default=False)
|
2016-06-25 14:46:44 +00:00
|
|
|
orga = models.BooleanField(default=False)
|
2016-06-11 13:42:40 +00:00
|
|
|
|
|
|
|
objects = models.Manager()
|
|
|
|
on_site = CurrentSiteManager()
|
|
|
|
|
|
|
|
class Meta:
|
2016-06-14 19:39:04 +00:00
|
|
|
# A User can participe only once to a Conference (= Site)
|
2016-06-11 13:42:40 +00:00
|
|
|
unique_together = ('site', 'user')
|
|
|
|
|
2016-06-11 15:28:39 +00:00
|
|
|
def __str__(self):
|
2016-06-14 19:39:04 +00:00
|
|
|
return "%s participation to %s" % (str(self.user.profile), self.site.name)
|
2016-06-12 19:09:52 +00:00
|
|
|
|
|
|
|
def get_absolute_url(self):
|
2016-06-14 19:39:04 +00:00
|
|
|
return reverse('show-participation', kwargs={'username': self.user.username})
|
2016-06-11 15:28:39 +00:00
|
|
|
|
2016-06-25 13:12:18 +00:00
|
|
|
def is_staff(self):
|
2016-06-25 14:46:44 +00:00
|
|
|
return self.user.is_superuser or self.orga or self.topic_set.exists()
|
2016-06-25 13:12:18 +00:00
|
|
|
|
2016-06-11 13:42:40 +00:00
|
|
|
|
2016-06-12 15:11:11 +00:00
|
|
|
def create_profile(sender, instance, created, **kwargs):
|
2016-06-11 13:42:40 +00:00
|
|
|
if created:
|
2016-06-12 15:11:11 +00:00
|
|
|
Profile.objects.create(user=instance)
|
2016-06-11 13:42:40 +00:00
|
|
|
|
2016-06-12 15:11:11 +00:00
|
|
|
models.signals.post_save.connect(create_profile, sender=User, weak=False, dispatch_uid='create_profile')
|