Пример #1
0
            return '%.2fMb' % (size / float(1024 * 1024))


class TopicReadTracker(models.Model):
    """
    Save per user topic read tracking
    """
    class Meta(object):
        verbose_name = _('Topic read tracker')
        verbose_name_plural = _('Topic read trackers')

    user = models.ForeignKey(User, blank=False, null=False)
    topic = models.ForeignKey(Topic, blank=True, null=True)
    time_stamp = models.DateTimeField(auto_now=True)

class ForumReadTracker(models.Model):
    """
    Save per user forum read tracking
    """
    class Meta(object):
        verbose_name = _('Forum read tracker')
        verbose_name_plural = _('Forum read trackers')

    user = models.ForeignKey(User, blank=False, null=False)
    forum = models.ForeignKey(Forum, blank=True, null=True)
    time_stamp = models.DateTimeField(auto_now=True)

from pybb import signals

signals.setup_signals()
Пример #2
0
    def votes_percent(self):
        topic_votes = self.topic.poll_votes()
        if topic_votes > 0:
            return 1.0 * self.votes() / topic_votes * 100


class PollAnswerUser(models.Model):
    poll_answer = models.ForeignKey(PollAnswer,
                                    related_name='users',
                                    verbose_name=_('Poll answer'))
    user = models.ForeignKey(User,
                             related_name='poll_answers',
                             verbose_name=_('User'))
    timestamp = models.DateTimeField(auto_now_add=True)

    class Meta:
        verbose_name = _('Poll answer user')
        verbose_name_plural = _('Polls answers users')
        unique_together = ((
            'poll_answer',
            'user',
        ), )

    def __unicode__(self):
        return u'%s - %s' % (self.poll_answer.topic, self.user)


from pybb import signals
signals.setup_signals()