From 051ec84f6ea0096c6bdd1f18d33e4f0cc4e04e1b Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Fri, 20 Sep 2019 00:09:49 +0200 Subject: [PATCH 1/8] Multi_opp app optional start --- multi_op/__init__.py | 0 multi_op/apps.py | 33 ++++ multi_op/forms.py | 54 ++++++ multi_op/preferences/forms.py | 39 ++++ multi_op/preferences/models.py | 40 ++++ .../templates/multi_op/aff_room_state.html | 69 +++++++ .../templates/multi_op/form_preferences.html | 48 +++++ multi_op/templates/multi_op/form_ticket.html | 58 ++++++ multi_op/templates/multi_op/index.html | 34 ++++ .../templates/multi_op/index_room_state.html | 53 ++++++ multi_op/templates/multi_op/navbar.html | 2 + .../templates/multi_op/navbar_logout.html | 6 + multi_op/templates/multi_op/preferences.html | 36 ++++ multi_op/templates/multi_op/sidebar.html | 43 +++++ multi_op/tests.py | 3 + multi_op/urls.py | 38 ++++ multi_op/views.py | 179 ++++++++++++++++++ users/views.py | 2 +- 18 files changed, 736 insertions(+), 1 deletion(-) create mode 100644 multi_op/__init__.py create mode 100644 multi_op/apps.py create mode 100644 multi_op/forms.py create mode 100644 multi_op/preferences/forms.py create mode 100644 multi_op/preferences/models.py create mode 100644 multi_op/templates/multi_op/aff_room_state.html create mode 100644 multi_op/templates/multi_op/form_preferences.html create mode 100644 multi_op/templates/multi_op/form_ticket.html create mode 100644 multi_op/templates/multi_op/index.html create mode 100644 multi_op/templates/multi_op/index_room_state.html create mode 100644 multi_op/templates/multi_op/navbar.html create mode 100644 multi_op/templates/multi_op/navbar_logout.html create mode 100644 multi_op/templates/multi_op/preferences.html create mode 100644 multi_op/templates/multi_op/sidebar.html create mode 100644 multi_op/tests.py create mode 100644 multi_op/urls.py create mode 100644 multi_op/views.py diff --git a/multi_op/__init__.py b/multi_op/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/multi_op/apps.py b/multi_op/apps.py new file mode 100644 index 00000000..ae633793 --- /dev/null +++ b/multi_op/apps.py @@ -0,0 +1,33 @@ +# -*- 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 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. +""" +The database models for the 'apps' app of re2o. + +For further details on each of those models, see the documentation details for +each. +""" + + +from django.apps import AppConfig + + +class MultiOpConfig(AppConfig): + name = 'multi_op' diff --git a/multi_op/forms.py b/multi_op/forms.py new file mode 100644 index 00000000..bedebb0a --- /dev/null +++ b/multi_op/forms.py @@ -0,0 +1,54 @@ +# -*- 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 © 2017 Gabriel Détraz +# Copyright © 2017 Goulven Kermarec +# Copyright © 2017 Augustin Lemesle +# Copyright © 2017 Maël Kervella +# +# 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. +""" +Select a dorm +""" + + +from django import forms +from django.forms import ModelForm, Form +from re2o.field_permissions import FieldPermissionFormMixin +from re2o.mixins import FormRevMixin +from django.utils.translation import ugettext_lazy as _ + +from topologie.models import( + Dormitory, +) + + +class DormitoryForm(FormRevMixin, Form): + """Select a dorm""" + dormitory = forms.ModelMultipleChoiceField( + queryset=Dormitory.objects.all(), + label=_("Dormitory"), + widget=forms.CheckboxSelectMultiple, + required=False + ) + + def __init__(self, *args, **kwargs): + super(DormitoryForm, self).__init__(*args, **kwargs) + + + + diff --git a/multi_op/preferences/forms.py b/multi_op/preferences/forms.py new file mode 100644 index 00000000..d5e6ce80 --- /dev/null +++ b/multi_op/preferences/forms.py @@ -0,0 +1,39 @@ +# -*- 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 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. +""" +The database models for the 'preference' app of re2o. + +For further details on each of those models, see the documentation details for +each. +""" + + +from django import forms +from django.forms import ModelForm, Form +from django.utils.translation import ugettext_lazy as _ + +from .models import Preferences + +class EditPreferencesForm(ModelForm): + """ Edit the ticket's settings""" + class Meta: + model = Preferences + fields = '__all__' diff --git a/multi_op/preferences/models.py b/multi_op/preferences/models.py new file mode 100644 index 00000000..89e82fb2 --- /dev/null +++ b/multi_op/preferences/models.py @@ -0,0 +1,40 @@ +# -*- 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 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. +""" +Fichier définissant les administration des models de preference +""" + + +from django.db import models +from django.utils.translation import ugettext_lazy as _ + +class Preferences(models.Model): + """ Definition of the app settings""" + + enabled_dorm = models.ManyToManyField( + 'topologie.Dormitory', + related_name='vlan_tagged', + blank=True, + verbose_name=_("Enabled dorm") + ) + + class Meta: + verbose_name = _("Dormitory of connection settings") diff --git a/multi_op/templates/multi_op/aff_room_state.html b/multi_op/templates/multi_op/aff_room_state.html new file mode 100644 index 00000000..57205953 --- /dev/null +++ b/multi_op/templates/multi_op/aff_room_state.html @@ -0,0 +1,69 @@ +{% 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 © 2017 Gabriel Détraz +Copyright © 2017 Goulven Kermarec +Copyright © 2017 Augustin Lemesle + +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 acl %} +{% load logs_extra %} +{% load i18n %} + +{% if room_list.paginator %} + {% include 'pagination.html' with list=room_list %} +{% endif %} + + + + + {% trans "Room" as tr_room %} + {% trans "Building" as tr_building %} + + + + + + + + + + {% for room in room_list %} + + + + + + + + + + {% endfor %} +
{% include 'buttons/sort.html' with prefix='building' col='name' text=tr_building %}{% include 'buttons/sort.html' with prefix='room' col='name' text=tr_room %}{% trans "Connnected on" %}{% trans "User" %}{% trans "Details" %}{% trans "End of subscription on" %}{% trans "Internet access" %}
{{ room.building }}{{ room.name }}{% if room.port_set.all %}AURORE{% else %}{% trans "Other operator" %}{% endif %}{% if room.adherent %}{{ room.adherent }}{% else %} {% trans "Aucun" %}{% endif %}{{ room.details }}{% if room.user.is_adherent %}{{ room.user.end_adhesion }}{% else %}{% trans "Not a member" %}{% endif %} + {% if room.user.has_access == True %} + {% trans "Active" %} + {% else %} + {% trans "Disabled" %} + {% endif %} +
+ +{% if room_list.paginator %} + {% include 'pagination.html' with list=room_list %} +{% endif %} + diff --git a/multi_op/templates/multi_op/form_preferences.html b/multi_op/templates/multi_op/form_preferences.html new file mode 100644 index 00000000..5c7e5d5e --- /dev/null +++ b/multi_op/templates/multi_op/form_preferences.html @@ -0,0 +1,48 @@ +{% extends 'machines/sidebar.html' %} +{% 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 © 2017 Gabriel Détraz +Copyright © 2017 Goulven Kermarec +Copyright © 2017 Augustin Lemesle +Copyright © 2017 Maël Kervella + +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 bootstrap3 %} +{% load i18n %} + +{% block title %}{% trans "Ticket" %}{% endblock %} + +{% block content %} +

{% trans "Tickets settings modification" %}

+ +{% for message in messages %} +
+ + {{ message | safe }} +
+{% endfor %} + +
+ {% csrf_token %} + {% bootstrap_field preferencesform.publish_address %} + {% bootstrap_field preferencesform.mail_language %} + {% bootstrap_button "Editer" button_type="submit" icon='ok' button_class='btn-success' %} +
+{% endblock %} diff --git a/multi_op/templates/multi_op/form_ticket.html b/multi_op/templates/multi_op/form_ticket.html new file mode 100644 index 00000000..d35e9f5d --- /dev/null +++ b/multi_op/templates/multi_op/form_ticket.html @@ -0,0 +1,58 @@ +{% extends 'machines/sidebar.html' %} +{% 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 © 2017 Gabriel Détraz +Copyright © 2017 Goulven Kermarec +Copyright © 2017 Augustin Lemesle +Copyright © 2017 Maël Kervella + +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 bootstrap3 %} +{% load massive_bootstrap_form %} +{% load i18n %} + +{% block title %}{% trans "Ticket" %}{% endblock %} + +{% block content %} +

Ouverture d'un Ticket

+ +
+ {% csrf_token %} + {% if not user.is_authenticated %} +

{% trans "Vous n'êtes pas authentifié. Veuillez fournir une adresse mail afin que nous puissions vous recontacter." %}

+ {% bootstrap_field ticketform.email %} + {% endif %} + {% bootstrap_field ticketform.title %} +
+

{% trans "Description de votre problème. Veuillez fournir le plus d'informations possible afin de faciliter la recherche de solution. Voici quelques informations dont nous pourions avoir besoin:" %}

+ + {% bootstrap_field ticketform.description %} + {% bootstrap_button "Ouvrir le Ticket" button_type="submit" icon='ok' button_class='btn-success' %} +
+{% endblock %} diff --git a/multi_op/templates/multi_op/index.html b/multi_op/templates/multi_op/index.html new file mode 100644 index 00000000..4429c4fd --- /dev/null +++ b/multi_op/templates/multi_op/index.html @@ -0,0 +1,34 @@ +{% extends 'users/sidebar.html' %} +{% 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 © 2017 Gabriel Détraz +Copyright © 2017 Goulven Kermarec +Copyright © 2017 Augustin Lemesle + +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 bootstrap3 %} +{% load i18n %} + +{% block title%}{% trans "Tickets" %}{% endblock %} + +{% block content %} +

{% trans "Tickets" %}

+ {% include 'tickets/aff_tickets.html' with tickets_list=tickets_list %} +{% endblock %} diff --git a/multi_op/templates/multi_op/index_room_state.html b/multi_op/templates/multi_op/index_room_state.html new file mode 100644 index 00000000..50881a19 --- /dev/null +++ b/multi_op/templates/multi_op/index_room_state.html @@ -0,0 +1,53 @@ +{% extends 'multi_op/sidebar.html' %} +{% 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 © 2017 Gabriel Détraz +Copyright © 2017 Goulven Kermarec +Copyright © 2017 Augustin Lemesle + +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 bootstrap3 %} +{% load acl %} +{% load i18n %} + +{% block title %}{% trans "Multi Operators" %}{% endblock %} + +{% block content %} + +{% if dormitory_form %} +{% bootstrap_form_errors dormitory_form %} +{% endif %} + +

{% trans "Rooms connections" %}

+ +{% if dormitory_form %} +
+ {% csrf_token %} + {% bootstrap_form dormitory_form %} + {% bootstrap_button "Select Dormitory" icon='ok' button_class='btn-success' %} +
+{% endif %} + +{% include 'multi_op/aff_room_state.html' with room_list=room_list %} +
+
+
+{% endblock %} + diff --git a/multi_op/templates/multi_op/navbar.html b/multi_op/templates/multi_op/navbar.html new file mode 100644 index 00000000..d5b6cb51 --- /dev/null +++ b/multi_op/templates/multi_op/navbar.html @@ -0,0 +1,2 @@ +{% load i18n %} +
  • {% trans "Tickets" %}
  • diff --git a/multi_op/templates/multi_op/navbar_logout.html b/multi_op/templates/multi_op/navbar_logout.html new file mode 100644 index 00000000..8a7114f3 --- /dev/null +++ b/multi_op/templates/multi_op/navbar_logout.html @@ -0,0 +1,6 @@ +{% load i18n %} +
  • + + {% trans "Ouvrir un ticket" %} + +
  • diff --git a/multi_op/templates/multi_op/preferences.html b/multi_op/templates/multi_op/preferences.html new file mode 100644 index 00000000..60cbfac6 --- /dev/null +++ b/multi_op/templates/multi_op/preferences.html @@ -0,0 +1,36 @@ +{% load i18n %} + +
    + + +
    + + + + {% trans "Edit" %} + +

    + +
    + + + + {% if preferences.publish_address %} + + {% else %} + + {% endif %} + + + + +

    {% trans "Publication email address"%}

    {{ preferences.publish_address }}

    {% trans "Pas d'adresse, les tickets ne sont pas annoncés" %}

    {% trans "Email language" %}

    {{ language }}

    +
    +
    +
    +
    +
    diff --git a/multi_op/templates/multi_op/sidebar.html b/multi_op/templates/multi_op/sidebar.html new file mode 100644 index 00000000..0433fc61 --- /dev/null +++ b/multi_op/templates/multi_op/sidebar.html @@ -0,0 +1,43 @@ +{% extends 'base.html' %} +{% 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 © 2017 Gabriel Détraz +Copyright © 2017 Goulven Kermarec +Copyright © 2017 Augustin Lemesle + +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 %} + +{% block sidebar %} + + + {% trans "Rooms connection state" %} + + + + {% trans "Sockets to connect" %} + + + + {% trans "Sockets to disconnect" %} + + +{% endblock %} + diff --git a/multi_op/tests.py b/multi_op/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/multi_op/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/multi_op/urls.py b/multi_op/urls.py new file mode 100644 index 00000000..0dbb0ca8 --- /dev/null +++ b/multi_op/urls.py @@ -0,0 +1,38 @@ +# -*- 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 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. +""" +The database models for the 'urls' app of re2o. + +For further details on each of those models, see the documentation details for +each. +""" + +from django.conf.urls import url + +from . import views + +urlpatterns = [ + url(r'^$', views.aff_state_global, name='aff-state-global'), + url(r'^(?P[0-9]+)$', views.aff_state_dormitory, name='aff-state-dormitory'), + url(r'^pending-connection$', views.aff_pending_connection, name='aff-pending-connection'), + url(r'^pending-disconnection$', views.aff_pending_disconnection, name='aff-pending-disconnection'), + # url(r'^multi_op/edit-preferences-multiop$', views.edit_preferences, name='edit-preferences-multiop'), +] diff --git a/multi_op/views.py b/multi_op/views.py new file mode 100644 index 00000000..41c7e40d --- /dev/null +++ b/multi_op/views.py @@ -0,0 +1,179 @@ +# -*- 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 © 2017 Gabriel Détraz +# Copyright © 2017 Goulven Kermarec +# Copyright © 2017 Augustin Lemesle +# +# 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 +# Goulven 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.views.decorators.cache import cache_page +from django.utils.translation import ugettext as _ +from django.urls import reverse +from django.forms import modelformset_factory +from django.db.models import Q +from re2o.views import form +from re2o.utils import all_has_access, all_adherent + +from re2o.base import ( + re2o_paginator, + SortTable, +) + +from re2o.acl import( + can_view, + can_view_all, + can_edit, + can_create, +) + +from preferences.models import GeneralOption + +from .forms import DormitoryForm + +from .preferences.models import( + Preferences, +) + +from topologie.models import Room, Dormitory + +from .preferences.forms import ( + EditPreferencesForm, +) + + +def display_rooms_connection(request, dormitory=None): + """View to display global state of connection state""" + room_list = Room.objects.select_related('building__dormitory').order_by('building_dormitory', 'port') + if dormitory: + room_list = room_list.filter(building__dormitory=dormitory) + room_list = SortTable.sort( + room_list, + request.GET.get('col'), + request.GET.get('order'), + SortTable.TOPOLOGIE_INDEX_ROOM + ) + pagination_number = GeneralOption.get_cached_value('pagination_number') + room_list = re2o_paginator(request, room_list, pagination_number) + return render( + request, + 'multi_op/index_room_state.html', + {'room_list': room_list} + ) + + +@login_required +@can_view_all(Room) +def aff_state_global(request): + return display_rooms_connection(request) + + +@login_required +@can_view(Dormitory) +def aff_state_dormitory(request, dormitory, dormitoryid): + return display_rooms_connection(dormitory=dormitory) + + +@login_required +@can_view_all(Room) +def aff_pending_connection(request): + """Aff pending Rooms to connect on our network""" + room_list = Room.objects.select_related('building__dormitory').filter(port__isnull=True).filter(adherent__in=all_has_access()).order_by('building_dormitory', 'port') + dormitory_form = DormitoryForm(request.POST or None) + if dormitory_form.is_valid(): + room_list = room_list.filter(building__dormitory__in=dormitory_form.cleaned_data['dormitory']) + room_list = SortTable.sort( + room_list, + request.GET.get('col'), + request.GET.get('order'), + SortTable.TOPOLOGIE_INDEX_ROOM + ) + pagination_number = GeneralOption.get_cached_value('pagination_number') + room_list = re2o_paginator(request, room_list, pagination_number) + return render( + request, + 'multi_op/index_room_state.html', + {'room_list': room_list, 'dormitory_form': dormitory_form} + ) + + +@login_required +@can_view_all(Room) +def aff_pending_disconnection(request): + """Aff pending Rooms to disconnect from our network""" + room_list = Room.objects.select_related('building__dormitory').filter(port__isnull=False).exclude(Q(adherent__in=all_has_access()) | Q(adherent__in=all_adherent())).order_by('building_dormitory', 'port') + dormitory_form = DormitoryForm(request.POST or None) + if dormitory_form.is_valid(): + room_list = room_list.filter(building__dormitory__in=dormitory_form.cleaned_data['dormitory']) + room_list = SortTable.sort( + room_list, + request.GET.get('col'), + request.GET.get('order'), + SortTable.TOPOLOGIE_INDEX_ROOM + ) + pagination_number = GeneralOption.get_cached_value('pagination_number') + room_list = re2o_paginator(request, room_list, pagination_number) + return render( + request, + 'multi_op/index_room_state.html', + {'room_list': room_list, 'dormitory_form': dormitory_form} + ) + + +def edit_preferences(request): + """ View to edit the settings of the tickets """ + + preferences_instance, created = Preferences.objects.get_or_create(id=1) + preferencesform = EditPreferencesForm( + request.POST or None, + instance = preferences_instance,) + + if preferencesform.is_valid(): + if preferencesform.changed_data: + preferencesform.save() + messages.success(request,'Preferences updated') + return redirect(reverse('preferences:display-options',)) + else: + messages.error(request,'Formulaire Invalide') + return form({'preferencesform':preferencesform,},'multi_op/form_preferences.html',request) + return form({'preferencesform':preferencesform,},'multi_op/form_preferences.html',request) + + +def navbar_user(request): + """View to display the app in user's dropdown in the navbar""" + return render_to_string('multi_op/navbar.html') + +def navbar_logout(request): + """View to display the app in user's dropdown in the navbar""" + return None + + +def preferences(request): + """ View to display the settings of the tickets in the preferences page""" + pref, created = Preferences.objects.get_or_create(id=1) + context = {'preferences':pref,'language':str(pref.LANGUES[pref.mail_language][1])} + return render_to_string('tickets/preferences.html', context=context, request=request, using=None) + + diff --git a/users/views.py b/users/views.py index 37c0ec88..9764fbe0 100644 --- a/users/views.py +++ b/users/views.py @@ -977,7 +977,7 @@ def profil(request, users, **_kwargs): ) optionnal_apps = [import_module(app) for app in OPTIONNAL_APPS_RE2O] - optionnal_templates_list = [app.views.profil(request,users) for app in optionnal_apps] + optionnal_templates_list = [app.views.profil(request,users) for app in optionnal_apps if hasattr(app.views, 'profil')] pagination_large_number = GeneralOption.get_cached_value( 'pagination_large_number' From 8a41a1af60e35bf9c9c534fc66bb6785b75f8c0d Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Fri, 20 Sep 2019 00:37:59 +0200 Subject: [PATCH 2/8] Fix bug affichage --- multi_op/templates/multi_op/aff_room_state.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/multi_op/templates/multi_op/aff_room_state.html b/multi_op/templates/multi_op/aff_room_state.html index 57205953..de25171b 100644 --- a/multi_op/templates/multi_op/aff_room_state.html +++ b/multi_op/templates/multi_op/aff_room_state.html @@ -51,9 +51,9 @@ with this program; if not, write to the Free Software Foundation, Inc., {% if room.port_set.all %}AURORE{% else %}{% trans "Other operator" %}{% endif %} {% if room.adherent %}{{ room.adherent }}{% else %} {% trans "Aucun" %}{% endif %} {{ room.details }} - {% if room.user.is_adherent %}{{ room.user.end_adhesion }}{% else %}{% trans "Not a member" %}{% endif %} + {% if room.adherent.is_adherent %}{{ room.adherent.end_adhesion }}{% else %}{% trans "Not a member" %}{% endif %} - {% if room.user.has_access == True %} + {% if room.adherent.has_access == True %} {% trans "Active" %} {% else %} {% trans "Disabled" %} From 6d76d0a5f7a8f8ab47fb0dc4f85c17c1720646d6 Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Fri, 20 Sep 2019 13:56:26 +0200 Subject: [PATCH 3/8] Contact view on optional app... is optionnal --- re2o/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/re2o/views.py b/re2o/views.py index 414416a7..d443a84c 100644 --- a/re2o/views.py +++ b/re2o/views.py @@ -116,7 +116,7 @@ def contact_page(request): address = MailContact.objects.all() optionnal_apps = [import_module(app) for app in OPTIONNAL_APPS_RE2O] - optionnal_templates_contact_list = [app.views.contact(request) for app in optionnal_apps] + optionnal_templates_contact_list = [app.views.contact(request) for app in optionnal_apps if hasattr(app.views, 'contact')] return render( request, From 6617d6a000c3d3713d50a53bfcbb031bbfd0a8cb Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Fri, 20 Sep 2019 19:56:19 +0200 Subject: [PATCH 4/8] =?UTF-8?q?Fix=20affichage=20dans=20le=20dropdown=20ad?= =?UTF-8?q?apt=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- multi_op/templates/multi_op/navbar.html | 2 +- multi_op/views.py | 8 ++------ re2o/context_processors.py | 4 ++-- templates/base.html | 13 ++++++++++--- tickets/templates/tickets/navbar.html | 2 +- tickets/views.py | 8 ++++---- 6 files changed, 20 insertions(+), 17 deletions(-) diff --git a/multi_op/templates/multi_op/navbar.html b/multi_op/templates/multi_op/navbar.html index d5b6cb51..c5e84c43 100644 --- a/multi_op/templates/multi_op/navbar.html +++ b/multi_op/templates/multi_op/navbar.html @@ -1,2 +1,2 @@ {% load i18n %} -
  • {% trans "Tickets" %}
  • +
  • {% trans "Multi Operators" %}
  • diff --git a/multi_op/views.py b/multi_op/views.py index 41c7e40d..75811a0d 100644 --- a/multi_op/views.py +++ b/multi_op/views.py @@ -161,13 +161,9 @@ def edit_preferences(request): return form({'preferencesform':preferencesform,},'multi_op/form_preferences.html',request) -def navbar_user(request): +def navbar_user(): """View to display the app in user's dropdown in the navbar""" - return render_to_string('multi_op/navbar.html') - -def navbar_logout(request): - """View to display the app in user's dropdown in the navbar""" - return None + return ('topologie', render_to_string('multi_op/navbar.html')) def preferences(request): diff --git a/re2o/context_processors.py b/re2o/context_processors.py index 3ee39073..97f2d4f8 100644 --- a/re2o/context_processors.py +++ b/re2o/context_processors.py @@ -62,8 +62,8 @@ def context_optionnal_apps(request): """Fonction de context pour générer la navbar en fonction des apps optionnels""" optionnal_apps = [import_module(app) for app in OPTIONNAL_APPS_RE2O] - optionnal_templates_navbar_user_list = [app.views.navbar_user(request) for app in optionnal_apps] - optionnal_templates_navbar_logout_list = [app.views.navbar_logout(request) for app in optionnal_apps] + optionnal_templates_navbar_user_list = [app.views.navbar_user() for app in optionnal_apps if hasattr(app.views, 'navbar_user')] + optionnal_templates_navbar_logout_list = [app.views.navbar_logout() for app in optionnal_apps if hasattr(app.views, 'navbar_logout')] return {'optionnal_templates_navbar_user_list':optionnal_templates_navbar_user_list, 'optionnal_templates_navbar_logout_list':optionnal_templates_navbar_logout_list} diff --git a/templates/base.html b/templates/base.html index f116c2be..122c7c3a 100644 --- a/templates/base.html +++ b/templates/base.html @@ -101,9 +101,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
  • {% trans "Manage the subscriptions" %}
  • {% acl_end %} - {% for template in optionnal_templates_navbar_user_list%} - {{ template }} - {% endfor %} + {% for app, template in optionnal_templates_navbar_user_list %} + {% if app != 'topologie' %} + {{ template }} + {% endif %} + {% endfor %} {% acl_end %} @@ -114,6 +116,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
  • {% trans "Switches" %}
  • {% trans "Access points" %}
  • {% trans "Rooms" %}
  • + {% for app, template in optionnal_templates_navbar_user_list %} + {% if app == 'topologie' %} + {{ template }} + {% endif %} + {% endfor %} {% acl_end %} diff --git a/tickets/templates/tickets/navbar.html b/tickets/templates/tickets/navbar.html index 3c4318f7..11473229 100644 --- a/tickets/templates/tickets/navbar.html +++ b/tickets/templates/tickets/navbar.html @@ -1,2 +1,2 @@ {% load i18n %} -
  • {% trans "Tickets" %}
  • +
  • {% trans "Tickets" %}
  • diff --git a/tickets/views.py b/tickets/views.py index 7fb96511..b16e4eea 100644 --- a/tickets/views.py +++ b/tickets/views.py @@ -186,12 +186,12 @@ def preferences(request): def contact(request): """View to display a contact address on the contact page used here to display a link to open a ticket""" - return render_to_string('tickets/contact.html') + return ('users', render_to_string('tickets/contact.html')) -def navbar_user(request): +def navbar_user(): """View to display the ticket link in thet user's dropdown in the navbar""" - return render_to_string('tickets/navbar.html') + return ('users', render_to_string('tickets/navbar.html')) -def navbar_logout(request): +def navbar_logout(): """View to display the ticket link to log out users""" return render_to_string('tickets/navbar_logout.html') From 745a30280c21307c96b17d8d805e1edddac75699 Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Fri, 20 Sep 2019 21:45:48 +0200 Subject: [PATCH 5/8] Display connection state for luser --- users/templates/users/profil.html | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/users/templates/users/profil.html b/users/templates/users/profil.html index 00489017..bf3fd9e5 100644 --- a/users/templates/users/profil.html +++ b/users/templates/users/profil.html @@ -187,9 +187,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
    {% trans "Room" %}
    - {{ users.room }} {% can_view_all Port %}{% if users.room.port_set.all %} / - {{ users.room.port_set.all|join:", " }} {% endif %}{% acl_end %} -
    + {{ users.room }} {% if users.room.port_set.all %}{% can_view_all Port %}/ + {{ users.room.port_set.all|join:", " }} {% acl_else %} + {% trans "Connected" %}{% acl_end %} + {% else %}{% if users.room %}{% trans "Pending connection..." %}{% endif %} + {% endif %} +
    @@ -222,7 +225,7 @@ with this program; if not, write to the Free Software Foundation, Inc., {% if users.end_adhesion != None %}
    {{ users.end_adhesion }}
    {% else %} -
    {% trans "Not a member" %}
    +
    {% trans "not a member" %}
    {% endif %}
    From 2df79830b64285e15ce31eef17353748ac36c4bc Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Fri, 20 Sep 2019 23:03:44 +0200 Subject: [PATCH 6/8] An optional app can possibly not have a pannel pref --- preferences/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/preferences/views.py b/preferences/views.py index 9a5da84d..d27cdb4f 100644 --- a/preferences/views.py +++ b/preferences/views.py @@ -105,7 +105,7 @@ def display_options(request): document_template_list = DocumentTemplate.objects.order_by('name') optionnal_apps = [import_module(app) for app in OPTIONNAL_APPS_RE2O] - optionnal_templates_list = [app.views.preferences(request) for app in optionnal_apps] + optionnal_templates_list = [app.views.preferences(request) for app in optionnal_apps if hasattr(app.views, 'preferences')] return form({ 'useroptions': useroptions, From dfe15ec23d3028870e6f2665795ec20f17b9c6f7 Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Sat, 21 Sep 2019 16:25:05 +0200 Subject: [PATCH 7/8] Button to remove port of a room --- multi_op/templates/multi_op/aff_room_state.html | 8 +++++++- multi_op/urls.py | 2 +- multi_op/views.py | 12 ++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/multi_op/templates/multi_op/aff_room_state.html b/multi_op/templates/multi_op/aff_room_state.html index de25171b..75ca027c 100644 --- a/multi_op/templates/multi_op/aff_room_state.html +++ b/multi_op/templates/multi_op/aff_room_state.html @@ -42,6 +42,7 @@ with this program; if not, write to the Free Software Foundation, Inc., {% trans "Details" %} {% trans "End of subscription on" %} {% trans "Internet access" %} + {% trans "Action" %} {% for room in room_list %} @@ -51,7 +52,7 @@ with this program; if not, write to the Free Software Foundation, Inc., {% if room.port_set.all %}AURORE{% else %}{% trans "Other operator" %}{% endif %} {% if room.adherent %}{{ room.adherent }}{% else %} {% trans "Aucun" %}{% endif %} {{ room.details }} - {% if room.adherent.is_adherent %}{{ room.adherent.end_adhesion }}{% else %}{% trans "Not a member" %}{% endif %} + {% if room.adherent.is_adherent %}{% else %}{% endif %}{% if room.adherent.end_adhesion %}{{ room.adherent.end_adhesion}}{% else %}{% trans "No member" %}{% endif %} {% if room.adherent.has_access == True %} {% trans "Active" %} @@ -59,6 +60,11 @@ with this program; if not, write to the Free Software Foundation, Inc., {% trans "Disabled" %} {% endif %} + + {% if room.port_set.all %} + + {% endif %} + {% endfor %} diff --git a/multi_op/urls.py b/multi_op/urls.py index 0dbb0ca8..866de712 100644 --- a/multi_op/urls.py +++ b/multi_op/urls.py @@ -34,5 +34,5 @@ urlpatterns = [ url(r'^(?P[0-9]+)$', views.aff_state_dormitory, name='aff-state-dormitory'), url(r'^pending-connection$', views.aff_pending_connection, name='aff-pending-connection'), url(r'^pending-disconnection$', views.aff_pending_disconnection, name='aff-pending-disconnection'), - # url(r'^multi_op/edit-preferences-multiop$', views.edit_preferences, name='edit-preferences-multiop'), + url(r'^disconnect-room/(?P[0-9]+)$', views.disconnect_room, name='disconnect-room'), ] diff --git a/multi_op/views.py b/multi_op/views.py index 75811a0d..7b94a158 100644 --- a/multi_op/views.py +++ b/multi_op/views.py @@ -142,6 +142,18 @@ def aff_pending_disconnection(request): ) +@login_required +@can_edit(Room) +def disconnect_room(request, room, roomid): + """Action of disconnecting a room""" + room.port_set.clear() + room.save() + messages.success(request,'Room %s disconnected' % room) + return redirect(reverse( + 'multi_op:aff-pending-disconnection' + )) + + def edit_preferences(request): """ View to edit the settings of the tickets """ From bed24b5c1c955d3d918ba682389870535f59a088 Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Sat, 21 Sep 2019 16:26:55 +0200 Subject: [PATCH 8/8] Unusefull stuff --- multi_op/views.py | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/multi_op/views.py b/multi_op/views.py index 7b94a158..7debd02e 100644 --- a/multi_op/views.py +++ b/multi_op/views.py @@ -154,34 +154,10 @@ def disconnect_room(request, room, roomid): )) -def edit_preferences(request): - """ View to edit the settings of the tickets """ - - preferences_instance, created = Preferences.objects.get_or_create(id=1) - preferencesform = EditPreferencesForm( - request.POST or None, - instance = preferences_instance,) - - if preferencesform.is_valid(): - if preferencesform.changed_data: - preferencesform.save() - messages.success(request,'Preferences updated') - return redirect(reverse('preferences:display-options',)) - else: - messages.error(request,'Formulaire Invalide') - return form({'preferencesform':preferencesform,},'multi_op/form_preferences.html',request) - return form({'preferencesform':preferencesform,},'multi_op/form_preferences.html',request) - - def navbar_user(): """View to display the app in user's dropdown in the navbar""" return ('topologie', render_to_string('multi_op/navbar.html')) -def preferences(request): - """ View to display the settings of the tickets in the preferences page""" - pref, created = Preferences.objects.get_or_create(id=1) - context = {'preferences':pref,'language':str(pref.LANGUES[pref.mail_language][1])} - return render_to_string('tickets/preferences.html', context=context, request=request, using=None)