Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
AE UTBM
Sith
Commits
d1fb9cc4
Verified
Commit
d1fb9cc4
authored
May 09, 2019
by
Sli
Browse files
clubs: remove moderator and club from mailing form + display not moderated mailings
parent
1d071958
Changes
5
Hide whitespace changes
Inline
Side-by-side
club/forms.py
View file @
d1fb9cc4
...
...
@@ -88,7 +88,7 @@ class MailingForm(forms.Form):
)
# Include fields for handling mailing creation
mailing_fields
=
(
"email"
,
"club"
,
"moderator"
)
mailing_fields
=
(
"email"
,)
self
.
fields
.
update
(
forms
.
fields_for_model
(
Mailing
,
fields
=
mailing_fields
))
for
field
in
mailing_fields
:
self
.
fields
[
"mailing_"
+
field
]
=
self
.
fields
.
pop
(
field
)
...
...
@@ -103,17 +103,10 @@ class MailingForm(forms.Form):
self
.
fields
[
"subscription_"
+
field
]
=
self
.
fields
.
pop
(
field
)
self
.
fields
[
"subscription_"
+
field
].
required
=
False
self
.
fields
[
"mailing_club"
].
queryset
=
Club
.
objects
.
filter
(
id
=
club_id
)
self
.
fields
[
"mailing_club"
].
initial
=
club_id
self
.
fields
[
"mailing_club"
].
widget
=
forms
.
HiddenInput
()
self
.
fields
[
"subscription_mailing"
].
queryset
=
Mailing
.
objects
.
filter
(
club__id
=
club_id
,
is_moderated
=
True
)
self
.
fields
[
"mailing_moderator"
].
queryset
=
User
.
objects
.
filter
(
id
=
user_id
)
self
.
fields
[
"mailing_moderator"
].
initial
=
user_id
self
.
fields
[
"mailing_moderator"
].
widget
=
forms
.
HiddenInput
()
def
check_required
(
self
,
cleaned_data
,
field
):
"""
If the given field doesn't exist or has no value, add a required error on it
...
...
@@ -150,8 +143,8 @@ class MailingForm(forms.Form):
if
cleaned_data
[
"action"
]
==
self
.
ACTION_NEW_MAILING
:
self
.
check_required
(
cleaned_data
,
"mailing_email"
)
self
.
check_required
(
cleaned_data
,
"mailing_club"
)
self
.
check_required
(
cleaned_data
,
"mailing_moderator"
)
#
self.check_required(cleaned_data, "mailing_club")
#
self.check_required(cleaned_data, "mailing_moderator")
if
cleaned_data
[
"action"
]
==
self
.
ACTION_NEW_SUBSCRIPTION
:
self
.
check_required
(
cleaned_data
,
"subscription_mailing"
)
...
...
club/models.py
View file @
d1fb9cc4
...
...
@@ -338,6 +338,8 @@ class Mailing(models.Model):
)
def
clean
(
self
):
if
Mailing
.
objects
.
filter
(
email
=
self
.
email
).
exists
():
raise
ValidationError
(
_
(
"This mailing list already exists."
))
if
self
.
can_moderate
(
self
.
moderator
):
self
.
is_moderated
=
True
else
:
...
...
club/templates/club/mailing.jinja
View file @
d1fb9cc4
...
...
@@ -6,11 +6,20 @@
{%
endblock
%}
{%
block
content
%}
{%
if
mailings
%}
<b>
{%
trans
%}
Remember : mailing lists need to be moderated, if your new created list is not shown wait until moderation takes action
{%
endtrans
%}
</b>
{%
for
mailing
in
mailings
%}
{%
if
mailings_not_moderated
%}
<p>
{%
trans
%}
Mailing lists waiting for moderation
{%
endtrans
%}
</p>
<ul>
{%
for
mailing
in
mailings_not_moderated
%}
<li>
{{
mailing.email_full
}}
<a
href=
"
{{
url
(
'club:mailing_delete'
,
mailing_id
=
mailing.id
)
}}
"
>
-
{%
trans
%}
Delete
{%
endtrans
%}
</a></li>
{%
endfor
%}
</ul>
{%
endif
%}
{%
if
mailings_moderated
%}
{%
for
mailing
in
mailings_moderated
%}
<h2>
{%
trans
%}
Mailing
{%
endtrans
%}
{{
mailing.email_full
}}
{%
-
if
user.is_owner
(
mailing
)
-
%}
<a
href=
"
{{
url
(
'club:mailing_delete'
,
mailing_id
=
mailing.id
)
}}
"
>
-
{%
trans
%}
Delete
{%
endtrans
%}
</a>
...
...
@@ -87,15 +96,11 @@
<h2>
{%
trans
%}
New mailing
{%
endtrans
%}
</h2>
<form
action=
"
{{
url
(
'club:mailing'
,
club_id
=
club.id
)
}}
"
method=
"post"
enctype=
"multipart/form-data"
>
{%
csrf_token
%}
{{
form.mailing_club.errors
}}
{{
form.mailing_moderator.errors
}}
<p>
{{
form.mailing_email.errors
}}
<label
for=
"
{{
form.mailing_email.id_for_label
}}
"
>
{{
form.mailing_email.label
}}
</label>
{{
form.mailing_email
}}
</p>
{{
form.mailing_club
}}
{{
form.mailing_moderator
}}
<input
hidden
type=
"number"
name=
"
{{
form.action.name
}}
"
value=
"
{{
form_actions.NEW_MALING
}}
"
/>
<p><input
type=
"submit"
value=
"
{%
trans
%}
Create mailing list
{%
endtrans
%}
"
/></p>
</form>
...
...
club/views.py
View file @
d1fb9cc4
...
...
@@ -35,7 +35,7 @@ from django.core.urlresolvers import reverse, reverse_lazy
from
django.utils
import
timezone
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.utils.translation
import
ugettext
as
_t
from
django.core.exceptions
import
PermissionDenied
from
django.core.exceptions
import
PermissionDenied
,
ValidationError
,
NON_FIELD_ERRORS
from
django.shortcuts
import
get_object_or_404
,
redirect
from
core.views
import
(
...
...
@@ -532,6 +532,9 @@ class ClubMailingView(ClubTabsMixin, CanEditMixin, DetailFormView):
kwargs
[
"mailings_moderated"
]
=
(
kwargs
[
"mailings"
].
exclude
(
is_moderated
=
False
).
all
()
)
kwargs
[
"mailings_not_moderated"
]
=
(
kwargs
[
"mailings"
].
exclude
(
is_moderated
=
True
).
all
()
)
kwargs
[
"form_actions"
]
=
{
"NEW_MALING"
:
self
.
form_class
.
ACTION_NEW_MAILING
,
"NEW_SUBSCRIPTION"
:
self
.
form_class
.
ACTION_NEW_SUBSCRIPTION
,
...
...
@@ -539,20 +542,24 @@ class ClubMailingView(ClubTabsMixin, CanEditMixin, DetailFormView):
}
return
kwargs
def
add_new_mailing
(
self
,
cleaned_data
):
def
add_new_mailing
(
self
,
cleaned_data
)
->
ValidationError
:
"""
Create a new mailing list from the form
"""
mailing
=
Mailing
(
club
=
cleaned_data
[
"mailing_club"
]
,
club
=
self
.
get_object
()
,
email
=
cleaned_data
[
"mailing_email"
],
moderator
=
cleaned_data
[
"mailing_moderator"
]
,
moderator
=
self
.
request
.
user
,
is_moderated
=
False
,
)
mailing
.
clean
()
try
:
mailing
.
clean
()
except
ValidationError
as
validation_error
:
return
validation_error
mailing
.
save
()
return
None
def
add_new_subscription
(
self
,
cleaned_data
):
def
add_new_subscription
(
self
,
cleaned_data
)
->
ValidationError
:
"""
Add mailing subscriptions for each user given and/or for the specified email in form
"""
...
...
@@ -568,8 +575,14 @@ class ClubMailingView(ClubTabsMixin, CanEditMixin, DetailFormView):
mailing
=
cleaned_data
[
"subscription_mailing"
],
email
=
cleaned_data
[
"subscription_email"
],
)
try
:
sub
.
clean
()
sub
.
save
()
except
ValidationError
as
validation_error
:
return
validation_error
sub
.
save
()
return
None
def
remove_subscription
(
self
,
cleaned_data
):
"""
...
...
@@ -588,16 +601,21 @@ class ClubMailingView(ClubTabsMixin, CanEditMixin, DetailFormView):
resp
=
super
(
ClubMailingView
,
self
).
form_valid
(
form
)
cleaned_data
=
form
.
clean
()
error
=
None
if
cleaned_data
[
"action"
]
==
self
.
form_class
.
ACTION_NEW_MAILING
:
self
.
add_new_mailing
(
cleaned_data
)
error
=
self
.
add_new_mailing
(
cleaned_data
)
if
cleaned_data
[
"action"
]
==
self
.
form_class
.
ACTION_NEW_SUBSCRIPTION
:
self
.
add_new_subscription
(
cleaned_data
)
error
=
self
.
add_new_subscription
(
cleaned_data
)
if
cleaned_data
[
"action"
]
==
self
.
form_class
.
ACTION_REMOVE_SUBSCRIPTION
:
self
.
remove_subscription
(
cleaned_data
)
if
error
:
form
.
add_error
(
NON_FIELD_ERRORS
,
error
)
return
self
.
form_invalid
(
form
)
return
resp
def
get_success_url
(
self
,
**
kwargs
):
...
...
locale/fr/LC_MESSAGES/django.po
View file @
d1fb9cc4
...
...
@@ -6,7 +6,7 @@
msgid
""
msgstr
""
"Report-Msgid-Bugs-To:
\n
"
"POT-Creation-Date: 2019-05-0
1 22:45
+0200
\n
"
"POT-Creation-Date: 2019-05-0
9 11:33
+0200
\n
"
"PO-Revision-Date: 2016-07-18
\n
"
"Last-Translator: Skia <skia@libskia.so>
\n
"
"Language-Team: AE info <ae.info@utbm.fr>
\n
"
...
...
@@ -174,10 +174,10 @@ msgstr "étiquette"
msgid
"target type"
msgstr
"type de cible"
#: accounting/models.py:313 club/models.py:41
3
#: accounting/models.py:313 club/models.py:41
5
#: club/templates/club/club_members.jinja:16
#: club/templates/club/club_old_members.jinja:8
#: club/templates/club/mailing.jinja:
32
#: club/templates/club/mailing.jinja:
41
#: counter/templates/counter/cash_summary_list.jinja:32
#: counter/templates/counter/stats.jinja:15
#: counter/templates/counter/stats.jinja:52
...
...
@@ -345,7 +345,7 @@ msgstr "Compte en banque : "
#: accounting/templates/accounting/club_account_details.jinja:60
#: accounting/templates/accounting/label_list.jinja:26
#: club/templates/club/club_sellings.jinja:50
#: club/templates/club/mailing.jinja:
16
club/templates/club/mailing.jinja:
3
4
#: club/templates/club/mailing.jinja:
25
club/templates/club/mailing.jinja:4
3
#: com/templates/com/mailing_admin.jinja:19
#: com/templates/com/news_admin_list.jinja:41
#: com/templates/com/news_admin_list.jinja:70
...
...
@@ -1054,7 +1054,7 @@ msgstr "description"
msgid
"past member"
msgstr
"Anciens membres"
#: club/models.py:323 club/models.py:4
18
#: club/models.py:323 club/models.py:4
20
msgid
"Email address"
msgstr
"Adresse email"
...
...
@@ -1071,19 +1071,23 @@ msgstr "est modéré"
msgid
"moderator"
msgstr
"modérateur"
#: club/models.py:406 club/templates/club/mailing.jinja:14
#: club/models.py:342
msgid
"This mailing list already exists."
msgstr
"Cette liste de diffusion existe déjà."
#: club/models.py:408 club/templates/club/mailing.jinja:23
msgid
"Mailing"
msgstr
"Liste de diffusion"
#: club/models.py:42
5
#: club/models.py:42
7
msgid
"At least user or email is required"
msgstr
"Au moins un utilisateur ou un email est nécessaire"
#: club/models.py:43
3
#: club/models.py:43
5
msgid
"This email is already suscribed in this mailing"
msgstr
"Cet email est déjà abonné à cette mailing"
#: club/models.py:4
59
#: club/models.py:4
61
msgid
"Unregistered user"
msgstr
"Utilisateur non enregistré"
...
...
@@ -1275,7 +1279,7 @@ msgstr "Gestion des laveries"
msgid
"Mailing lists"
msgstr
"Mailing listes"
#: club/templates/club/mailing.jinja:1
1
#: club/templates/club/mailing.jinja:1
0
msgid
""
"Remember : mailing lists need to be moderated, if your new created list is "
"not shown wait until moderation takes action"
...
...
@@ -1284,40 +1288,44 @@ msgstr ""
"nouvellement créee n'est pas affichée, attendez jusqu'à qu'un modérateur "
"entre en action"
#: club/templates/club/mailing.jinja:20
#: club/templates/club/mailing.jinja:13
msgid
"Mailing lists waiting for moderation"
msgstr
"Listes de diffusions en attente de modération"
#: club/templates/club/mailing.jinja:29
msgid
"Generate mailing list"
msgstr
"Générer la liste de diffusion"
#: club/templates/club/mailing.jinja:
33
#: club/templates/club/mailing.jinja:
42
#: com/templates/com/mailing_admin.jinja:10
msgid
"Email"
msgstr
"Email"
#: club/templates/club/mailing.jinja:
49
#: club/templates/club/mailing.jinja:
58
msgid
"Remove from mailing list"
msgstr
"Supprimer de la liste de diffusion"
#: club/templates/club/mailing.jinja:
53
#: club/templates/club/mailing.jinja:
62
msgid
"There is no subscriber for this mailing list"
msgstr
"Il n'y a pas d'abonnés dans cette liste de diffusion"
#: club/templates/club/mailing.jinja:
58
#: club/templates/club/mailing.jinja:
67
msgid
"No mailing list existing for this club"
msgstr
"Aucune mailing liste n'existe pour ce club"
#: club/templates/club/mailing.jinja:
63
#: club/templates/club/mailing.jinja:
72
msgid
"New member"
msgstr
"Nouveau membre"
#: club/templates/club/mailing.jinja:
83
#: club/templates/club/mailing.jinja:
92
msgid
"Add to mailing list"
msgstr
"Ajouter à la mailing liste"
#: club/templates/club/mailing.jinja:
87
#: club/templates/club/mailing.jinja:
96
msgid
"New mailing"
msgstr
"Nouvelle liste de diffusion"
#: club/templates/club/mailing.jinja:10
0
#: club/templates/club/mailing.jinja:10
9
msgid
"Create mailing list"
msgstr
"Créer une liste de diffusion"
...
...
Write
Preview
Supports
Markdown
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