diff --git a/preferences/admin.py b/preferences/admin.py index 809a4b6d..5928acb2 100644 --- a/preferences/admin.py +++ b/preferences/admin.py @@ -34,7 +34,10 @@ from .models import ( OptionalTopologie, GeneralOption, Service, +<<<<<<< HEAD MailContact, +======= +>>>>>>> 5a88882... Ajoute le réglage reminder et factorise la liste des services Reminder, AssoOption, MailMessageOption, diff --git a/preferences/forms.py b/preferences/forms.py index 5b2660d3..3dcbd00c 100644 --- a/preferences/forms.py +++ b/preferences/forms.py @@ -228,6 +228,7 @@ class ServiceForm(FormRevMixin, ModelForm): self.fields['image'].label = _("Image") + class DelServiceForm(Form): """Suppression de services sur la page d'accueil""" services = forms.ModelMultipleChoiceField( @@ -280,3 +281,15 @@ class ReminderForm(FormRevMixin, ModelForm): def __init__(self, *args, **kwargs): prefix = kwargs.pop('prefix', self.Meta.model.__name__) super(ReminderForm, self).__init__(*args, prefix=prefix, **kwargs) + +class ReminderForm(FormRevMixin, ModelForm): + """Edition, ajout de rappel""" + class Meta: + model = Reminder + fields = '__all__' + + def __init__(self, *args, **kwargs): + prefix = kwargs.pop('prefix', self.Meta.model.__name__) + super(ReminderForm, self).__init__(*args, prefix=prefix, **kwargs) + + diff --git a/preferences/migrations/0035_reminder.py b/preferences/migrations/0035_reminder.py new file mode 100644 index 00000000..eaba7753 --- /dev/null +++ b/preferences/migrations/0035_reminder.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.7 on 2018-05-05 10:53 +from __future__ import unicode_literals + +from django.db import migrations, models +import re2o.mixins + + +class Migration(migrations.Migration): + + dependencies = [ + ('preferences', '0034_auto_20180416_1120'), + ] + + operations = [ + migrations.CreateModel( + name='Reminder', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('days', models.IntegerField(default=7, help_text="Délais entre le mail et la fin d'adhésion", unique=True)), + ('message', models.CharField(blank=True, default='', max_length=255, null=True)), + ], + options={ + 'permissions': (('view_reminder', 'Peut voir un objet reminder'),), + }, + bases=(re2o.mixins.AclMixin, models.Model), + ), + ] diff --git a/preferences/templates/preferences/aff_reminder.html b/preferences/templates/preferences/aff_reminder.html new file mode 100644 index 00000000..4bcaacce --- /dev/null +++ b/preferences/templates/preferences/aff_reminder.html @@ -0,0 +1,47 @@ +{% comment %} +Re2o est un logiciel d'administration développé initiallement au rezometz. Il +se veut agnostique au réseau considéré, de manière à être installable en +quelques clics. + +Copyright © 2017 Gabriel Détraz +Copyright © 2017 Goulven Kermarec +Copyright © 2017 Augustin Lemesle + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +{% endcomment %} +{% load acl %} + + + + + + + + + + {% for reminder in reminder_list %} + + + + + + {% endfor %} +
Nombre de jours avant le rappelMessage custom pour ce rappel
{{ reminder.days }}{{ reminder.message }} + {% can_edit reminder %} + {% include 'buttons/edit.html' with href='preferences:edit-reminder' id=reminder.id %} + {% acl_end %} + {% include 'buttons/history.html' with href='preferences:history' name='reminder' id=reminder.id %} +
+ diff --git a/preferences/templates/preferences/display_preferences.html b/preferences/templates/preferences/display_preferences.html index 05154246..356006c0 100644 --- a/preferences/templates/preferences/display_preferences.html +++ b/preferences/templates/preferences/display_preferences.html @@ -247,6 +247,16 @@ with this program; if not, write to the Free Software Foundation, Inc., {% endfor %} + + {% for line in assooptions %} + + {% for text, field in line %} + + + {% endfor %} + + {% endfor %} +
{{ field }}{{ text }}

Options pour le mail de fin d'adhésion

diff --git a/preferences/urls.py b/preferences/urls.py index 1f6dffdd..b882a9dd 100644 --- a/preferences/urls.py +++ b/preferences/urls.py @@ -75,6 +75,13 @@ urlpatterns = [ url(r'^del_service/$', views.del_service, name='del-service'), url(r'^add_mailcontact/$', views.add_mailcontact, name='add-mailcontact'), url(r'^add_reminder/$', views.add_reminder, name='add-reminder'), + url(r'^add_reminder/$', views.add_reminder, name='add-reminder'), + url( + r'^edit_reminder/(?P[0-9]+)$', + views.edit_reminder, + name='edit-reminder' + ), + url(r'^del_reminder/$', views.del_reminder, name='del-reminder'), url( r'^edit_reminder/(?P[0-9]+)$', views.edit_reminder, diff --git a/preferences/views.py b/preferences/views.py index a4724be1..778cb7c1 100644 --- a/preferences/views.py +++ b/preferences/views.py @@ -44,7 +44,7 @@ from re2o.views import form from re2o.acl import can_create, can_edit, can_delete, can_view_all from .forms import ( - ServiceForm, DelServiceForm, MailContactForm, DelMailContactForm, ReminderForm + ServiceForm, DelServiceForm, MailContactForm, DelMailContactForm, ReminderForm, ReminderForm ) from .models import ( diff --git a/re2o/views.py b/re2o/views.py index 15becb35..16ef98d9 100644 --- a/re2o/views.py +++ b/re2o/views.py @@ -62,12 +62,128 @@ def index(request): twitter_account_name = HomeOption.get_cached_value('twitter_account_name') asso_name = AssoOption.get_cached_value('pseudo') return form({ +<<<<<<< HEAD 'services_urls': services, 'twitter_url': twitter_url, 'twitter_account_name': twitter_account_name, 'facebook_url': facebook_url, 'asso_name': asso_name }, 're2o/index.html', request) +======= + 'services_urls': services, + 'twitter_url': twitter_url, + 'twitter_account_name' : twitter_account_name, + 'facebook_url': facebook_url, + 'asso_name': asso_name + }, 're2o/index.html', request) + + +#: Binding the corresponding char sequence of history url to re2o models. +HISTORY_BIND = { + 'users': { + 'user': users.models.User, + 'ban': users.models.Ban, + 'whitelist': users.models.Whitelist, + 'school': users.models.School, + 'listright': users.models.ListRight, + 'serviceuser': users.models.ServiceUser, + 'listshell': users.models.ListShell, + }, + 'preferences': { + 'service': preferences.models.Service, + 'reminder': preferences.models.Reminder, + }, + 'cotisations': { + 'facture': cotisations.models.Facture, + 'article': cotisations.models.Article, + 'paiement': cotisations.models.Paiement, + 'banque': cotisations.models.Banque, + }, + 'topologie': { + 'switch': topologie.models.Switch, + 'port': topologie.models.Port, + 'room': topologie.models.Room, + 'stack': topologie.models.Stack, + 'modelswitch': topologie.models.ModelSwitch, + 'constructorswitch': topologie.models.ConstructorSwitch, + 'accesspoint': topologie.models.AccessPoint, + 'switchbay': topologie.models.SwitchBay, + 'building': topologie.models.Building, + }, + 'machines': { + 'machine': machines.models.Machine, + 'interface': machines.models.Interface, + 'domain': machines.models.Domain, + 'machinetype': machines.models.MachineType, + 'iptype': machines.models.IpType, + 'extension': machines.models.Extension, + 'soa': machines.models.SOA, + 'mx': machines.models.Mx, + 'txt': machines.models.Txt, + 'srv': machines.models.Srv, + 'ns': machines.models.Ns, + 'service': machines.models.Service, + 'vlan': machines.models.Vlan, + 'nas': machines.models.Nas, + 'ipv6list': machines.models.Ipv6List, + }, +} + + +@login_required +def history(request, application, object_name, object_id): + """Render history for a model. + + The model is determined using the `HISTORY_BIND` dictionnary if none is + found, raises a Http404. The view checks if the user is allowed to see the + history using the `can_view` method of the model. + + Args: + request: The request sent by the user. + object_name: Name of the model. + object_id: Id of the object you want to acces history. + + Returns: + The rendered page of history if access is granted, else the user is + redirected to their profile page, with an error message. + + Raises: + Http404: This kind of models doesn't have history. + """ + try: + model = HISTORY_BIND[application][object_name] + except KeyError: + raise Http404(u"Il n'existe pas d'historique pour ce modèle.") + object_name_id = object_name + 'id' + kwargs = {object_name_id: object_id} + try: + instance = model.get_instance(**kwargs) + except model.DoesNotExist: + messages.error(request, u"Entrée inexistante") + return redirect(reverse( + 'users:profil', + kwargs={'userid': str(request.user.id)} + )) + can, msg = instance.can_view(request.user) + if not can: + messages.error(request, msg or "Vous ne pouvez pas accéder à ce menu") + return redirect(reverse( + 'users:profil', + kwargs={'userid': str(request.user.id)} + )) + pagination_number = GeneralOption.get_cached_value('pagination_number') + reversions = Version.objects.get_for_object(instance) + if hasattr(instance, 'linked_objects'): + for related_object in chain(instance.linked_objects()): + reversions = (reversions | + Version.objects.get_for_object(related_object)) + reversions = re2o_paginator(request, reversions, pagination_number) + return render( + request, + 're2o/history.html', + {'reversions': reversions, 'object': instance} + ) +>>>>>>> 5a88882... Ajoute le réglage reminder et factorise la liste des services def about_page(request):