Commit cf9a1217 authored by Lucas Serrano's avatar Lucas Serrano

[settings] Création de l'apps user_settings

parent c0d35764
......@@ -327,6 +327,13 @@ INTRANET_APPS = (
'label': _(u'Gestion des clubs'),
'test': lambda u: u.groups.filter(name='crans_respo_club'),
},
{
'name': 'user_settings',
'label': _(u'Préférences'),
'category' :'Administration',
'title' : _(u'Réglages des préférences'),
'test': lambda u: True,
},
)
INTRANET_APPS = tuple([ i for i in INTRANET_APPS if i['name'] not in
......
default_app_config = 'user_settings.apps.UserSettingsConfig'
from django.contrib import admin
from models import UserSettings
admin.site.register(UserSettings)
# -*- coding: utf-8 -*-
from django.apps import AppConfig
class UserSettingsConfig(AppConfig):
name = 'user_settings'
verbose_name = 'User Settings'
def ready(self):
import signals
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-02-25 14:43+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: models.py:10
msgid "langue"
msgstr "language"
#: templates/edit.html:3
msgid "Édition des préférences"
msgstr "Settings configuration"
#: templates/edit.html:4
msgid "Préférences"
msgstr "Settings"
#: templates/edit.html:11
msgid "Internationalisation"
msgstr "Internationalization"
#: templates/edit.html:21
msgid "Enregistrer les changements"
msgstr "Save configuration"
#: views.py:24
msgid "Vos préférences ont bien été sauvegardées"
msgstr "Your settings have been saved"
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-02-25 14:43+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
#: models.py:10
msgid "langue"
msgstr ""
#: templates/edit.html:3
msgid "Édition des préférences"
msgstr ""
#: templates/edit.html:4
msgid "Préférences"
msgstr ""
#: templates/edit.html:11
msgid "Internationalisation"
msgstr ""
#: templates/edit.html:21
msgid "Enregistrer les changements"
msgstr ""
#: views.py:24
msgid "Vos préférences ont bien été sauvegardées"
msgstr ""
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.conf import settings
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='UserSettings',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('langue', models.CharField(max_length=2, choices=[(b'fr', 'French'), (b'en', 'English')])),
('user', models.OneToOneField(related_name='settings', to=settings.AUTH_USER_MODEL)),
],
options={
},
bases=(models.Model,),
),
]
# -*- coding: utf-8 -*-
from django.db import models
from django.contrib.auth.models import User
from django.utils.translation import ugettext_lazy as _
from intranet.settings import LANGUAGES
class UserSettings(models.Model):
user = models.OneToOneField(User, related_name='settings')
langue = models.CharField(_(u"langue"), max_length=2, choices=LANGUAGES)
# -*- coding: utf-8 -*-
from django.dispatch import receiver
from django.contrib.auth import user_logged_in
from django.utils import translation
@receiver(user_logged_in)
def restore_user_settings(sender, request, user, **kwargs):
try:
request.session[translation.LANGUAGE_SESSION_KEY] = user.settings.langue
except AttributeError:
pass
<svg xmlns="http://www.w3.org/2000/svg" width="1000" height="1000" viewBox="0 0 1000 1000" id="a">
<g pointer-events="none" stroke="#000" stroke-width="15">
<g transform="translate(375.986 377.186)">
<path d="M317.46-23.242l4.72-.346 21.013 3.6 25.93 10.726V9.262l-25.93 10.727-21.013 3.598-4.72-.346-3.197 27.354 4.672.752 19.617 8.348 22.758 16.417-4.273 18.025-27.704 4.458-21.277-1.344-4.513-1.425-9.42 25.88 4.374 1.81 17.162 12.645 18.357 21.223-8.313 16.554-27.986-2.053-20.393-6.214-4.063-2.427-15.134 23.01 3.838 2.768 13.784 16.264 12.968 24.885-11.907 14.19-26.757-8.45-18.41-10.75-3.394-3.3-20.033 18.9 3.096 3.58 9.66 19.004 6.882 27.204-14.86 11.063-24.088-14.393-15.434-14.706-2.542-3.993-23.85 13.77 2.188 4.2 5.018 20.718.42 28.058-17.008 7.338-20.12-19.56-11.627-17.87-1.552-4.47-26.383 7.897 1.16 4.59.105 21.318-6.06 27.4-18.244 3.216L39.91 341.45l-7.193-20.068-.48-4.71-27.493 1.603.07 4.732L0 343.775l-12.216 25.262-18.493-1.077-9.2-26.51-2.37-21.186.62-4.692-27.123-4.783-1.023 4.62-9.474 19.098-17.713 21.765-17.746-5.313-2.838-27.917 2.58-21.163 1.684-4.422-25.288-10.908-2.06 4.26-13.624 16.398-22.254 17.093-16.043-9.26 3.676-27.82 7.39-19.998 2.66-3.914-22.092-16.446-2.987 3.67-17.037 12.815-25.597 11.5-13.475-12.713 9.992-26.22 11.803-17.755 3.49-3.197-17.702-21.097-3.754 2.882-19.534 8.54-27.558 5.287-10.18-15.477 15.77-23.21 15.58-14.554 4.132-2.305-12.36-24.612-4.317 1.94-20.976 3.804-28.035-1.21-6.335-17.408 20.697-18.948 18.515-10.57 4.554-1.29-6.35-26.796-4.65.89-21.288-1.134-27-7.644-2.15-18.4 24.51-13.663 20.452-6.015 4.728-.205v-27.54l-4.728-.205-20.453-6.014-24.51-13.663 2.15-18.4 27-7.643 21.29-1.135 4.648.89 6.35-26.797-4.553-1.29-18.515-10.57-20.697-18.947 6.335-17.407 28.036-1.212 20.977 3.805 4.317 1.94 12.36-24.612-4.133-2.304-15.578-14.553-15.77-23.21 10.18-15.478 27.558 5.287 19.534 8.54 3.754 2.882 17.702-21.097-3.49-3.196-11.803-17.752-9.992-26.222 13.474-12.713 25.596 11.5 17.038 12.815 2.987 3.67 22.092-16.446-2.66-3.914-7.39-19.998-3.675-27.82 16.043-9.26 22.254 17.092 13.623 16.398 2.06 4.26 25.29-10.908-1.686-4.422-2.578-21.163 2.84-27.917 17.745-5.313 17.713 21.765 9.474 19.098 1.023 4.62 27.122-4.782-.62-4.692 2.37-21.186 9.2-26.51 18.494-1.077L0-343.775l4.815 20.768-.07 4.732 27.492 1.602.48-4.71 7.193-20.067 15.066-23.674 18.243 3.217 6.06 27.4-.105 21.317-1.16 4.59 26.383 7.897 1.553-4.47 11.628-17.87 20.12-19.56 17.01 7.337-.422 28.058-5.018 20.72-2.187 4.197 23.85 13.77 2.543-3.994 15.434-14.706 24.09-14.393 14.858 11.062-6.88 27.203-9.662 19.004-3.096 3.58 20.032 18.9 3.393-3.3 18.41-10.75 26.758-8.45 11.908 14.19-12.968 24.885-13.784 16.264-3.838 2.77 15.134 23.008 4.063-2.427 20.393-6.214 27.986-2.052 8.313 16.555-18.358 21.223-17.163 12.646-4.373 1.81 9.42 25.88 4.512-1.426 21.277-1.344 27.704 4.458 4.273 18.025-22.758 16.417-19.617 8.348-4.672.752z" fill="none"/>
<circle r="50" fill="none"/>
</g>
<g transform="rotate(-2.732 16384.224 -15621.123)">
<path d="M177.115-20.114L190.21-21.6l12.527 1.632 26.29 11.494V8.474l-26.29 11.494L190.21 21.6l-13.095-1.486-5.785 29.082 12.667 3.638 10.95 6.302 19.89 20.68-6.487 15.658-28.686.558-12.2-3.285-11.528-6.385-16.474 24.655 10.31 8.208 7.704 10.013 10.462 26.716-11.984 11.984-26.716-10.462-10.013-7.703-8.208-10.31-24.655 16.473 6.385 11.53 3.285 12.198-.558 28.686-15.658 6.486-20.68-19.89-6.302-10.95-3.638-12.666-29.082 5.785L21.6 190.21l-1.632 12.527-11.494 26.29H-8.474l-11.494-26.29-1.633-12.527 1.486-13.095-29.082-5.785-3.638 12.667-6.302 10.95-20.68 19.89-15.658-6.487-.558-28.686 3.285-12.2 6.385-11.528-24.655-16.474-8.208 10.31-10.013 7.704-26.716 10.462-11.984-11.984 10.462-26.716 7.703-10.013 10.31-8.208-16.473-24.655-11.53 6.385-12.198 3.285-28.686-.558-6.486-15.658 19.89-20.68 10.95-6.302 12.666-3.638-5.785-29.082-13.095 1.487-12.527-1.632-26.29-11.494V-8.474l26.29-11.494 12.527-1.633 13.095 1.486 5.785-29.082-12.667-3.638-10.95-6.302-19.89-20.68 6.487-15.658 28.686-.558 12.2 3.285 11.528 6.385 16.474-24.655-10.31-8.208-7.704-10.013-10.462-26.716 11.984-11.984 26.716 10.462 10.013 7.703 8.208 10.31 24.655-16.473-6.385-11.53-3.285-12.198.558-28.686 15.658-6.486 20.68 19.89 6.302 10.95 3.638 12.666 29.082-5.785-1.487-13.095 1.632-12.527 11.494-26.29H8.474l11.494 26.29L21.6-190.21l-1.486 13.095 29.082 5.785 3.638-12.667 6.302-10.95 20.68-19.89 15.658 6.487.558 28.686-3.285 12.2-6.385 11.528 24.655 16.474 8.208-10.31 10.013-7.704 26.716-10.462 11.984 11.984-10.462 26.716-7.703 10.013-10.31 8.208 16.473 24.655 11.53-6.385 12.198-3.285 28.686.558 6.486 15.658-19.89 20.68-10.95 6.302-12.666 3.638z" fill="none"/>
<circle r="50" fill="none"/>
</g>
</g>
</svg>
<svg xmlns="http://www.w3.org/2000/svg" width="1000" height="1000" viewBox="0 0 1000 1000" id="a">
<g pointer-events="none" stroke="#fff" stroke-width="15">
<g transform="translate(375.986 377.186)">
<path d="M317.46-23.242l4.72-.346 21.013 3.6 25.93 10.726V9.262l-25.93 10.727-21.013 3.598-4.72-.346-3.197 27.354 4.672.752 19.617 8.348 22.758 16.417-4.273 18.025-27.704 4.458-21.277-1.344-4.513-1.425-9.42 25.88 4.374 1.81 17.162 12.645 18.357 21.223-8.313 16.554-27.986-2.053-20.393-6.214-4.063-2.427-15.134 23.01 3.838 2.768 13.784 16.264 12.968 24.885-11.907 14.19-26.757-8.45-18.41-10.75-3.394-3.3-20.033 18.9 3.096 3.58 9.66 19.004 6.882 27.204-14.86 11.063-24.088-14.393-15.434-14.706-2.542-3.993-23.85 13.77 2.188 4.2 5.018 20.718.42 28.058-17.008 7.338-20.12-19.56-11.627-17.87-1.552-4.47-26.383 7.897 1.16 4.59.105 21.318-6.06 27.4-18.244 3.216L39.91 341.45l-7.193-20.068-.48-4.71-27.493 1.603.07 4.732L0 343.775l-12.216 25.262-18.493-1.077-9.2-26.51-2.37-21.186.62-4.692-27.123-4.783-1.023 4.62-9.474 19.098-17.713 21.765-17.746-5.313-2.838-27.917 2.58-21.163 1.684-4.422-25.288-10.908-2.06 4.26-13.624 16.398-22.254 17.093-16.043-9.26 3.676-27.82 7.39-19.998 2.66-3.914-22.092-16.446-2.987 3.67-17.037 12.815-25.597 11.5-13.475-12.713 9.992-26.22 11.803-17.755 3.49-3.197-17.702-21.097-3.754 2.882-19.534 8.54-27.558 5.287-10.18-15.477 15.77-23.21 15.58-14.554 4.132-2.305-12.36-24.612-4.317 1.94-20.976 3.804-28.035-1.21-6.335-17.408 20.697-18.948 18.515-10.57 4.554-1.29-6.35-26.796-4.65.89-21.288-1.134-27-7.644-2.15-18.4 24.51-13.663 20.452-6.015 4.728-.205v-27.54l-4.728-.205-20.453-6.014-24.51-13.663 2.15-18.4 27-7.643 21.29-1.135 4.648.89 6.35-26.797-4.553-1.29-18.515-10.57-20.697-18.947 6.335-17.407 28.036-1.212 20.977 3.805 4.317 1.94 12.36-24.612-4.133-2.304-15.578-14.553-15.77-23.21 10.18-15.478 27.558 5.287 19.534 8.54 3.754 2.882 17.702-21.097-3.49-3.196-11.803-17.752-9.992-26.222 13.474-12.713 25.596 11.5 17.038 12.815 2.987 3.67 22.092-16.446-2.66-3.914-7.39-19.998-3.675-27.82 16.043-9.26 22.254 17.092 13.623 16.398 2.06 4.26 25.29-10.908-1.686-4.422-2.578-21.163 2.84-27.917 17.745-5.313 17.713 21.765 9.474 19.098 1.023 4.62 27.122-4.782-.62-4.692 2.37-21.186 9.2-26.51 18.494-1.077L0-343.775l4.815 20.768-.07 4.732 27.492 1.602.48-4.71 7.193-20.067 15.066-23.674 18.243 3.217 6.06 27.4-.105 21.317-1.16 4.59 26.383 7.897 1.553-4.47 11.628-17.87 20.12-19.56 17.01 7.337-.422 28.058-5.018 20.72-2.187 4.197 23.85 13.77 2.543-3.994 15.434-14.706 24.09-14.393 14.858 11.062-6.88 27.203-9.662 19.004-3.096 3.58 20.032 18.9 3.393-3.3 18.41-10.75 26.758-8.45 11.908 14.19-12.968 24.885-13.784 16.264-3.838 2.77 15.134 23.008 4.063-2.427 20.393-6.214 27.986-2.052 8.313 16.555-18.358 21.223-17.163 12.646-4.373 1.81 9.42 25.88 4.512-1.426 21.277-1.344 27.704 4.458 4.273 18.025-22.758 16.417-19.617 8.348-4.672.752z" fill="none"/>
<circle r="50" fill="none"/>
</g>
<g transform="rotate(-2.732 16384.224 -15621.123)">
<path d="M177.115-20.114L190.21-21.6l12.527 1.632 26.29 11.494V8.474l-26.29 11.494L190.21 21.6l-13.095-1.486-5.785 29.082 12.667 3.638 10.95 6.302 19.89 20.68-6.487 15.658-28.686.558-12.2-3.285-11.528-6.385-16.474 24.655 10.31 8.208 7.704 10.013 10.462 26.716-11.984 11.984-26.716-10.462-10.013-7.703-8.208-10.31-24.655 16.473 6.385 11.53 3.285 12.198-.558 28.686-15.658 6.486-20.68-19.89-6.302-10.95-3.638-12.666-29.082 5.785L21.6 190.21l-1.632 12.527-11.494 26.29H-8.474l-11.494-26.29-1.633-12.527 1.486-13.095-29.082-5.785-3.638 12.667-6.302 10.95-20.68 19.89-15.658-6.487-.558-28.686 3.285-12.2 6.385-11.528-24.655-16.474-8.208 10.31-10.013 7.704-26.716 10.462-11.984-11.984 10.462-26.716 7.703-10.013 10.31-8.208-16.473-24.655-11.53 6.385-12.198 3.285-28.686-.558-6.486-15.658 19.89-20.68 10.95-6.302 12.666-3.638-5.785-29.082-13.095 1.487-12.527-1.632-26.29-11.494V-8.474l26.29-11.494 12.527-1.633 13.095 1.486 5.785-29.082-12.667-3.638-10.95-6.302-19.89-20.68 6.487-15.658 28.686-.558 12.2 3.285 11.528 6.385 16.474-24.655-10.31-8.208-7.704-10.013-10.462-26.716 11.984-11.984 26.716 10.462 10.013 7.703 8.208 10.31 24.655-16.473-6.385-11.53-3.285-12.198.558-28.686 15.658-6.486 20.68 19.89 6.302 10.95 3.638 12.666 29.082-5.785-1.487-13.095 1.632-12.527 11.494-26.29H8.474l11.494 26.29L21.6-190.21l-1.486 13.095 29.082 5.785 3.638-12.667 6.302-10.95 20.68-19.89 15.658 6.487.558 28.686-3.285 12.2-6.385 11.528 24.655 16.474 8.208-10.31 10.013-7.704 26.716-10.462 11.984 11.984-10.462 26.716-7.703 10.013-10.31 8.208 16.473 24.655 11.53-6.385 12.198-3.285 28.686.558 6.486 15.658-19.89 20.68-10.95 6.302-12.666 3.638z" fill="none"/>
<circle r="50" fill="none"/>
</g>
</g>
</svg>
{% extends "template.html" %}
{% load i18n %}
{% block title %}{% trans "Édition des préférences" %}{% endblock %}
{% block h1 %}<h1>{% trans "Préférences" %}</h1>{% endblock %}
{% block content %}
<form class="form-full-width" method="post">{% csrf_token %}
<div class="error-container">
{{ form.non_field_errors }}
</div>
<h2>{% trans "Internationalisation" %}</h2>
<div class="row">
<div class="six columns">
{{ form.langue.label_tag }}
{{ form.langue }}
{{ form.langue.errors }}
{{ form.langue.help_text }}
</div>
</div>
<footer>
<input type="submit" value="{% trans "Enregistrer les changements" %}">
</footer>
{% endblock content %}
from django.test import TestCase
# Create your tests here.
# -*- coding: utf-8 -*-
from django.conf.urls import url
import views
urlpatterns = [
url('^$', views.UserSettingsUpdateOrCreateView.as_view(), name='edit'),
]
# -*- coding: utf-8 -*-
from django.shortcuts import render
from django.views.generic.edit import UpdateView
from django.core.urlresolvers import reverse_lazy
from django.contrib.auth.decorators import login_required
from django.utils.decorators import method_decorator
from django.utils.translation import ugettext_lazy as _
from django.contrib import messages
from django.utils import translation
from models import UserSettings
class UserSettingsUpdateOrCreateView(UpdateView):
template_name = 'edit.html'
model = UserSettings
fields = ['langue']
success_url = reverse_lazy('index')
def get_object(self):
instance, created = UserSettings.objects.get_or_create(user=self.request.user)
return instance
def form_valid(self, form, *args, **kwargs):
messages.success(self.request, _(u'Vos préférences ont bien été sauvegardées'))
self.request.session[translation.LANGUAGE_SESSION_KEY] = form.cleaned_data['langue']
return super(UserSettingsUpdateOrCreateView, self).form_valid(form, *args, **kwargs)
@method_decorator(login_required)
def dispatch(self, *args, **kwargs):
return super(UserSettingsUpdateOrCreateView, self).dispatch(*args, **kwargs)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment