8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-22 11:23:10 +00:00
This commit is contained in:
root 2018-08-31 20:41:04 +02:00
parent 3e679757af
commit e4247e9cb3
8 changed files with 193 additions and 20 deletions

View file

@ -148,7 +148,7 @@ def new_facture(request, user, userid):
p.facture = new_invoice_instance p.facture = new_invoice_instance
p.save() p.save()
send_mail_invoice(new_invoice_instance) #send_mail_invoice(new_invoice_instance)
return new_invoice_instance.paiement.end_payment( return new_invoice_instance.paiement.end_payment(
new_invoice_instance, new_invoice_instance,

View file

@ -35,6 +35,7 @@ from .models import (
GeneralOption, GeneralOption,
Service, Service,
MailContact, MailContact,
Reminder,
AssoOption, AssoOption,
MailMessageOption, MailMessageOption,
HomeOption HomeOption
@ -85,6 +86,9 @@ class HomeOptionAdmin(VersionAdmin):
"""Class admin options home""" """Class admin options home"""
pass pass
class ReminderAdmin(VersionAdmin):
"""Class reminder"""
pass
admin.site.register(OptionalUser, OptionalUserAdmin) admin.site.register(OptionalUser, OptionalUserAdmin)
admin.site.register(OptionalMachine, OptionalMachineAdmin) admin.site.register(OptionalMachine, OptionalMachineAdmin)
@ -93,5 +97,6 @@ admin.site.register(GeneralOption, GeneralOptionAdmin)
admin.site.register(HomeOption, HomeOptionAdmin) admin.site.register(HomeOption, HomeOptionAdmin)
admin.site.register(Service, ServiceAdmin) admin.site.register(Service, ServiceAdmin)
admin.site.register(MailContact, MailContactAdmin) admin.site.register(MailContact, MailContactAdmin)
admin.site.register(Reminder, ReminderAdmin)
admin.site.register(AssoOption, AssoOptionAdmin) admin.site.register(AssoOption, AssoOptionAdmin)
admin.site.register(MailMessageOption, MailMessageOptionAdmin) admin.site.register(MailMessageOption, MailMessageOptionAdmin)

View file

@ -24,6 +24,7 @@ Formulaire d'edition des réglages : user, machine, topologie, asso...
""" """
from __future__ import unicode_literals from __future__ import unicode_literals
from re2o.mixins import FormRevMixin
from django.forms import ModelForm, Form from django.forms import ModelForm, Form
from django import forms from django import forms
@ -39,6 +40,7 @@ from .models import (
HomeOption, HomeOption,
Service, Service,
MailContact MailContact
Reminder
) )
@ -211,7 +213,7 @@ class EditHomeOptionForm(ModelForm):
self.fields['twitter_account_name'].label = _("Twitter account name") self.fields['twitter_account_name'].label = _("Twitter account name")
class ServiceForm(ModelForm): class ServiceForm(FormRevMixin, ModelForm):
"""Edition, ajout de services sur la page d'accueil""" """Edition, ajout de services sur la page d'accueil"""
class Meta: class Meta:
model = Service model = Service
@ -269,3 +271,12 @@ class DelMailContactForm(Form):
else: else:
self.fields['mailcontacts'].queryset = MailContact.objects.all() self.fields['mailcontacts'].queryset = MailContact.objects.all()
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

@ -215,6 +215,32 @@ def optionaltopologie_post_save(**kwargs):
topologie_pref.set_in_cache() topologie_pref.set_in_cache()
class Reminder(AclMixin, models.Model):
"""Options pour les mails de notification de fin d'adhésion.
Days: liste des nombres de jours pour lesquells un mail est envoyé
optionalMessage: message additionel pour le mail
"""
PRETTY_NAME="Options pour le mail de fin d'adhésion"
days = models.IntegerField(
default=7,
unique=True,
help_text="Délais entre le mail et la fin d'adhésion"
)
message = models.CharField(
max_length=255,
default="",
null=True,
blank=True,
help_text="Message affiché spécifiquement pour ce rappel"
)
class Meta:
permissions = (
("view_reminder", "Peut voir un objet reminder"),
)
class GeneralOption(AclMixin, PreferencesModel): class GeneralOption(AclMixin, PreferencesModel):
"""Options générales : nombre de resultats par page, nom du site, """Options générales : nombre de resultats par page, nom du site,
temps les liens sont valides""" temps les liens sont valides"""

View file

@ -224,8 +224,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% acl_end %} {% acl_end %}
<a class="btn btn-danger btn-sm" role="button" href="{% url 'preferences:del-mailcontact' %}"><i class="fa fa-trash"></i>{% trans "Delete one or several addresses" %}</a> <a class="btn btn-danger btn-sm" role="button" href="{% url 'preferences:del-mailcontact' %}"><i class="fa fa-trash"></i>{% trans "Delete one or several addresses" %}</a>
{% include "preferences/aff_mailcontact.html" with mailcontact_list=mailcontact_list %} {% include "preferences/aff_mailcontact.html" with mailcontact_list=mailcontact_list %}
<p>
</p>
<table class="table table-striped"> <table class="table table-striped">
<tr> <tr>
<th>{% trans "Twitter account URL" %}</th> <th>{% trans "Twitter account URL" %}</th>
@ -238,5 +237,26 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<td>{{ homeoptions.facebook_url }}</td> <td>{{ homeoptions.facebook_url }}</td>
</tr> </tr>
</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>
{% can_create preferences.Reminder%}
<a class="btn btn-primary btn-sm" role="button" href="{% url 'preferences:add-reminder' %}"><i class="fa fa-plus"></i> Ajouter un rappel</a>
{% acl_end %}
{% include "preferences/aff_reminder.html" with reminder_list=reminder_list %}
<br />
<br />
<br />
{% endblock %} {% endblock %}

View file

@ -74,6 +74,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'^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_mailcontact/(?P<mailcontactid>[0-9]+)$', r'^edit_mailcontact/(?P<mailcontactid>[0-9]+)$',
views.edit_mailcontact, views.edit_mailcontact,

View file

@ -41,11 +41,12 @@ from django.utils.translation import ugettext as _
from reversion import revisions as reversion from reversion import revisions as reversion
from re2o.views import form from re2o.views import form
from re2o.acl import can_create, can_edit, can_delete_set, 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 ServiceForm, DelServiceForm, MailContactForm, DelMailContactForm, ReminderForm
) )
from .models import ( from .models import (
Service, Service,
MailContact, MailContact,
@ -133,11 +134,8 @@ def add_service(request):
"""Ajout d'un service de la page d'accueil""" """Ajout d'un service de la page d'accueil"""
service = ServiceForm(request.POST or None, request.FILES or None) service = ServiceForm(request.POST or None, request.FILES or None)
if service.is_valid(): if service.is_valid():
with transaction.atomic(), reversion.create_revision(): service.save()
service.save() messages.success(request, "Ce service a été ajouté")
reversion.set_user(request.user)
reversion.set_comment("Creation")
messages.success(request, _("The service was added."))
return redirect(reverse('preferences:display-options')) return redirect(reverse('preferences:display-options'))
return form( return form(
{'preferenceform': service, 'action_name': _("Add a service")}, {'preferenceform': service, 'action_name': _("Add a service")},
@ -156,15 +154,8 @@ def edit_service(request, service_instance, **_kwargs):
instance=service_instance instance=service_instance
) )
if service.is_valid(): if service.is_valid():
with transaction.atomic(), reversion.create_revision(): service.save()
service.save() messages.success(request, "Service modifié")
reversion.set_user(request.user)
reversion.set_comment(
"Field(s) edited: %s" % ', '.join(
field for field in service.changed_data
)
)
messages.success(request, _("The service was edited."))
return redirect(reverse('preferences:display-options')) return redirect(reverse('preferences:display-options'))
return form( return form(
{'preferenceform': service, 'action_name': _("Edit")}, {'preferenceform': service, 'action_name': _("Edit")},
@ -172,6 +163,34 @@ def edit_service(request, service_instance, **_kwargs):
request request
) )
@login_required
@can_delete(Service)
def del_service(request, service_instance, **_kwargs):
"""Destruction d'un service"""
if request.method == "POST":
service_instance.delete()
messages.success(request, "Le service a été détruit")
return redirect(reverse('preferences:display-options'))
return form(
{'objet': service_instance, 'objet_name': 'service'},
'preferences/delete.html',
request
)
@login_required
@can_create(Reminder)
def add_reminder(request):
"""Ajout d'un rappel"""
reminder = ReminderForm(request.POST or None)
if reminder.is_valid():
reminder.save()
messages.success(request, "Ce rappel a été ajouté")
return redirect(reverse('preferences:display-options'))
return form(
{'preferenceform': reminder, 'action_name': 'Ajouter'},
'preferences/preferences.html',
request
)
@login_required @login_required
@can_delete_set(Service) @can_delete_set(Service)
@ -232,6 +251,17 @@ def edit_mailcontact(request, mailcontact_instance, **_kwargs):
return redirect(reverse('preferences:display-options')) return redirect(reverse('preferences:display-options'))
return form( return form(
{'preferenceform': mailcontact, 'action_name': _("Edit")}, {'preferenceform': mailcontact, 'action_name': _("Edit")},
@can_edit(Reminder)
def edit_reminder(request, reminder_instance, **_kwargs):
"""Edition des rappels"""
reminder = ReminderForm(request.POST or None, instance=reminder_instance)
if reminder.is_valid():
reminder.save()
messages.success(request, "Service modifié")
return redirect(reverse('preferences:display-options'))
return form(
{'preferenceform': reminder, 'action_name': 'Editer'},
'preferences/preferences.html', 'preferences/preferences.html',
request request
) )
@ -258,3 +288,18 @@ def del_mailcontact(request, instances):
request request
) )
@login_required
@can_delete(Reminder)
def del_reminder(request, reminder_instance, **_kwargs):
"""Destruction d'un reminder"""
if request.method == "POST":
reminder_instance.delete()
messages.success(request, "Le reminder a été détruit")
return redirect(reverse('preferences:display-options'))
return form(
{'objet': reminder_instance, 'objet_name': 'reminder'},
'preferences/delete.html',
request
)

View file

@ -79,6 +79,65 @@ from django.contrib.contenttypes.models import ContentType
register = template.Library() register = template.Library()
MODEL_NAME = {
# cotisations
'Facture': cotisations.models.Facture,
'Vente': cotisations.models.Vente,
'Article': cotisations.models.Article,
'Banque': cotisations.models.Banque,
'Paiement': cotisations.models.Paiement,
'Cotisation': cotisations.models.Cotisation,
# machines
'Machine': machines.models.Machine,
'MachineType': machines.models.MachineType,
'IpType': machines.models.IpType,
'Vlan': machines.models.Vlan,
'Nas': machines.models.Nas,
'SOA': machines.models.SOA,
'Extension': machines.models.Extension,
'Mx': machines.models.Mx,
'Ns': machines.models.Ns,
'Txt': machines.models.Txt,
'Srv': machines.models.Srv,
'Interface': machines.models.Interface,
'Domain': machines.models.Domain,
'IpList': machines.models.IpList,
'Ipv6List': machines.models.Ipv6List,
'machines.Service': machines.models.Service,
'Service_link': machines.models.Service_link,
'OuverturePortList': machines.models.OuverturePortList,
'OuverturePort': machines.models.OuverturePort,
# preferences
'OptionalUser': preferences.models.OptionalUser,
'OptionalMachine': preferences.models.OptionalMachine,
'OptionalTopologie': preferences.models.OptionalTopologie,
'GeneralOption': preferences.models.GeneralOption,
'preferences.Service': preferences.models.Service,
'preferences.Reminder': preferences.models.Reminder,
'AssoOption': preferences.models.AssoOption,
'MailMessageOption': preferences.models.MailMessageOption,
# topologie
'Stack': topologie.models.Stack,
'Switch': topologie.models.Switch,
'AccessPoint': topologie.models.AccessPoint,
'ModelSwitch': topologie.models.ModelSwitch,
'ConstructorSwitch': topologie.models.ConstructorSwitch,
'Port': topologie.models.Port,
'Room': topologie.models.Room,
'Building': topologie.models.Building,
'SwitchBay': topologie.models.SwitchBay,
# users
'User': users.models.User,
'Adherent': users.models.Adherent,
'Club': users.models.Club,
'ServiceUser': users.models.ServiceUser,
'School': users.models.School,
'ListRight': users.models.ListRight,
'ListShell': users.models.ListShell,
'Ban': users.models.Ban,
'Whitelist': users.models.Whitelist,
}
def get_model(model_name): def get_model(model_name):
"""Retrieve the model object from its name""" """Retrieve the model object from its name"""