2016-06-12 20:45:22 +00:00
|
|
|
from enum import IntEnum
|
|
|
|
|
2016-06-12 17:00:04 +00:00
|
|
|
from django.contrib.auth.models import User
|
2016-06-08 21:22:23 +00:00
|
|
|
from django.contrib.sites.managers import CurrentSiteManager
|
2016-06-11 13:47:08 +00:00
|
|
|
from django.contrib.sites.models import Site
|
2016-06-12 16:35:59 +00:00
|
|
|
from django.core.urlresolvers import reverse
|
2016-06-29 23:13:59 +00:00
|
|
|
from django.core.validators import MaxValueValidator, MinValueValidator
|
2016-06-11 13:47:08 +00:00
|
|
|
from django.db import models
|
2016-06-07 20:59:13 +00:00
|
|
|
|
2016-06-11 13:47:08 +00:00
|
|
|
from autoslug import AutoSlugField
|
2016-06-29 23:02:00 +00:00
|
|
|
from sortedm2m.fields import SortedManyToManyField
|
2016-06-07 20:59:13 +00:00
|
|
|
|
2016-06-19 23:00:08 +00:00
|
|
|
from accounts.models import Participation
|
2016-06-25 11:39:28 +00:00
|
|
|
from ponyconf.utils import PonyConfModel, enum_to_choices
|
2016-06-12 20:45:22 +00:00
|
|
|
|
2016-06-29 23:02:00 +00:00
|
|
|
__all__ = ['Topic', 'Talk']
|
2016-06-07 20:59:13 +00:00
|
|
|
|
|
|
|
|
2016-06-25 11:39:28 +00:00
|
|
|
class Topic(PonyConfModel):
|
2016-06-07 20:59:13 +00:00
|
|
|
|
|
|
|
name = models.CharField(max_length=128, verbose_name='Name', unique=True)
|
|
|
|
slug = AutoSlugField(populate_from='name', unique=True)
|
|
|
|
|
2016-06-19 23:00:08 +00:00
|
|
|
reviewers = models.ManyToManyField(Participation, blank=True)
|
|
|
|
|
2016-06-07 20:59:13 +00:00
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
2016-06-12 16:35:59 +00:00
|
|
|
def get_absolute_url(self):
|
2016-06-12 19:09:52 +00:00
|
|
|
return reverse('list-talks-by-topic', kwargs={'topic': self.slug})
|
2016-06-12 16:35:59 +00:00
|
|
|
|
2016-06-07 20:59:13 +00:00
|
|
|
|
2016-06-25 11:39:28 +00:00
|
|
|
class Talk(PonyConfModel):
|
2016-06-07 20:59:13 +00:00
|
|
|
|
2016-06-25 10:36:57 +00:00
|
|
|
EVENTS = IntEnum('Event', 'conference_short conference_long workshop stand other')
|
2016-06-12 20:45:22 +00:00
|
|
|
|
2016-06-07 20:59:13 +00:00
|
|
|
site = models.ForeignKey(Site, on_delete=models.CASCADE)
|
|
|
|
|
2016-06-14 21:58:04 +00:00
|
|
|
proposer = models.ForeignKey(User, related_name='+')
|
2016-06-29 23:02:00 +00:00
|
|
|
speakers = SortedManyToManyField(User)
|
2016-06-07 20:59:13 +00:00
|
|
|
title = models.CharField(max_length=128, verbose_name='Title')
|
|
|
|
slug = AutoSlugField(populate_from='title', unique=True)
|
|
|
|
description = models.TextField(blank=True, verbose_name='Description')
|
|
|
|
topics = models.ManyToManyField(Topic, blank=True)
|
2016-06-25 10:36:57 +00:00
|
|
|
event = models.IntegerField(choices=enum_to_choices(EVENTS), default=EVENTS.conference_short.value)
|
2016-06-07 20:59:13 +00:00
|
|
|
|
2016-06-11 13:42:40 +00:00
|
|
|
objects = models.Manager()
|
|
|
|
on_site = CurrentSiteManager()
|
|
|
|
|
2016-06-07 20:59:13 +00:00
|
|
|
def __str__(self):
|
|
|
|
return self.title
|
|
|
|
|
2016-06-12 16:35:59 +00:00
|
|
|
def get_absolute_url(self):
|
|
|
|
return reverse('show-talk', kwargs={'slug': self.slug})
|
|
|
|
|
2016-06-14 21:58:04 +00:00
|
|
|
def is_editable_by(self, user):
|
|
|
|
if user.is_superuser:
|
|
|
|
return True
|
|
|
|
if user == self.proposer:
|
|
|
|
return True
|
2016-06-19 23:00:08 +00:00
|
|
|
if user in self.speakers.all():
|
2016-06-14 21:58:04 +00:00
|
|
|
return True
|
|
|
|
try:
|
|
|
|
participation = Participation.on_site.get(user=user)
|
|
|
|
except Participation.DoesNotExists:
|
|
|
|
return False
|
2016-06-25 14:46:44 +00:00
|
|
|
return participation.orga or self.topics.filter(reviewers=participation).exists()
|
2016-06-29 23:13:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Vote(PonyConfModel):
|
|
|
|
|
|
|
|
talk = models.ForeignKey(Talk)
|
|
|
|
user = models.ForeignKey(Participation)
|
|
|
|
vote = models.IntegerField(validators=[MinValueValidator(-2), MaxValueValidator(2)], default=0)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
unique_together = ('talk', 'user')
|