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.,
+ +
Url du compte twitter | +{{ accueiloptions.twitter_url }} | +Nom utilisé pour afficher le compte | +{{ accueiloptions.twitter_account_name }} | +
---|---|---|---|
Url du compte facebook | +{{ accueiloptions.facebook_url }} | +