Commit ccf533c5 authored by Christophe Siraut's avatar Christophe Siraut

Better random function.

parent 9d531fea
......@@ -5,14 +5,20 @@ from django.utils.translation import ugettext_lazy as _
import string
import random
def _createId(length):
firstchar = string.ascii_letters # First char: Always a letter
chars = string.digits + string.ascii_letters # Letters and digits for the rest
return random.choice(firstchar) + ''.join([random.choice(chars) for dummy in xrange(0, length - 1)])
def createId(length):
firstchar = string.ascii_letters
c = string.digits + string.ascii_letters
lastchars = ''.join([random.choice(c) for dummy in xrange(0, length - 1)])
return random.choice(firstchar) + lastchars
class Poll(models.Model):
# Override django id AutoField with randomly generatyed hash
id = models.CharField(primary_key=True, unique=True, max_length=8, default=_createId(5))
# Override django id AutoField with randomly generated hash
id = models.CharField(
primary_key=True,
max_length=8,
default=createId(5))
title = models.CharField(_('Title'), max_length=80)
pub_date = models.DateField(auto_now_add=True)
upd_date = models.DateField(auto_now=True)
......@@ -26,15 +32,19 @@ class Poll(models.Model):
def link(self):
return 'http://%s/%s/' % (Site.objects.get_current(), self.id)
class Choice(models.Model):
poll = models.ForeignKey(Poll)
choice = models.DateTimeField()
details = models.CharField(max_length=200, blank=True)
votecount = models.IntegerField(default=0, blank=True)
class Meta:
ordering = ['choice']
def __unicode__(self):
return str(self.choice) # hacky?
return str(self.choice)
class Bulletin(models.Model):
poll = models.ForeignKey(Poll, editable=False)
......@@ -43,13 +53,15 @@ class Bulletin(models.Model):
def __unicode__(self):
return self.voter
class Vote(models.Model):
choice = models.ForeignKey(Choice)
bulletin = models.ForeignKey(Bulletin)
voice = models.BooleanField()
comment = models.CharField(max_length=80, blank=True)
class Meta:
ordering = ['choice']
def __unicode__(self):
return str(self.voice)
......@@ -25,7 +25,7 @@ urlpatterns = patterns('',
url(r'^(?P<poll_id>\w{4,6})/edit/choices/$', 'meetingpoll.views.editchoices', name='choices'),
url(r'^(?P<poll_id>\w{4,6})/vote/$', 'meetingpoll.views.vote', name='vote'),
url(r'^(?P<poll_id>\w{4,6})/csv/$', 'meetingpoll.views.exp_csv'),
url(r'^(?P<poll_id>\w{4,6})/clear/', 'account.view.clear_cookie'),
url(r'^(?P<poll_id>\w{4,6})/clear/', 'meetingpoll.views.clear_cookie'),
url(r'^accounts/profile/$', 'account.views.profile', name='profile'),
url(r'^accounts/', include('registration.backends.default.urls')),
url(r'^i18n/', include('django.conf.urls.i18n')),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment