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):
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):

View File

@ -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