Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
nuages
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
etch
nuages
Commits
ccf533c5
Commit
ccf533c5
authored
Jun 22, 2013
by
Christophe Siraut
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Better random function.
parent
9d531fea
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
9 deletions
+21
-9
meetingpoll/models.py
meetingpoll/models.py
+20
-8
nuages/urls.py
nuages/urls.py
+1
-1
No files found.
meetingpoll/models.py
View file @
ccf533c5
...
...
@@ -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
)
nuages/urls.py
View file @
ccf533c5
...
...
@@ -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'
)),
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment