core, counter: add preferences for counter notifications

Signed-off-by: Skia <skia@libskia.so>
This commit is contained in:
Skia 2017-09-02 12:42:07 +02:00
parent 914feffbd8
commit 9f259b35bd
6 changed files with 174 additions and 99 deletions

View File

@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
from django.conf import settings
class Migration(migrations.Migration):
dependencies = [
('core', '0022_auto_20170822_2232'),
]
operations = [
migrations.AddField(
model_name='preferences',
name='notify_on_click',
field=models.BooleanField(verbose_name='get a notification for every click', default=False),
),
migrations.AddField(
model_name='preferences',
name='notify_on_refill',
field=models.BooleanField(verbose_name='get a notification for every refilling', default=False),
),
migrations.AlterField(
model_name='preferences',
name='show_my_stats',
field=models.BooleanField(verbose_name='show your stats to others', default=False),
),
migrations.AlterField(
model_name='preferences',
name='user',
field=models.OneToOneField(related_name='_preferences', to=settings.AUTH_USER_MODEL),
),
]

View File

@ -497,6 +497,15 @@ class User(AbstractBaseUser):
def subscribed(self): def subscribed(self):
return self.is_in_group(settings.SITH_MAIN_MEMBERS_GROUP) return self.is_in_group(settings.SITH_MAIN_MEMBERS_GROUP)
@cached_property
def preferences(self):
try:
return self._preferences
except:
prefs = Preferences(user=self)
prefs.save()
return prefs
@cached_property @cached_property
def forum_infos(self): def forum_infos(self):
try: try:
@ -582,16 +591,22 @@ class AnonymousUser(AuthAnonymousUser):
class Preferences(models.Model): class Preferences(models.Model):
user = models.OneToOneField(User, related_name="preferences") user = models.OneToOneField(User, related_name="_preferences")
receive_weekmail = models.BooleanField( receive_weekmail = models.BooleanField(
_('do you want to receive the weekmail'), _('do you want to receive the weekmail'),
default=False, default=False,
# help_text=_('Do you want to receive the weekmail?'),
) )
show_my_stats = models.BooleanField( show_my_stats = models.BooleanField(
_('define if we show a users stats'), _('show your stats to others'),
default=False,
)
notify_on_click = models.BooleanField(
_('get a notification for every click'),
default=False,
)
notify_on_refill = models.BooleanField(
_('get a notification for every refilling'),
default=False, default=False,
help_text=_('Show your account statistics to others'),
) )
def get_display_name(self): def get_display_name(self):

View File

@ -464,7 +464,8 @@ class UserPreferencesView(UserTabsMixin, CanEditMixin, UpdateView):
model = User model = User
pk_url_kwarg = "user_id" pk_url_kwarg = "user_id"
template_name = "core/user_preferences.jinja" template_name = "core/user_preferences.jinja"
form_class = modelform_factory(Preferences, fields=['receive_weekmail']) form_class = modelform_factory(Preferences, fields=['receive_weekmail',
'notify_on_click', 'notify_on_refill'])
context_object_name = "profile" context_object_name = "profile"
current_tab = "prefs" current_tab = "prefs"
@ -474,11 +475,7 @@ class UserPreferencesView(UserTabsMixin, CanEditMixin, UpdateView):
def get_form_kwargs(self): def get_form_kwargs(self):
kwargs = super(UserPreferencesView, self).get_form_kwargs() kwargs = super(UserPreferencesView, self).get_form_kwargs()
try: pref = self.object.preferences
pref = self.object.preferences
except:
pref = Preferences(user=self.object)
pref.save()
kwargs.update({'instance': pref}) kwargs.update({'instance': pref})
return kwargs return kwargs

View File

@ -326,11 +326,12 @@ class Refilling(models.Model):
self.customer.amount += self.amount self.customer.amount += self.amount
self.customer.save() self.customer.save()
self.is_validated = True self.is_validated = True
Notification(user=self.customer.user, url=reverse('core:user_account_detail', if self.customer.user.preferences.notify_on_refill:
kwargs={'user_id': self.customer.user.id, 'year': self.date.year, 'month': self.date.month}), Notification(user=self.customer.user, url=reverse('core:user_account_detail',
param=str(self.amount), kwargs={'user_id': self.customer.user.id, 'year': self.date.year, 'month': self.date.month}),
type="REFILLING", param=str(self.amount),
).save() type="REFILLING",
).save()
super(Refilling, self).save(*args, **kwargs) super(Refilling, self).save(*args, **kwargs)
@ -444,13 +445,14 @@ class Selling(models.Model):
self.send_mail_customer() self.send_mail_customer()
except: except:
pass pass
Notification( if self.customer.user.preferences.notify_on_click:
user=self.customer.user, Notification(
url=reverse('core:user_account_detail', user=self.customer.user,
kwargs={'user_id': self.customer.user.id, 'year': self.date.year, 'month': self.date.month}), url=reverse('core:user_account_detail',
param="%d x %s" % (self.quantity, self.label), kwargs={'user_id': self.customer.user.id, 'year': self.date.year, 'month': self.date.month}),
type="SELLING", param="%d x %s" % (self.quantity, self.label),
).save() type="SELLING",
).save()
super(Selling, self).save(*args, **kwargs) super(Selling, self).save(*args, **kwargs)

View File

@ -6,7 +6,7 @@
msgid "" msgid ""
msgstr "" msgstr ""
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-09-02 02:16+0200\n" "POT-Creation-Date: 2017-09-02 12:33+0200\n"
"PO-Revision-Date: 2016-07-18\n" "PO-Revision-Date: 2016-07-18\n"
"Last-Translator: Skia <skia@libskia.so>\n" "Last-Translator: Skia <skia@libskia.so>\n"
"Language-Team: AE info <ae.info@utbm.fr>\n" "Language-Team: AE info <ae.info@utbm.fr>\n"
@ -88,12 +88,12 @@ msgstr "Compte club"
msgid "%(club_account)s on %(bank_account)s" msgid "%(club_account)s on %(bank_account)s"
msgstr "%(club_account)s sur %(bank_account)s" msgstr "%(club_account)s sur %(bank_account)s"
#: accounting/models.py:195 club/models.py:190 counter/models.py:463 #: accounting/models.py:195 club/models.py:190 counter/models.py:465
#: election/models.py:16 launderette/models.py:148 #: election/models.py:16 launderette/models.py:148
msgid "start date" msgid "start date"
msgstr "date de début" msgstr "date de début"
#: accounting/models.py:196 club/models.py:191 counter/models.py:464 #: accounting/models.py:196 club/models.py:191 counter/models.py:466
#: election/models.py:17 #: election/models.py:17
msgid "end date" msgid "end date"
msgstr "date de fin" msgstr "date de fin"
@ -127,18 +127,18 @@ msgstr "numéro"
msgid "journal" msgid "journal"
msgstr "classeur" msgstr "classeur"
#: accounting/models.py:258 core/models.py:628 core/models.py:1003 #: accounting/models.py:258 core/models.py:643 core/models.py:1018
#: core/models.py:1044 counter/models.py:300 counter/models.py:349 #: core/models.py:1059 counter/models.py:300 counter/models.py:350
#: counter/models.py:481 eboutic/models.py:39 eboutic/models.py:73 #: counter/models.py:483 eboutic/models.py:39 eboutic/models.py:73
#: forum/models.py:239 forum/models.py:314 stock/models.py:76 #: forum/models.py:239 forum/models.py:314 stock/models.py:76
msgid "date" msgid "date"
msgstr "date" msgstr "date"
#: accounting/models.py:259 counter/models.py:482 stock/models.py:79 #: accounting/models.py:259 counter/models.py:484 stock/models.py:79
msgid "comment" msgid "comment"
msgstr "commentaire" msgstr "commentaire"
#: accounting/models.py:260 counter/models.py:301 counter/models.py:350 #: accounting/models.py:260 counter/models.py:301 counter/models.py:351
#: subscription/models.py:55 #: subscription/models.py:55
msgid "payment method" msgid "payment method"
msgstr "méthode de paiement" msgstr "méthode de paiement"
@ -164,7 +164,7 @@ msgid "accounting type"
msgstr "type comptable" msgstr "type comptable"
#: accounting/models.py:269 accounting/models.py:371 accounting/models.py:398 #: accounting/models.py:269 accounting/models.py:371 accounting/models.py:398
#: accounting/models.py:422 counter/models.py:341 #: accounting/models.py:422 counter/models.py:342
msgid "label" msgid "label"
msgstr "étiquette" msgstr "étiquette"
@ -888,7 +888,7 @@ msgstr "Vous ne pouvez pas faire de boucles dans les clubs"
msgid "A club with that unix_name already exists" msgid "A club with that unix_name already exists"
msgstr "Un club avec ce nom UNIX existe déjà." msgstr "Un club avec ce nom UNIX existe déjà."
#: club/models.py:188 counter/models.py:461 counter/models.py:479 #: club/models.py:188 counter/models.py:463 counter/models.py:481
#: eboutic/models.py:38 eboutic/models.py:72 election/models.py:140 #: eboutic/models.py:38 eboutic/models.py:72 election/models.py:140
#: launderette/models.py:114 launderette/models.py:152 sas/models.py:158 #: launderette/models.py:114 launderette/models.py:152 sas/models.py:158
#: trombi/models.py:148 #: trombi/models.py:148
@ -927,7 +927,7 @@ msgid "Enter a valid address. Only the root of the address is needed."
msgstr "" msgstr ""
"Entrez une adresse valide. Seule la racine de l'adresse est nécessaire." "Entrez une adresse valide. Seule la racine de l'adresse est nécessaire."
#: club/models.py:238 com/models.py:67 core/models.py:629 #: club/models.py:238 com/models.py:67 core/models.py:644
msgid "is moderated" msgid "is moderated"
msgstr "est modéré" msgstr "est modéré"
@ -1262,7 +1262,7 @@ msgstr "résumé"
msgid "content" msgid "content"
msgstr "contenu" msgstr "contenu"
#: com/models.py:64 core/models.py:1043 launderette/models.py:86 #: com/models.py:64 core/models.py:1058 launderette/models.py:86
#: launderette/models.py:112 launderette/models.py:149 stock/models.py:59 #: launderette/models.py:112 launderette/models.py:149 stock/models.py:59
#: stock/models.py:98 #: stock/models.py:98
msgid "type" msgid "type"
@ -1931,109 +1931,113 @@ msgstr "Un utilisateur de ce nom d'utilisateur existe déjà"
msgid "Profile" msgid "Profile"
msgstr "Profil" msgstr "Profil"
#: core/models.py:581 #: core/models.py:590
msgid "Visitor" msgid "Visitor"
msgstr "Visiteur" msgstr "Visiteur"
#: core/models.py:587 #: core/models.py:596
msgid "do you want to receive the weekmail" msgid "do you want to receive the weekmail"
msgstr "voulez-vous recevoir le Weekmail" msgstr "voulez-vous recevoir le Weekmail"
#: core/models.py:592 #: core/models.py:600
msgid "define if we show a users stats" msgid "show your stats to others"
msgstr "Definit si l'on montre les statistiques de l'utilisateur" msgstr "montrez vos statistiques aux autres"
#: core/models.py:594 #: core/models.py:604
msgid "Show your account statistics to others" msgid "get a notification for every click"
msgstr "Montrez vos statistiques de compte aux autres" msgstr "recevez une notification pour chaque click"
#: core/models.py:617 #: core/models.py:608
msgid "get a notification for every refilling"
msgstr "recevez une notification pour chaque rechargement"
#: core/models.py:632
msgid "file name" msgid "file name"
msgstr "nom du fichier" msgstr "nom du fichier"
#: core/models.py:618 core/models.py:829 #: core/models.py:633 core/models.py:844
msgid "parent" msgid "parent"
msgstr "parent" msgstr "parent"
#: core/models.py:619 core/models.py:635 #: core/models.py:634 core/models.py:650
msgid "file" msgid "file"
msgstr "fichier" msgstr "fichier"
#: core/models.py:620 #: core/models.py:635
msgid "compressed file" msgid "compressed file"
msgstr "version allégée" msgstr "version allégée"
#: core/models.py:621 #: core/models.py:636
msgid "thumbnail" msgid "thumbnail"
msgstr "miniature" msgstr "miniature"
#: core/models.py:622 core/models.py:630 #: core/models.py:637 core/models.py:645
msgid "owner" msgid "owner"
msgstr "propriétaire" msgstr "propriétaire"
#: core/models.py:623 core/models.py:835 core/views/files.py:149 #: core/models.py:638 core/models.py:850 core/views/files.py:149
msgid "edit group" msgid "edit group"
msgstr "groupe d'édition" msgstr "groupe d'édition"
#: core/models.py:624 core/models.py:836 core/views/files.py:150 #: core/models.py:639 core/models.py:851 core/views/files.py:150
msgid "view group" msgid "view group"
msgstr "groupe de vue" msgstr "groupe de vue"
#: core/models.py:625 #: core/models.py:640
msgid "is folder" msgid "is folder"
msgstr "est un dossier" msgstr "est un dossier"
#: core/models.py:626 #: core/models.py:641
msgid "mime type" msgid "mime type"
msgstr "type mime" msgstr "type mime"
#: core/models.py:627 #: core/models.py:642
msgid "size" msgid "size"
msgstr "taille" msgstr "taille"
#: core/models.py:631 #: core/models.py:646
msgid "asked for removal" msgid "asked for removal"
msgstr "retrait demandé" msgstr "retrait demandé"
#: core/models.py:632 #: core/models.py:647
msgid "is in the SAS" msgid "is in the SAS"
msgstr "est dans le SAS" msgstr "est dans le SAS"
#: core/models.py:671 #: core/models.py:686
msgid "Character '/' not authorized in name" msgid "Character '/' not authorized in name"
msgstr "Le caractère '/' n'est pas autorisé dans les noms de fichier" msgstr "Le caractère '/' n'est pas autorisé dans les noms de fichier"
#: core/models.py:674 core/models.py:679 #: core/models.py:689 core/models.py:694
msgid "Loop in folder tree" msgid "Loop in folder tree"
msgstr "Boucle dans l'arborescence des dossiers" msgstr "Boucle dans l'arborescence des dossiers"
#: core/models.py:683 #: core/models.py:698
msgid "You can not make a file be a children of a non folder file" msgid "You can not make a file be a children of a non folder file"
msgstr "" msgstr ""
"Vous ne pouvez pas mettre un fichier enfant de quelque chose qui n'est pas " "Vous ne pouvez pas mettre un fichier enfant de quelque chose qui n'est pas "
"un dossier" "un dossier"
#: core/models.py:687 #: core/models.py:702
msgid "Duplicate file" msgid "Duplicate file"
msgstr "Un fichier de ce nom existe déjà" msgstr "Un fichier de ce nom existe déjà"
#: core/models.py:701 #: core/models.py:716
msgid "You must provide a file" msgid "You must provide a file"
msgstr "Vous devez fournir un fichier" msgstr "Vous devez fournir un fichier"
#: core/models.py:767 #: core/models.py:782
msgid "Folder: " msgid "Folder: "
msgstr "Dossier : " msgstr "Dossier : "
#: core/models.py:769 #: core/models.py:784
msgid "File: " msgid "File: "
msgstr "Fichier : " msgstr "Fichier : "
#: core/models.py:821 #: core/models.py:836
msgid "page unix name" msgid "page unix name"
msgstr "nom unix de la page" msgstr "nom unix de la page"
#: core/models.py:825 #: core/models.py:840
msgid "" msgid ""
"Enter a valid page name. This value may contain only unaccented letters, " "Enter a valid page name. This value may contain only unaccented letters, "
"numbers and ./+/-/_ characters." "numbers and ./+/-/_ characters."
@ -2041,51 +2045,51 @@ msgstr ""
"Entrez un nom de page correct. Uniquement des lettres non accentuées, " "Entrez un nom de page correct. Uniquement des lettres non accentuées, "
"numéros, et ./+/-/_" "numéros, et ./+/-/_"
#: core/models.py:832 #: core/models.py:847
msgid "page name" msgid "page name"
msgstr "nom de la page" msgstr "nom de la page"
#: core/models.py:833 #: core/models.py:848
msgid "owner group" msgid "owner group"
msgstr "groupe propriétaire" msgstr "groupe propriétaire"
#: core/models.py:837 #: core/models.py:852
msgid "lock user" msgid "lock user"
msgstr "utilisateur bloquant" msgstr "utilisateur bloquant"
#: core/models.py:838 #: core/models.py:853
msgid "lock_timeout" msgid "lock_timeout"
msgstr "décompte du déblocage" msgstr "décompte du déblocage"
#: core/models.py:865 #: core/models.py:880
msgid "Duplicate page" msgid "Duplicate page"
msgstr "Une page de ce nom existe déjà" msgstr "Une page de ce nom existe déjà"
#: core/models.py:871 #: core/models.py:886
msgid "Loop in page tree" msgid "Loop in page tree"
msgstr "Boucle dans l'arborescence des pages" msgstr "Boucle dans l'arborescence des pages"
#: core/models.py:1000 #: core/models.py:1015
msgid "revision" msgid "revision"
msgstr "révision" msgstr "révision"
#: core/models.py:1001 #: core/models.py:1016
msgid "page title" msgid "page title"
msgstr "titre de la page" msgstr "titre de la page"
#: core/models.py:1002 #: core/models.py:1017
msgid "page content" msgid "page content"
msgstr "contenu de la page" msgstr "contenu de la page"
#: core/models.py:1041 #: core/models.py:1056
msgid "url" msgid "url"
msgstr "url" msgstr "url"
#: core/models.py:1042 #: core/models.py:1057
msgid "param" msgid "param"
msgstr "param" msgstr "param"
#: core/models.py:1045 #: core/models.py:1060
msgid "viewed" msgid "viewed"
msgstr "vue" msgstr "vue"
@ -3160,7 +3164,7 @@ msgstr "groupe d'achat"
msgid "archived" msgid "archived"
msgstr "archivé" msgstr "archivé"
#: counter/models.py:157 counter/models.py:564 #: counter/models.py:157 counter/models.py:566
msgid "product" msgid "product"
msgstr "produit" msgstr "produit"
@ -3197,7 +3201,7 @@ msgstr "vendeurs"
msgid "token" msgid "token"
msgstr "jeton" msgstr "jeton"
#: counter/models.py:195 counter/models.py:462 counter/models.py:480 #: counter/models.py:195 counter/models.py:464 counter/models.py:482
#: launderette/models.py:39 stock/models.py:39 #: launderette/models.py:39 stock/models.py:39
msgid "counter" msgid "counter"
msgstr "comptoir" msgstr "comptoir"
@ -3206,7 +3210,7 @@ msgstr "comptoir"
msgid "bank" msgid "bank"
msgstr "banque" msgstr "banque"
#: counter/models.py:305 counter/models.py:352 #: counter/models.py:305 counter/models.py:353
msgid "is validated" msgid "is validated"
msgstr "est validé" msgstr "est validé"
@ -3214,37 +3218,37 @@ msgstr "est validé"
msgid "refilling" msgid "refilling"
msgstr "rechargement" msgstr "rechargement"
#: counter/models.py:345 eboutic/models.py:129 #: counter/models.py:346 eboutic/models.py:129
msgid "unit price" msgid "unit price"
msgstr "prix unitaire" msgstr "prix unitaire"
#: counter/models.py:346 counter/models.py:553 eboutic/models.py:130 #: counter/models.py:347 counter/models.py:555 eboutic/models.py:130
msgid "quantity" msgid "quantity"
msgstr "quantité" msgstr "quantité"
#: counter/models.py:351 #: counter/models.py:352
msgid "Sith account" msgid "Sith account"
msgstr "Compte utilisateur" msgstr "Compte utilisateur"
#: counter/models.py:351 sith/settings.py:359 sith/settings.py:364 #: counter/models.py:352 sith/settings.py:359 sith/settings.py:364
#: sith/settings.py:386 #: sith/settings.py:386
msgid "Credit card" msgid "Credit card"
msgstr "Carte bancaire" msgstr "Carte bancaire"
#: counter/models.py:355 #: counter/models.py:356
msgid "selling" msgid "selling"
msgstr "vente" msgstr "vente"
#: counter/models.py:374 #: counter/models.py:375
msgid "Unknown event" msgid "Unknown event"
msgstr "Événement inconnu" msgstr "Événement inconnu"
#: counter/models.py:375 #: counter/models.py:376
#, python-format #, python-format
msgid "Eticket bought for the event %(event)s" msgid "Eticket bought for the event %(event)s"
msgstr "Eticket acheté pour l'événement %(event)s" msgstr "Eticket acheté pour l'événement %(event)s"
#: counter/models.py:377 counter/models.py:389 #: counter/models.py:378 counter/models.py:390
#, python-format #, python-format
msgid "" msgid ""
"You bought an eticket for the event %(event)s.\n" "You bought an eticket for the event %(event)s.\n"
@ -3253,51 +3257,51 @@ msgstr ""
"Vous avez acheté un Eticket pour l'événement %(event)s.\n" "Vous avez acheté un Eticket pour l'événement %(event)s.\n"
"Vous pouvez le télécharger sur cette page: %(url)s" "Vous pouvez le télécharger sur cette page: %(url)s"
#: counter/models.py:465 #: counter/models.py:467
msgid "last activity date" msgid "last activity date"
msgstr "dernière activité" msgstr "dernière activité"
#: counter/models.py:468 #: counter/models.py:470
msgid "permanency" msgid "permanency"
msgstr "permanence" msgstr "permanence"
#: counter/models.py:483 #: counter/models.py:485
msgid "emptied" msgid "emptied"
msgstr "coffre vidée" msgstr "coffre vidée"
#: counter/models.py:486 #: counter/models.py:488
msgid "cash register summary" msgid "cash register summary"
msgstr "relevé de caisse" msgstr "relevé de caisse"
#: counter/models.py:551 #: counter/models.py:553
msgid "cash summary" msgid "cash summary"
msgstr "relevé" msgstr "relevé"
#: counter/models.py:552 #: counter/models.py:554
msgid "value" msgid "value"
msgstr "valeur" msgstr "valeur"
#: counter/models.py:554 #: counter/models.py:556
msgid "check" msgid "check"
msgstr "chèque" msgstr "chèque"
#: counter/models.py:557 #: counter/models.py:559
msgid "cash register summary item" msgid "cash register summary item"
msgstr "élément de relevé de caisse" msgstr "élément de relevé de caisse"
#: counter/models.py:565 #: counter/models.py:567
msgid "banner" msgid "banner"
msgstr "bannière" msgstr "bannière"
#: counter/models.py:566 #: counter/models.py:568
msgid "event date" msgid "event date"
msgstr "date de l'événement" msgstr "date de l'événement"
#: counter/models.py:567 #: counter/models.py:569
msgid "event title" msgid "event title"
msgstr "titre de l'événement" msgstr "titre de l'événement"
#: counter/models.py:568 #: counter/models.py:570
msgid "secret" msgid "secret"
msgstr "secret" msgstr "secret"
@ -5053,6 +5057,9 @@ msgstr "Vous ne pouvez plus écrire de commentaires, la date est passée."
msgid "Maximum characters: %(max_length)s" msgid "Maximum characters: %(max_length)s"
msgstr "Nombre de caractères max: %(max_length)s" msgstr "Nombre de caractères max: %(max_length)s"
#~ msgid "define if we show a users stats"
#~ msgstr "Definit si l'on montre les statistiques de l'utilisateur"
#~ msgid "General management" #~ msgid "General management"
#~ msgstr "Gestion générale" #~ msgstr "Gestion générale"

View File

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('subscription', '0005_auto_20170821_2054'),
]
operations = [
migrations.AlterField(
model_name='subscription',
name='subscription_type',
field=models.CharField(verbose_name='subscription type', choices=[('amicale/doceo', 'Amicale/DOCEO member'), ('assidu', 'Assidu member'), ('crous', 'CROUS member'), ('cursus-alternant', 'Alternating cursus'), ('cursus-branche', 'Branch cursus'), ('cursus-tronc-commun', 'Common core cursus'), ('deux-mois-essai', 'Two month for free'), ('deux-semestres', 'Two semesters'), ('membre-honoraire', 'Honorary member'), ('reseau-ut', 'UT network member'), ('sbarro/esta', 'Sbarro/ESTA member'), ('un-semestre', 'One semester'), ('un-semestre-welcome', 'One semester Welcome Week')], max_length=255),
),
]