mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-09 19:40:19 +00:00
core, counter: add preferences for counter notifications
Signed-off-by: Skia <skia@libskia.so>
This commit is contained in:
35
core/migrations/0023_auto_20170902_1226.py
Normal file
35
core/migrations/0023_auto_20170902_1226.py
Normal 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),
|
||||
),
|
||||
]
|
@ -497,6 +497,15 @@ class User(AbstractBaseUser):
|
||||
def subscribed(self):
|
||||
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
|
||||
def forum_infos(self):
|
||||
try:
|
||||
@ -582,16 +591,22 @@ class AnonymousUser(AuthAnonymousUser):
|
||||
|
||||
|
||||
class Preferences(models.Model):
|
||||
user = models.OneToOneField(User, related_name="preferences")
|
||||
user = models.OneToOneField(User, related_name="_preferences")
|
||||
receive_weekmail = models.BooleanField(
|
||||
_('do you want to receive the weekmail'),
|
||||
default=False,
|
||||
# help_text=_('Do you want to receive the weekmail?'),
|
||||
)
|
||||
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,
|
||||
help_text=_('Show your account statistics to others'),
|
||||
)
|
||||
|
||||
def get_display_name(self):
|
||||
|
@ -464,7 +464,8 @@ class UserPreferencesView(UserTabsMixin, CanEditMixin, UpdateView):
|
||||
model = User
|
||||
pk_url_kwarg = "user_id"
|
||||
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"
|
||||
current_tab = "prefs"
|
||||
|
||||
@ -474,11 +475,7 @@ class UserPreferencesView(UserTabsMixin, CanEditMixin, UpdateView):
|
||||
|
||||
def get_form_kwargs(self):
|
||||
kwargs = super(UserPreferencesView, self).get_form_kwargs()
|
||||
try:
|
||||
pref = self.object.preferences
|
||||
except:
|
||||
pref = Preferences(user=self.object)
|
||||
pref.save()
|
||||
pref = self.object.preferences
|
||||
kwargs.update({'instance': pref})
|
||||
return kwargs
|
||||
|
||||
|
Reference in New Issue
Block a user