Commit 2398b719 authored by Christophe Siraut's avatar Christophe Siraut

Better random key generation.

parent d0eea9ea
......@@ -7,7 +7,7 @@ Nuages - Easy poll sharing
The project uses the following django application:
- django-registration: https://bitbucket.org/ubernostrum/django-registration
On debian they can be installed as follow:
On debian one can install it as follow:
# aptitude install python-django-registration
......
from django.contrib.auth.models import User
from django.contrib.sites.models import Site
import os
from binascii import hexlify
from django.db import models
from django.utils.translation import ugettext_lazy as _
import string
import random
def _createId():
# Random 4 caracters string
return hexlify(os.urandom(2))
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)])
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)
id = models.CharField(primary_key=True, unique=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)
......
......@@ -16,6 +16,7 @@ urlpatterns = patterns('',
url(r'^nuages/$', TemplateView.as_view(template_name='nuages.html'), name='documentation'),
url(r'^languages/$', TemplateView.as_view(template_name='languages.html'), name='languages'),
url(r'^(?P<poll_id>\w{4})/$', 'meetingpoll.views.vote'),
url(r'^(?P<poll_id>\w{5})/$', 'meetingpoll.views.vote'),
url(r'^new/$', 'meetingpoll.views.new', name='new'),
url(r'^(?P<pk>\w+)/edit/$', login_required(UpdateView.as_view(
queryset=Poll.objects.all(),
......@@ -24,11 +25,13 @@ urlpatterns = patterns('',
url(r'^(?P<poll_id>\w+)/delete/$', 'meetingpoll.views.delete'),
url(r'^(?P<poll_id>\w+)/edit/choices/$', 'meetingpoll.views.editchoices', name='choices'),
url(r'^(?P<poll_id>\w{4})/vote/$', 'meetingpoll.views.vote', name='vote'),
url(r'^(?P<poll_id>\w{5})/vote/$', 'meetingpoll.views.vote', name='vote'),
url(r'^(?P<poll_id>\w+)/csv/$', 'meetingpoll.views.exp_csv'),
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')),
url(r'^(?P<poll_id>\w{4})/clear/', 'meetingpoll.userviews.clear_cookie'),
url(r'^(?P<poll_id>\w{5})/clear/', 'meetingpoll.userviews.clear_cookie'),
url(r'^admin/', include(admin.site.urls)),
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
)
......
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