From 771961e3729864605f3a63e3ce702ff2bdb99927 Mon Sep 17 00:00:00 2001 From: grisel-davy Date: Fri, 4 Sep 2020 15:37:37 +0200 Subject: [PATCH] Fix multi_op app breaking preferences page --- multi_op/migrations/0001_initial.py | 27 +++++++++ multi_op/migrations/__init__.py | 0 multi_op/models.py | 45 +++++++++++++++ multi_op/preferences/__init__.py | 24 ++++++++ multi_op/preferences/forms.py | 4 +- multi_op/preferences/models.py | 2 +- multi_op/preferences/views.py | 58 ++++++++++++++++++++ multi_op/templates/multi_op/preferences.html | 30 ++++++++++ multi_op/urls.py | 2 +- multi_op/views.py | 2 +- 10 files changed, 189 insertions(+), 5 deletions(-) create mode 100644 multi_op/migrations/0001_initial.py create mode 100644 multi_op/migrations/__init__.py create mode 100644 multi_op/models.py create mode 100644 multi_op/preferences/__init__.py create mode 100644 multi_op/preferences/views.py create mode 100644 multi_op/templates/multi_op/preferences.html diff --git a/multi_op/migrations/0001_initial.py b/multi_op/migrations/0001_initial.py new file mode 100644 index 00000000..6777a2f1 --- /dev/null +++ b/multi_op/migrations/0001_initial.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.29 on 2020-09-04 12:50 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('topologie', '0074_auto_20200419_1640'), + ] + + operations = [ + migrations.CreateModel( + name='Preferences', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('enabled_dorm', models.ManyToManyField(blank=True, related_name='vlan_tagged', to='topologie.Dormitory', verbose_name='enabled dorm')), + ], + options={ + 'verbose_name': 'dormitories preferences', + }, + ), + ] diff --git a/multi_op/migrations/__init__.py b/multi_op/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/multi_op/models.py b/multi_op/models.py new file mode 100644 index 00000000..e6e7312b --- /dev/null +++ b/multi_op/models.py @@ -0,0 +1,45 @@ +# -*- mode: python; coding: utf-8 -*- +# 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 © 2019 Arthur Grisel-Davy +# Copyright © 2020 Gabriel Détraz +# +# 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. +""" +Multi_op model +""" + +from __future__ import absolute_import + +from django.db import models +from django.utils.translation import ugettext_lazy as _ +from django.template import loader +from django.db.models.signals import post_save +from django.dispatch import receiver +from django.utils.functional import cached_property + +from reversion.models import Version + +from re2o.mixins import AclMixin +from re2o.mail_utils import send_mail_object +from django.core.mail import EmailMessage + +from preferences.models import GeneralOption + +import users.models + +from .preferences.models import Preferences diff --git a/multi_op/preferences/__init__.py b/multi_op/preferences/__init__.py new file mode 100644 index 00000000..c73d6113 --- /dev/null +++ b/multi_op/preferences/__init__.py @@ -0,0 +1,24 @@ +# -*- mode: python; coding: utf-8 -*- +# 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 © 2020 Gabriel Détraz +# Copyright © 2019 Arthur Grisel-Davy +# +# 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. +"""multi_op +The app in charge of managing the operator of the dormitories +""" diff --git a/multi_op/preferences/forms.py b/multi_op/preferences/forms.py index d425f33d..a58410c7 100644 --- a/multi_op/preferences/forms.py +++ b/multi_op/preferences/forms.py @@ -30,12 +30,12 @@ from django import forms from django.forms import ModelForm, Form from django.utils.translation import ugettext_lazy as _ -from .models import MultiopOption +from .models import Preferences class EditPreferencesForm(ModelForm): """Form used to edit the settings of multi_op.""" class Meta: - model = MultiopOption + model = Preferences fields = "__all__" diff --git a/multi_op/preferences/models.py b/multi_op/preferences/models.py index 47544b47..8a185188 100644 --- a/multi_op/preferences/models.py +++ b/multi_op/preferences/models.py @@ -28,7 +28,7 @@ from django.db import models from django.utils.translation import ugettext_lazy as _ -class MultiopOption(models.Model): +class Preferences(models.Model): """Definition of the settings of multi_op.""" enabled_dorm = models.ManyToManyField( diff --git a/multi_op/preferences/views.py b/multi_op/preferences/views.py new file mode 100644 index 00000000..7283bef8 --- /dev/null +++ b/multi_op/preferences/views.py @@ -0,0 +1,58 @@ +# -*- mode: python; coding: utf-8 -*- +# 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 © 2020 Gabriel Détraz +# Copyright © 2019 Arthur Grisel-Davy +# +# 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. + +# App de gestion des users pour re2o +# Lara Kermarec, Gabriel Détraz, Lemesle Augustin +# Gplv2 + +from django.contrib import messages +from django.contrib.auth.decorators import login_required +from django.shortcuts import render, redirect +from django.template.loader import render_to_string +from django.utils.translation import ugettext as _ +from django.urls import reverse + +from re2o.base import re2o_paginator + +from re2o.acl import can_view, can_view_all, can_edit, can_create + +from preferences.views import edit_options_template_function + +from . import forms +from . import models + + + +def aff_preferences(request): + """View used to display the settings of multi_op in the preferences page.""" + pref, created = models.Preferences.objects.get_or_create() + context = { + "preferences": pref, + } + return render_to_string( + "multi_op/preferences.html", context=context, request=request, using=None + ) + + +@login_required +def edit_options(request, section): + return edit_options_template_function(request, section, forms, models) diff --git a/multi_op/templates/multi_op/preferences.html b/multi_op/templates/multi_op/preferences.html new file mode 100644 index 00000000..391b7330 --- /dev/null +++ b/multi_op/templates/multi_op/preferences.html @@ -0,0 +1,30 @@ +{% load design %} +{% load i18n %} + +
+ + +
+ {% comment %} + + + {% trans "Edit" %} + +

+ {% endcomment %} + +
+ + + + + +

{% trans "Enabled Dorm" %}

{{ preferences.enabled_dorm | tick}}

+
+
+
+
diff --git a/multi_op/urls.py b/multi_op/urls.py index 45b144e2..45b4b906 100644 --- a/multi_op/urls.py +++ b/multi_op/urls.py @@ -38,7 +38,7 @@ urlpatterns = [ name="aff-state-dormitory", ), url( - r"^edit_options/(?P
MultiopOption)$", + r"^edit_options/(?P
Preferences)$", edit_options, name="edit-options", ), diff --git a/multi_op/views.py b/multi_op/views.py index ad89bfae..729eae27 100644 --- a/multi_op/views.py +++ b/multi_op/views.py @@ -45,7 +45,7 @@ from preferences.models import GeneralOption, AssoOption from .forms import DormitoryForm -from .preferences.models import MultiopOption +from .preferences.models import Preferences from topologie.models import Room, Dormitory