class Vote(models.Model): """ Vote entity for a voting session of the planning poker game. This is a temporary dataset valid for a particular session. When a new session is started, the old data should be deleted. """ session = models.CharField( _('Session ID'), max_length=32) # use session to associate a topic with a session_id product = models.IntegerField(_('Product ID')) voter = models.ForeignKey(User, verbose_name=_('Voter User ID')) chair = models.BooleanField(_('Chairperson or not'), default=False) status = models.CharField(_('Status'), max_length=8, default='STARTED', choices=VOTING_CHOICES) vote = models.CharField(_('Vote number'), max_length=8, default='*') tstamp = models.DateTimeField(_('Timestamp'), auto_now_add=True) objects = VoteManager() class Meta: db_table = 'scrum_vote' verbose_name = _('Vote') verbose_name_plural = _('Votes') ordering = ('-tstamp', ) def closed(self): return self.status == 'CLOSED' def expired(self): """ If timestamp of this vote is 24 hours ago, it is regarded as expired. """ from datetime import datetime return (datetime.now() - self.tstamp).days > 0
class Vote(models.Model): content_type = models.ForeignKey(ContentType, related_name="votes") object_id = models.PositiveIntegerField() key = models.CharField(max_length=32) score = models.IntegerField() user = models.ForeignKey(User, blank=True, null=True, related_name="votes") ip_address = models.IPAddressField() cookie = models.CharField(max_length=32, blank=True, null=True) date_added = models.DateTimeField(auto_now_add=True) date_changed = models.DateTimeField(auto_now=True) objects = VoteManager() content_object = generic.GenericForeignKey() class Meta: unique_together = (('content_type', 'object_id', 'key', 'user', 'ip_address')) def __unicode__(self): return u"%s voted %s on %s" % (self.user_display, self.score, self.content_object) def user_display(self): if self.user: return "%s (%s)" % (self.user.username, self.ip_address) return self.ip_address user_display = property(user_display) def partial_ip_address(self): ip = self.ip_address.split('.') ip[-1] = 'xxx' return '.'.join(ip) partial_ip_address = property(partial_ip_address)
class Vote(models.Model): log = models.ForeignKey(Log) ip = models.IPAddressField() vote_type = models.IntegerField("Oy tipi", choices=VOTE_CHOICES) objects = VoteManager() class Meta: db_table = 'votes'
class Vote(models.Model): content_type = models.ForeignKey(ContentType, related_name="votes") object_id = models.PositiveIntegerField() key = models.CharField(max_length=32) score = models.IntegerField() user = models.ForeignKey(settings.AUTH_USER_MODEL, blank=True, null=True, related_name="votes") ip_address = models.GenericIPAddressField() cookie = models.CharField(max_length=32, blank=True, null=True) date_added = models.DateTimeField(default=now, editable=False) date_changed = models.DateTimeField(default=now, editable=False) objects = VoteManager() content_object = GenericForeignKey() class Meta: unique_together = (('content_type', 'object_id', 'key', 'user', 'ip_address')) def __unicode__(self): return u"%s voted %s on %s" % (self.user_display, self.score, self.content_object) def save(self, *args, **kwargs): self.date_changed = now() super(Vote, self).save(*args, **kwargs) def user_display(self): if self.user: return "%s (%s)" % (self.user.username, self.ip_address) return self.ip_address user_display = property(user_display) def partial_ip_address(self): ip = self.ip_address.split('.') ip[-1] = 'xxx' return '.'.join(ip) partial_ip_address = property(partial_ip_address)