from django.db import models
from djangoratings import RatingField
from tagging.fields import TagField


class Presentation(models.Model):
    class Meta:
        permissions = (
            # not all people should be able to view all presentations (but only
            # their own ones. But  e.g. reviewers need to be able to view all
            ("view_presentation", "Can view presentation"),
        )

    ACCEPT_CHOICES = (
        (0, u'rejected'),
        (1, u'selected'),
        (2, u'reserve list'),
    )

    author = models.CharField(max_length=50)
    email = models.CharField(max_length=50)
    organisation = models.CharField(max_length=100, blank=True, null=True)
    biography = models.TextField()
    title = models.CharField(max_length=100)
    abstract = models.TextField()

    THREE_POINT_SCALE = [(n, str(n)) for n in range(0, 3)]
    rating = RatingField(choices=THREE_POINT_SCALE, allow_anonymous=True,
                         can_change_vote=True)

    # make it possible to edit the post even after submission
    username = models.CharField(max_length=30)

    tags = TagField()

    # whether it should be part of the academic track or not
    academic = models.BooleanField(default=False)

    # whether it was rejected, selected or is on the reserve list
    accepted = models.IntegerField(choices=ACCEPT_CHOICES, blank=True, null=True)

    # presentations are organised in sessions
    sessioncode = models.CharField(max_length=50, blank=True, null=True)

    def __unicode__(self):
        return self.title
