mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-09 19:40:19 +00:00
Add preferences and improve weekmail
This commit is contained in:
@ -86,7 +86,7 @@ class Command(BaseCommand):
|
||||
home_root.save()
|
||||
club_root.save()
|
||||
|
||||
Sith().save()
|
||||
Sith(weekmail_destinations="etudiants@git.an personnel@git.an").save()
|
||||
Weekmail().save()
|
||||
|
||||
p = Page(name='Index')
|
||||
|
19
core/migrations/0019_preferences_receive_weekmail.py
Normal file
19
core/migrations/0019_preferences_receive_weekmail.py
Normal file
@ -0,0 +1,19 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('core', '0018_auto_20161224_0211'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='preferences',
|
||||
name='receive_weekmail',
|
||||
field=models.BooleanField(verbose_name='define if we want to receive the weekmail', default=False, help_text='Do you want to receive the weekmail'),
|
||||
),
|
||||
]
|
@ -487,12 +487,23 @@ class AnonymousUser(AuthAnonymousUser):
|
||||
|
||||
class Preferences(models.Model):
|
||||
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'),
|
||||
default=False,
|
||||
help_text=_('Show your account statistics to others'),
|
||||
)
|
||||
|
||||
def get_display_name(self):
|
||||
return self.user.get_display_name()
|
||||
|
||||
def get_absolute_url(self):
|
||||
return self.user.get_absolute_url()
|
||||
|
||||
def get_directory(instance, filename):
|
||||
return '.{0}/{1}'.format(instance.get_parent_path(), filename)
|
||||
|
||||
|
@ -67,6 +67,7 @@
|
||||
<ul>
|
||||
{% if user.is_in_group(settings.SITH_GROUP_COM_ADMIN_ID) or user.is_root %}
|
||||
<li><a href="{{ url('com:weekmail') }}">{% trans %}Weekmail{% endtrans %}</a></li>
|
||||
<li><a href="{{ url('com:weekmail_destinations') }}">{% trans %}Weekmail destinations{% endtrans %}</a></li>
|
||||
<li><a href="{{ url('com:news_admin_list') }}">{% trans %}Moderate news{% endtrans %}</a></li>
|
||||
<li><a href="{{ url('com:index_edit') }}">{% trans %}Edit index page{% endtrans %}</a></li>
|
||||
<li><a href="{{ url('com:alert_edit') }}">{% trans %}Edit alert message{% endtrans %}</a></li>
|
||||
|
@ -40,6 +40,7 @@ urlpatterns = [
|
||||
url(r'^user/(?P<user_id>[0-9]+)/edit$', UserUpdateProfileView.as_view(), name='user_edit'),
|
||||
url(r'^user/(?P<user_id>[0-9]+)/profile_upload$', UserUploadProfilePictView.as_view(), name='user_profile_upload'),
|
||||
url(r'^user/(?P<user_id>[0-9]+)/clubs$', UserClubView.as_view(), name='user_clubs'),
|
||||
url(r'^user/(?P<user_id>[0-9]+)/prefs$', UserPreferencesView.as_view(), name='user_prefs'),
|
||||
url(r'^user/(?P<user_id>[0-9]+)/groups$', UserUpdateGroupView.as_view(), name='user_groups'),
|
||||
url(r'^user/tools/$', UserToolsView.as_view(), name='user_tools'),
|
||||
url(r'^user/(?P<user_id>[0-9]+)/account$', UserAccountView.as_view(), name='user_account'),
|
||||
|
@ -19,7 +19,7 @@ import logging
|
||||
|
||||
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, TabedViewMixin
|
||||
from core.views.forms import RegisteringForm, UserPropForm, UserProfileForm, LoginForm, UserGodfathersForm
|
||||
from core.models import User, SithFile
|
||||
from core.models import User, SithFile, Preferences
|
||||
from club.models import Club
|
||||
from subscription.models import Subscription
|
||||
|
||||
@ -151,6 +151,11 @@ class UserTabsMixin(TabedViewMixin):
|
||||
'slug': 'edit',
|
||||
'name': _("Edit"),
|
||||
})
|
||||
tab_list.append({
|
||||
'url': reverse('core:user_prefs', kwargs={'user_id': self.object.id}),
|
||||
'slug': 'prefs',
|
||||
'name': _("Preferences"),
|
||||
})
|
||||
if self.request.user.can_view(self.object):
|
||||
tab_list.append({
|
||||
'url': reverse('core:user_clubs', kwargs={'user_id': self.object.id}),
|
||||
@ -378,6 +383,26 @@ class UserClubView(UserTabsMixin, CanViewMixin, DetailView):
|
||||
template_name = "core/user_clubs.jinja"
|
||||
current_tab = "clubs"
|
||||
|
||||
class UserPreferencesView(UserTabsMixin, CanEditMixin, UpdateView):
|
||||
"""
|
||||
Edit a user's preferences
|
||||
"""
|
||||
model = Preferences
|
||||
pk_url_kwarg = "user_id"
|
||||
template_name = "core/edit.jinja"
|
||||
fields = ['receive_weekmail']
|
||||
context_object_name = "profile"
|
||||
current_tab = "prefs"
|
||||
|
||||
def get_object(self, queryset=None):
|
||||
user = get_object_or_404(User, pk=self.kwargs['user_id'])
|
||||
try:
|
||||
return user.preferences
|
||||
except:
|
||||
pref = Preferences(user=user)
|
||||
pref.save()
|
||||
return pref
|
||||
|
||||
class UserUpdateGroupView(UserTabsMixin, CanEditPropMixin, UpdateView):
|
||||
"""
|
||||
Edit a user's groups
|
||||
|
Reference in New Issue
Block a user