Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
nuages
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
etch
nuages
Commits
d2e69403
Commit
d2e69403
authored
May 11, 2013
by
Christophe Siraut
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add templates and plumbing for notifications.
parent
88cbcf49
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
67 additions
and
15 deletions
+67
-15
.gitignore
.gitignore
+1
-1
README
README
+13
-1
accounts/forms.py
accounts/forms.py
+1
-1
accounts/models.py
accounts/models.py
+1
-1
accounts/views.py
accounts/views.py
+17
-0
sondage/views.py
sondage/views.py
+13
-10
templates/form.html
templates/form.html
+18
-0
templates/index.html
templates/index.html
+1
-0
templates/registration/login.html
templates/registration/login.html
+1
-1
urls.py
urls.py
+1
-0
No files found.
.gitignore
View file @
d2e69403
*.sqlite
*.pyc
*~
fix
fix
*
settings.py
staticroot
README
View file @
d2e69403
...
...
@@ -97,7 +97,7 @@ Fix permission for apache user
sudo chown -R www-data /usr/local/lib/nuages
Set domain name: login to
the /admin/ url of your installation, modify the "Site"
entry from "example.com" to your domain name.
Set domain name: login to
/admin/sites/site/1/ and modify the
entry from "example.com" to your domain name.
Email Service
=============
...
...
@@ -113,3 +113,15 @@ Another option is to add attributes in settings.py, this make email work only wh
EMAIL_HOST_PASSWORD = 'password'
EMAIL_USE_TLS = False
Migrations
==========
When models change, we need to perform some manual steps to keep existing data:
# mkdir fixture
# ./manage.py dumpdata sondage --indent=2 > fixture/sondage.json
# ./manage.py dumpdata accounts --indent=2 > fixture/accounts.json
# git pull
# ./manage.py reset sondage accounts
# ./manage.py syncdb
# ./manage.py loaddata < fixture/*.json
accounts/forms.py
View file @
d2e69403
...
...
@@ -4,5 +4,5 @@ from accounts.models import UserProfile
class
UserProfileForm
(
ModelForm
):
class
Meta
:
model
=
UserProfile
fields
=
(
'email_notification'
,)
fields
=
(
'email_notification
s
'
,)
accounts/models.py
View file @
d2e69403
...
...
@@ -4,7 +4,7 @@ from django.contrib.auth.signals import user_logged_in
class
UserProfile
(
models
.
Model
):
user
=
models
.
OneToOneField
(
User
)
email_notification
=
models
.
BooleanField
()
email_notification
s
=
models
.
BooleanField
()
def
login_handler
(
user
,
**
kwargs
):
try
:
...
...
accounts/views.py
View file @
d2e69403
from
django.conf
import
settings
from
django.shortcuts
import
render
,
HttpResponseRedirect
from
django.core.urlresolvers
import
reverse
from
django.contrib.auth.models
import
User
from
django.contrib.auth.decorators
import
login_required
from
django.utils.translation
import
ugettext_lazy
from
accounts.forms
import
UserProfileForm
def
_
(
string
):
return
unicode
(
ugettext_lazy
(
string
))
...
...
@@ -16,3 +20,16 @@ def email_notify(poll, voter):
for
choice
in
poll
.
choice_set
.
all
():
message
+=
"
%
s:
%
i
\n
"
%
(
choice
.
choice
,
choice
.
votecount
)
poll
.
user
.
email_user
(
subject
,
message
,
settings
.
DEFAULT_FROM_EMAIL
)
@
login_required
def
profile
(
request
):
if
request
.
method
==
'POST'
:
form
=
UserProfileForm
(
request
.
POST
)
if
form
.
is_valid
():
for
k
,
v
in
form
.
cleaned_data
.
iteritems
():
setattr
(
request
.
user
.
userprofile
,
k
,
v
)
request
.
user
.
userprofile
.
save
()
return
HttpResponseRedirect
(
reverse
(
'home'
))
form
=
UserProfileForm
()
return
render
(
request
,
"form.html"
,
{
'form'
:
form
})
sondage/views.py
View file @
d2e69403
...
...
@@ -11,7 +11,7 @@ from sondage.models import Poll, Choice, Vote, Bulletin
from
sondage.forms
import
PollForm
,
ChoiceForm
,
VoteForm
,
BulletinForm
from
django.views.generic.create_update
import
update_object
from
django.contrib.auth.decorators
import
login_required
#from django.contrib.sites.models import Site
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.conf
import
settings
from
accounts.views
import
email_notify
from
accounts.forms
import
UserProfileForm
...
...
@@ -119,7 +119,7 @@ def editchoices(request, poll_id):
return
HttpResponseRedirect
(
redir
)
else
:
#vforms=OrderedItemFormset(request.POST, instance=poll)
error_message
=
"There are some errors in the form you posted."
error_message
=
_
(
"There are some errors in the form you posted."
)
vforms
=
instances
else
:
...
...
@@ -220,16 +220,19 @@ def vote(request, poll_id):
old
.
voice
=
vorm
.
cleaned_data
[
'voice'
]
old
.
comment
=
vorm
.
cleaned_data
[
'comment'
]
old
.
save
()
error_message
=
"Your vote has been updated, thank you."
if
has_voted
:
if
poll
.
user
:
error_message
=
_
(
"Your vote has been updated, thank you."
)
if
has_voted
and
poll
.
user
:
try
:
if
poll
.
user
.
userprofile
.
email_notifications
:
email_notify
(
poll
,
voter
)
except
:
pass
else
:
error_message
=
'Did you forget to provide your name?'
error_message
=
_
(
'Did you forget to provide your name?'
)
else
:
#error_message = form.errors
error_message
=
'Did you forget to provide your name?'
voter
=
'your name'
error_message
=
_
(
'Did you forget to provide your name?'
)
voter
=
_
(
'your name'
)
else
:
# request.method = 'GET'
...
...
@@ -258,7 +261,7 @@ def vote(request, poll_id):
pass
else
:
voter
=
''
error_message
=
"Login let you modify your vote anytime."
error_message
=
_
(
"Login let you modify your vote anytime."
)
key
=
'has_voted-'
+
poll
.
id
if
request
.
session
.
get
(
key
,
False
):
has_voted
=
True
# Used to show "Forget me"
...
...
templates/form.html
0 → 100644
View file @
d2e69403
{% extends "base.html" %}
{% load i18n %}
{% block content %}
<form
action=
"."
method=
"post"
>
{% csrf_token %}
{% for field in form %}
<div
class=
"fieldWrapper"
>
{{ field.errors }}
{{ field.label_tag }}: {{ field }} {{ field.help_text }}
</div>
{% endfor %}
<br
/>
<div
class=
"form-actions"
>
<p><input
type=
"submit"
value=
{%
trans
'
Send
'
%}
/><p>
</div>
</form>
{% endblock %}
templates/index.html
View file @
d2e69403
...
...
@@ -49,6 +49,7 @@
<h2>
{% trans "My account" %}
</h2>
<ul>
<li>
{% trans "Username" %}: {{user}}
</li>
<li><a
href=
"{% url 'profile' %}"
>
{% trans 'Email notifications' %}
</a>
: {{ user.userprofile.email_notifications }}
</li>
<li><a
href=
"{% url 'auth_password_change' %}"
>
{% trans 'Change password' %}
</a></li>
<!--<li><a href="/user/email/change/">{% trans 'Change email address' %}</a></li>-->
<li><a
href=
"{% url 'auth_logout' %}"
>
{% trans 'Logout' %}
</a></li>
...
...
templates/registration/login.html
View file @
d2e69403
...
...
@@ -9,7 +9,7 @@
<input
type=
"submit"
value=
"{% trans 'Log in' %}"
/>
<input
type=
"hidden"
name=
"next"
value=
"{{ next }}"
/>
</form>
<br
/>
<p>
{% trans "Forgot password" %}?
<a
href=
"{% url auth_password_reset %}"
>
{% trans "Reset it" %}
</a>
!
</p>
<p>
{% trans "Not member" %}?
<a
href=
"{% url registration_register %}"
>
{% trans "Register" %}
</a>
!
</p>
{% endblock %}
urls.py
View file @
d2e69403
...
...
@@ -31,6 +31,7 @@ urlpatterns = patterns('',
url
(
r'^(?P<poll_id>\w+)/edit/choices/$'
,
'sondage.views.editchoices'
),
url
(
r'^(?P<poll_id>\w{4})/vote/$'
,
'sondage.views.vote'
),
url
(
r'^(?P<poll_id>\w+)/csv/$'
,
'sondage.views.exp_csv'
),
url
(
r'^accounts/profile/$'
,
'accounts.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/'
,
'sondage.userviews.clear_cookie'
),
...
...
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