# Path: deck/models.py
# class Vote(models.Model):
#     ANGRY, SLEEPY, SAD, HAPPY, LAUGHING = range(-1, 4)
#     VOTE_TITLES = dict(
#         angry=_('Angry'), sad=_('Sad'),
#         sleepy=_('Sleepy'), happy=_('Happy'),
#         laughing=_('Laughing')
#     )
#     VOTE_RATES = ((ANGRY, 'angry'),
#                   (SAD, 'sad'),
#                   (SLEEPY, 'sleepy'),
#                   (HAPPY, 'happy'),
#                   (LAUGHING, 'laughing'))
#     rate = models.SmallIntegerField(_('Rate Index'), null=True, blank=True,
#                                     choices=VOTE_RATES)
# 
#     # relations
#     proposal = models.ForeignKey(to='deck.Proposal', related_name='votes')
#     user = models.ForeignKey(to=settings.AUTH_USER_MODEL, related_name='votes')
# 
#     class Meta:
#         verbose_name = _('Vote')
#         verbose_name_plural = _('Votes')
#         unique_together = (('proposal', 'user'),)
# 
#     def __str__(self):
#         return six.text_type("{0.user}: {0.rate} in {0.proposal}".format(self))
# 
#     def save(self, *args, **kwargs):
#         validation_message = None
# 
#         user_is_in_jury = self.proposal.event.jury.users.filter(
#             pk=self.user.pk).exists()
#         if (self.user.is_superuser or user_is_in_jury):
#             pass
#         elif self.user == self.proposal.author:
#             validation_message = _(u'You cannot Rate your own proposals.')
#         elif not self.proposal.event.allow_public_voting:
#             validation_message = _(u"Proposal doesn't accept Public Voting.")
# 
#         if validation_message:
#             raise ValidationError(_(validation_message))
# 
#         return super(Vote, self).save(*args, **kwargs)
# 
# class Event(DeckBaseModel):
#     allow_public_voting = models.BooleanField(_('Allow Public Voting'),
#                                               default=True)
#     closing_date = models.DateTimeField(null=False, blank=False)
#     slots = models.SmallIntegerField(_('Slots'), default=10)
# 
#     # relations
#     jury = models.OneToOneField(to='jury.Jury', related_name='event',
#                                 null=True, blank=True)
#     anonymous_voting = models.BooleanField(
#         _('Anonymous Voting?'), default=False)
# 
#     class Meta:
#         ordering = ['-closing_date', '-created_at']
#         verbose_name = _('Event')
#         verbose_name_plural = _('Events')
# 
#     @property
#     def closing_date_is_passed(self):
#         return timezone.now() > self.closing_date
# 
#     @property
#     def closing_date_is_close(self):
#         if self.closing_date_is_passed:
#             return False
#         return timezone.now() > self.closing_date - timezone.timedelta(days=7)
# 
#     def get_absolute_url(self):
#         return reverse('view_event', kwargs={'slug': self.slug})
# 
#     def user_can_see_proposals(self, user):
#         can_see_proposals = False
#         if user.is_superuser or self.author == user:
#             can_see_proposals = True
#         elif self.allow_public_voting:
#             can_see_proposals = True
#         elif (not user.is_anonymous() and
#               self.jury.users.filter(pk=user.pk).exists()):
#             can_see_proposals = True
#         return can_see_proposals
# 
#     def get_proposers_count(self):
#         return self.proposals.values_list(
#             'author', flat=True).distinct().count()
# 
#     def get_votes_count(self):
#         return self.proposals.values_list('votes', flat=True).count()
# 
#     def get_votes_to_export(self):
#         return self.proposals.values(
#             'id', 'title', 'author__username', 'author__email'
#         ).annotate(
#             Sum('votes__rate')
#         ).annotate(Count('votes'))
# 
#     def get_schedule(self):
#         schedule = Activity.objects.filter(track__event=self)\
#             .cached_authors()\
#             .annotate(Sum('proposal__votes__rate'))\
#             .extra(select=dict(track_isnull='track_id IS NULL'))\
#             .order_by('track_isnull', 'track_order',
#                       '-proposal__votes__rate__sum')
#         return schedule
# 
#     def get_not_approved_schedule(self):
#         return self.proposals\
#             .cached_authors()\
#             .filter(
#                 models.Q(is_approved=False) |
#                 models.Q(track__isnull=True))
# 
#     def get_main_track(self):
#         return self.tracks.first()
# 
#     def filter_not_scheduled_by_slots(self):
#         return self.get_not_approved_schedule()[:self.slots]
# 
#     def user_in_jury(self, user):
#         return self.jury.users.filter(pk=user.pk).exists()


import hashlib
from django.contrib.auth.models import AnonymousUser
from django import template
from deck.models import Vote, Event
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger

register = template.Library()




@register.filter
def already_voted(user, proposal):
    return proposal.user_already_voted(user)


@register.filter
def allowed_to_vote(user, proposal):
    return proposal.user_can_vote(user)


@register.filter
def get_rate_display(user, proposal):
    if user.is_authenticated():
        vote = proposal.votes.filter(user=user)
        if vote:
            return vote.first().get_rate_display()


@register.filter
def get_rate_title(rate):

# Path: deck/models.py
# class Vote(models.Model):
#     ANGRY, SLEEPY, SAD, HAPPY, LAUGHING = range(-1, 4)
#     VOTE_TITLES = dict(
#         angry=_('Angry'), sad=_('Sad'),
#         sleepy=_('Sleepy'), happy=_('Happy'),
#         laughing=_('Laughing')
#     )
#     VOTE_RATES = ((ANGRY, 'angry'),
#                   (SAD, 'sad'),
#                   (SLEEPY, 'sleepy'),
#                   (HAPPY, 'happy'),
#                   (LAUGHING, 'laughing'))
#     rate = models.SmallIntegerField(_('Rate Index'), null=True, blank=True,
#                                     choices=VOTE_RATES)
# 
#     # relations
#     proposal = models.ForeignKey(to='deck.Proposal', related_name='votes')
#     user = models.ForeignKey(to=settings.AUTH_USER_MODEL, related_name='votes')
# 
#     class Meta:
#         verbose_name = _('Vote')
#         verbose_name_plural = _('Votes')
#         unique_together = (('proposal', 'user'),)
# 
#     def __str__(self):
#         return six.text_type("{0.user}: {0.rate} in {0.proposal}".format(self))
# 
#     def save(self, *args, **kwargs):
#         validation_message = None
# 
#         user_is_in_jury = self.proposal.event.jury.users.filter(
#             pk=self.user.pk).exists()
#         if (self.user.is_superuser or user_is_in_jury):
#             pass
#         elif self.user == self.proposal.author:
#             validation_message = _(u'You cannot Rate your own proposals.')
#         elif not self.proposal.event.allow_public_voting:
#             validation_message = _(u"Proposal doesn't accept Public Voting.")
# 
#         if validation_message:
#             raise ValidationError(_(validation_message))
# 
#         return super(Vote, self).save(*args, **kwargs)
# 
# class Event(DeckBaseModel):
#     allow_public_voting = models.BooleanField(_('Allow Public Voting'),
#                                               default=True)
#     closing_date = models.DateTimeField(null=False, blank=False)
#     slots = models.SmallIntegerField(_('Slots'), default=10)
# 
#     # relations
#     jury = models.OneToOneField(to='jury.Jury', related_name='event',
#                                 null=True, blank=True)
#     anonymous_voting = models.BooleanField(
#         _('Anonymous Voting?'), default=False)
# 
#     class Meta:
#         ordering = ['-closing_date', '-created_at']
#         verbose_name = _('Event')
#         verbose_name_plural = _('Events')
# 
#     @property
#     def closing_date_is_passed(self):
#         return timezone.now() > self.closing_date
# 
#     @property
#     def closing_date_is_close(self):
#         if self.closing_date_is_passed:
#             return False
#         return timezone.now() > self.closing_date - timezone.timedelta(days=7)
# 
#     def get_absolute_url(self):
#         return reverse('view_event', kwargs={'slug': self.slug})
# 
#     def user_can_see_proposals(self, user):
#         can_see_proposals = False
#         if user.is_superuser or self.author == user:
#             can_see_proposals = True
#         elif self.allow_public_voting:
#             can_see_proposals = True
#         elif (not user.is_anonymous() and
#               self.jury.users.filter(pk=user.pk).exists()):
#             can_see_proposals = True
#         return can_see_proposals
# 
#     def get_proposers_count(self):
#         return self.proposals.values_list(
#             'author', flat=True).distinct().count()
# 
#     def get_votes_count(self):
#         return self.proposals.values_list('votes', flat=True).count()
# 
#     def get_votes_to_export(self):
#         return self.proposals.values(
#             'id', 'title', 'author__username', 'author__email'
#         ).annotate(
#             Sum('votes__rate')
#         ).annotate(Count('votes'))
# 
#     def get_schedule(self):
#         schedule = Activity.objects.filter(track__event=self)\
#             .cached_authors()\
#             .annotate(Sum('proposal__votes__rate'))\
#             .extra(select=dict(track_isnull='track_id IS NULL'))\
#             .order_by('track_isnull', 'track_order',
#                       '-proposal__votes__rate__sum')
#         return schedule
# 
#     def get_not_approved_schedule(self):
#         return self.proposals\
#             .cached_authors()\
#             .filter(
#                 models.Q(is_approved=False) |
#                 models.Q(track__isnull=True))
# 
#     def get_main_track(self):
#         return self.tracks.first()
# 
#     def filter_not_scheduled_by_slots(self):
#         return self.get_not_approved_schedule()[:self.slots]
# 
#     def user_in_jury(self, user):
#         return self.jury.users.filter(pk=user.pk).exists()


# Path: deck/templatetags/deck_tags.py
import hashlib
from django.contrib.auth.models import AnonymousUser
from django import template
from deck.models import Vote, Event
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger


register = template.Library()




@register.filter
def already_voted(user, proposal):
    return proposal.user_already_voted(user)


@register.filter
def allowed_to_vote(user, proposal):
    return proposal.user_can_vote(user)


@register.filter
def get_rate_display(user, proposal):
    if user.is_authenticated():
        vote = proposal.votes.filter(user=user)
        if vote:
            return vote.first().get_rate_display()


@register.filter
def get_rate_title(rate):

    return Vote.VOTE_TITLES.get(rate)