8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-22 11:23:10 +00:00

Ajoute le réglage reminder et factorise la liste des services

This commit is contained in:
Gabriel Detraz 2018-05-06 19:11:12 +02:00 committed by grisel-davy
parent e4247e9cb3
commit 168579edb8
8 changed files with 225 additions and 1 deletions

View file

@ -34,7 +34,10 @@ from .models import (
OptionalTopologie, OptionalTopologie,
GeneralOption, GeneralOption,
Service, Service,
<<<<<<< HEAD
MailContact, MailContact,
=======
>>>>>>> 5a88882... Ajoute le réglage reminder et factorise la liste des services
Reminder, Reminder,
AssoOption, AssoOption,
MailMessageOption, MailMessageOption,

View file

@ -228,6 +228,7 @@ class ServiceForm(FormRevMixin, ModelForm):
self.fields['image'].label = _("Image") self.fields['image'].label = _("Image")
class DelServiceForm(Form): class DelServiceForm(Form):
"""Suppression de services sur la page d'accueil""" """Suppression de services sur la page d'accueil"""
services = forms.ModelMultipleChoiceField( services = forms.ModelMultipleChoiceField(
@ -280,3 +281,15 @@ class ReminderForm(FormRevMixin, ModelForm):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
prefix = kwargs.pop('prefix', self.Meta.model.__name__) prefix = kwargs.pop('prefix', self.Meta.model.__name__)
super(ReminderForm, self).__init__(*args, prefix=prefix, **kwargs) 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)

View file

@ -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),
),
]

View file

@ -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 %}
<table class="table table-striped">
<thead>
<tr>
<th>Nombre de jours avant le rappel</th>
<th>Message custom pour ce rappel</th>
<th></th>
<th></th>
</tr>
</thead>
{% for reminder in reminder_list %}
<tr>
<td>{{ reminder.days }}</td>
<td>{{ reminder.message }}</td>
<td class="text-right">
{% 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 %}
</td>
</tr>
{% endfor %}
</table>

View file

@ -247,6 +247,16 @@ with this program; if not, write to the Free Software Foundation, Inc.,
</tr> </tr>
{% endfor %} {% endfor %}
</table> </table>
<table class="table table-striped">
{% for line in assooptions %}
<tr>
{% for text, field in line %}
<th>{{ field }}</th>
<td>{{ text }}</td>
{% endfor %}
</tr>
{% endfor %}
</table>
<h2>Options pour le mail de fin d'adhésion</h2> <h2>Options pour le mail de fin d'adhésion</h2>

View file

@ -75,6 +75,13 @@ urlpatterns = [
url(r'^del_service/$', views.del_service, name='del-service'), url(r'^del_service/$', views.del_service, name='del-service'),
url(r'^add_mailcontact/$', views.add_mailcontact, name='add-mailcontact'), 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'^add_reminder/$', views.add_reminder, name='add-reminder'),
url(
r'^edit_reminder/(?P<reminderid>[0-9]+)$',
views.edit_reminder,
name='edit-reminder'
),
url(r'^del_reminder/$', views.del_reminder, name='del-reminder'),
url( url(
r'^edit_reminder/(?P<reminderid>[0-9]+)$', r'^edit_reminder/(?P<reminderid>[0-9]+)$',
views.edit_reminder, views.edit_reminder,

View file

@ -44,7 +44,7 @@ from re2o.views import form
from re2o.acl import can_create, can_edit, can_delete, can_view_all from re2o.acl import can_create, can_edit, can_delete, can_view_all
from .forms import ( from .forms import (
ServiceForm, DelServiceForm, MailContactForm, DelMailContactForm, ReminderForm ServiceForm, DelServiceForm, MailContactForm, DelMailContactForm, ReminderForm, ReminderForm
) )
from .models import ( from .models import (

View file

@ -62,12 +62,128 @@ def index(request):
twitter_account_name = HomeOption.get_cached_value('twitter_account_name') twitter_account_name = HomeOption.get_cached_value('twitter_account_name')
asso_name = AssoOption.get_cached_value('pseudo') asso_name = AssoOption.get_cached_value('pseudo')
return form({ return form({
<<<<<<< HEAD
'services_urls': services, 'services_urls': services,
'twitter_url': twitter_url, 'twitter_url': twitter_url,
'twitter_account_name': twitter_account_name, 'twitter_account_name': twitter_account_name,
'facebook_url': facebook_url, 'facebook_url': facebook_url,
'asso_name': asso_name 'asso_name': asso_name
}, 're2o/index.html', request) }, '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): def about_page(request):