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.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-25 15:38:01 +00:00
|
|
|
notes = models.TextField(default='')
|
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')
|
2016-07-09 22:42:40 +00:00
|
|
|
LICENCES = IntEnum('Video licence', 'CC-Zero CC-BY CC-BY-SA CC-BY-ND CC-BY-NC CC-BY-NC-SA CC-BY-NC-ND')
|
2016-06-11 13:42:40 +00:00
|
|
|
|
|
|
|
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-07-09 22:42:40 +00:00
|
|
|
videotaped = models.BooleanField("I'm ok to be recorded on video", default=True)
|
|
|
|
video_licence = models.IntegerField(choices=enum_to_choices(LICENCES), default=1)
|
2016-06-25 14:46:44 +00:00
|
|
|
orga = models.BooleanField(default=False)
|
2016-06-11 13:42:40 +00:00
|
|
|
|
|
|
|
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-07-03 20:58:19 +00:00
|
|
|
return str(self.user.profile)
|
2016-06-12 19:09:52 +00:00
|
|
|
|
|
|
|
def get_absolute_url(self):
|
2016-07-03 20:58:19 +00:00
|
|
|
return reverse('show-speaker', kwargs={'username': self.user.username})
|
2016-06-11 15:28:39 +00:00
|
|
|
|
2016-07-05 23:32:31 +00:00
|
|
|
def is_orga(self):
|
|
|
|
return self.user.is_superuser or self.orga
|
|
|
|
|
2016-06-25 13:12:18 +00:00
|
|
|
def is_staff(self):
|
2016-07-09 18:29:24 +00:00
|
|
|
return self.is_orga() or self.user.topic_set.exists()
|
2016-07-09 22:28:38 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def reviewed_topics(self):
|
|
|
|
from proposals.models import Topic
|
|
|
|
return Topic.objects.filter(reviewers=self.user).all()
|