diff --git a/preferences/forms.py b/preferences/forms.py index c3d6376f..981bf5e2 100644 --- a/preferences/forms.py +++ b/preferences/forms.py @@ -45,7 +45,8 @@ from .models import ( RadiusOption, CotisationsOption, DocumentTemplate, - RadiusAttribute + RadiusAttribute, + Mandate ) from topologie.models import Switch @@ -261,6 +262,17 @@ class EditCotisationsOptionForm(ModelForm): fields = '__all__' +class MandateForm(ModelForm): + """Edit Mandates""" + class Meta: + model = Mandate + fields = '__all__' + + def __init__(self, *args, **kwargs): + prefix = kwargs.pop('prefix', self.Meta.model.__name__) + super(MandateForm, self).__init__(*args, prefix=prefix, **kwargs) + + class ServiceForm(ModelForm): """Edition, ajout de services sur la page d'accueil""" class Meta: diff --git a/preferences/migrations/0063_mandate.py b/preferences/migrations/0063_mandate.py new file mode 100644 index 00000000..f28acee4 --- /dev/null +++ b/preferences/migrations/0063_mandate.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.23 on 2019-09-21 18:23 +from __future__ import unicode_literals + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion +from django.utils import timezone +import re2o.mixins + + +def create_current_mandate(apps, schema_editor): + AssoOption = apps.get_model('preferences', 'AssoOption') + Mandate = apps.get_model('preferences', 'Mandate') + Adherent = apps.get_model('users', 'Adherent') + pres_name = AssoOption.objects.get_or_create()[0].pres_name + l = pres_name.split(' ') + try: + name, surname = l[0], l[1] + president = Adherent.objects.get(name__icontains=name, surname__icontains=surname) + Mandate.objects.create( + president=president, + start_date=timezone.now(), + ) + except Exception as e: + print("Warning : I was unable to find an adherent corresponding to %s. You might want to edit your preferences afterward." % pres_name) + + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('preferences', '0062_auto_20190910_1909'), + ] + + operations = [ + migrations.CreateModel( + name='Mandate', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('start_date', models.DateTimeField(verbose_name='start date')), + ('end_date', models.DateTimeField(blank=True, null=True, verbose_name='end date')), + ('president', models.ForeignKey(blank=True, help_text='Displayed on subscription vouchers', null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL, verbose_name='President of the association')), + ], + options={ + 'verbose_name': 'Mandate', + 'verbose_name_plural': 'Mandates', + 'permissions': (('view_mandate', 'Can view a mandate'),), + }, + bases=(re2o.mixins.RevMixin, re2o.mixins.AclMixin, models.Model), + ), + migrations.RunPython(create_current_mandate), + ] diff --git a/preferences/models.py b/preferences/models.py index 39eb814e..90655d48 100644 --- a/preferences/models.py +++ b/preferences/models.py @@ -501,6 +501,41 @@ class MailContact(AclMixin, models.Model): def __str__(self): return(self.address) +class Mandate(RevMixin, AclMixin, models.Model): + class Meta: + verbose_name = _("Mandate") + verbose_name_plural = _("Mandates") + permissions = ( + ("view_mandate", _("Can view a mandate")), + ) + + president = models.ForeignKey( + 'users.User', + on_delete=models.SET_NULL, + null=True, + blank=True, + verbose_name=_("President of the association"), + help_text=_("Displayed on subscription vouchers") + ) + start_date = models.DateTimeField( + verbose_name=_("start date") + ) + end_date = models.DateTimeField( + verbose_name=_("end date"), + blank=True, + null=True + ) + + @classmethod + def get_mandate(cls, date=timezone.now): + if callable(date): + date = date() + return cls.objects.get( + start_date__gte=date, end_date__lte=date + ) + + def is_over(self): + return self.end_date is None class AssoOption(AclMixin, PreferencesModel): """Options générales de l'asso : siret, addresse, nom, etc""" diff --git a/preferences/templates/preferences/aff_mandate.html b/preferences/templates/preferences/aff_mandate.html new file mode 100644 index 00000000..38017985 --- /dev/null +++ b/preferences/templates/preferences/aff_mandate.html @@ -0,0 +1,52 @@ +{% 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 © 2018 Hugo Levy-Falk + +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 i18n %} +{% load acl %} +{% load logs_extra %} + +
{% trans "Start date" %} | +{% trans "End date" %} | +{% trans "President" %} | ++ |
---|---|---|---|
{{mandate.start_date|date:"d/m/Y"}} | +{% if mandate.end_date %}{{mandate.end_date|date:"d/m/Y"}}{% else %}{% trans "In progress." %}{% endif %} | +{{mandate.president.name}} {{mandate.president.surname}} | ++ {% can_edit mandate%} + {% include 'buttons/edit.html' with href='preferences:edit-mandate' id=mandate.id %} + {% acl_end %} + {% can_delete mandate %} + {% include 'buttons/suppr.html' with href='preferences:del-mandate' id=mandate.id %} + {% acl_end %} + {% history_button mandate %} + | +