diff --git a/preferences/forms.py b/preferences/forms.py index b4a79dd0..b33e4704 100644 --- a/preferences/forms.py +++ b/preferences/forms.py @@ -27,9 +27,16 @@ from __future__ import unicode_literals from django.forms import ModelForm, Form from django import forms -from .models import OptionalUser, OptionalMachine, OptionalTopologie -from .models import GeneralOption, AssoOption, MailMessageOption, Service - +from .models import ( + OptionalUser, + OptionalMachine, + OptionalTopologie, + GeneralOption, + AssoOption, + MailMessageOption, + AccueilOption, + Service +) class EditOptionalUserForm(ModelForm): """Formulaire d'édition des options de l'user. (solde, telephone..)""" @@ -185,6 +192,21 @@ class EditMailMessageOptionForm(ModelForm): mail de bienvenue en anglais' +class EditAccueilOptionForm(ModelForm): + """Formulaire d'édition des options de la page d'accueil""" + class Meta: + model = AccueilOption + fields = '__all__' + + def __init__(self, *args, **kwargs): + prefix = kwargs.pop('prefix', self.Meta.model.__name__) + super(EditAccueilOptionForm, 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/0033_accueiloption.py b/preferences/migrations/0033_accueiloption.py new file mode 100644 index 00000000..1b665e61 --- /dev/null +++ b/preferences/migrations/0033_accueiloption.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.7 on 2018-04-16 02:35 +from __future__ import unicode_literals + +from django.db import migrations, models +import re2o.mixins + + +class Migration(migrations.Migration): + + dependencies = [ + ('preferences', '0032_optionaluser_shell_default'), + ] + + operations = [ + migrations.CreateModel( + name='AccueilOption', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('facebook_url', models.URLField(blank=True, help_text='Url du compte facebook', null=True)), + ('twitter_url', models.URLField(blank=True, help_text='Url du compte twitter', null=True)), + ('twitter_account_name', models.CharField(blank=True, help_text='Nom du compte à afficher', max_length=32, null=True)), + ], + options={ + 'permissions': (('view_accueiloption', "Peut voir les options de l'accueil"),), + }, + bases=(re2o.mixins.AclMixin, models.Model), + ), + ] diff --git a/preferences/models.py b/preferences/models.py index e64d49ab..85f51c52 100644 --- a/preferences/models.py +++ b/preferences/models.py @@ -331,6 +331,40 @@ def assooption_post_save(**kwargs): asso_pref.set_in_cache() +class AccueilOption(AclMixin, PreferencesModel): + """Reglages de la page d'accueil""" + PRETTY_NAME = "Options de la page d'accueil" + + facebook_url = models.URLField( + null=True, + blank=True, + help_text="Url du compte facebook" + ) + twitter_url = models.URLField( + null=True, + blank=True, + help_text="Url du compte twitter" + ) + twitter_account_name = models.CharField( + max_length=32, + null=True, + blank=True, + help_text="Nom du compte à afficher" + ) + + class Meta: + permissions = ( + ("view_accueiloption", "Peut voir les options de l'accueil"), + ) + + +@receiver(post_save, sender=AccueilOption) +def accueiloption_post_save(**kwargs): + """Ecriture dans le cache""" + accueil_pref = kwargs['instance'] + accueil_pref.set_in_cache() + + class MailMessageOption(AclMixin, models.Model): """Reglages, mail de bienvenue et autre""" PRETTY_NAME = "Options de corps de mail" diff --git a/preferences/templates/preferences/display_preferences.html b/preferences/templates/preferences/display_preferences.html index 4b234c5c..575ddcac 100644 --- a/preferences/templates/preferences/display_preferences.html +++ b/preferences/templates/preferences/display_preferences.html @@ -211,12 +211,31 @@ with this program; if not, write to the Free Software Foundation, Inc., {{ mailmessageoptions.welcome_mail_en | safe }} -

Liste des services page d'accueil

+

Liste des services et préférences page d'accueil

{% can_create preferences.Service%} Ajouter un service {% acl_end %} Supprimer un ou plusieurs service {% include "preferences/aff_service.html" with service_list=service_list %} + + + + Editer + +

+ + + + + + + + + + + + +
Url du compte twitter{{ accueiloptions.twitter_url }}Nom utilisé pour afficher le compte{{ accueiloptions.twitter_account_name }}
Url du compte facebook{{ accueiloptions.facebook_url }}



diff --git a/preferences/urls.py b/preferences/urls.py index 9b51a432..e0391789 100644 --- a/preferences/urls.py +++ b/preferences/urls.py @@ -57,6 +57,11 @@ urlpatterns = [ views.edit_options, name='edit-options' ), + url( + r'^edit_options/(?P

AccueilOption)$', + views.edit_options, + name='edit-options' + ), url( r'^edit_options/(?P
MailMessageOption)$', views.edit_options, diff --git a/preferences/views.py b/preferences/views.py index 3393aa75..3f14191d 100644 --- a/preferences/views.py +++ b/preferences/views.py @@ -43,8 +43,16 @@ from re2o.views import form from re2o.acl import can_create, can_edit, can_delete_set, can_view_all from .forms import ServiceForm, DelServiceForm -from .models import Service, OptionalUser, OptionalMachine, AssoOption -from .models import MailMessageOption, GeneralOption, OptionalTopologie +from .models import ( + Service, + OptionalUser, + OptionalMachine, + AssoOption, + MailMessageOption, + GeneralOption, + OptionalTopologie, + AccueilOption +) from . import models from . import forms @@ -56,6 +64,7 @@ from . import forms @can_view_all(GeneralOption) @can_view_all(AssoOption) @can_view_all(MailMessageOption) +@can_view_all(AccueilOption) def display_options(request): """Vue pour affichage des options (en vrac) classé selon les models correspondants dans un tableau""" @@ -64,6 +73,7 @@ def display_options(request): topologieoptions, _created = OptionalTopologie.objects.get_or_create() generaloptions, _created = GeneralOption.objects.get_or_create() assooptions, _created = AssoOption.objects.get_or_create() + accueiloptions, _created = AccueilOption.objects.get_or_create() mailmessageoptions, _created = MailMessageOption.objects.get_or_create() service_list = Service.objects.all() return form({ @@ -72,6 +82,7 @@ def display_options(request): 'topologieoptions': topologieoptions, 'generaloptions': generaloptions, 'assooptions': assooptions, + 'accueiloptions': accueiloptions, 'mailmessageoptions': mailmessageoptions, 'service_list': service_list }, 'preferences/display_preferences.html', request) diff --git a/re2o/templates/re2o/sidebar.html b/re2o/templates/re2o/sidebar.html index 4f69298b..ad64caae 100644 --- a/re2o/templates/re2o/sidebar.html +++ b/re2o/templates/re2o/sidebar.html @@ -25,4 +25,30 @@ with this program; if not, write to the Free Software Foundation, Inc., {% block sidebar %} + +{% if facebook_url %} + + +
+ + +
+ +{% endif %} + +{% if twitter_url %} + + + + + +{% endif %} + {% endblock %} +