diff --git a/printer/forms.py b/printer/forms.py index a1dab8ed..1563f7d3 100644 --- a/printer/forms.py +++ b/printer/forms.py @@ -21,6 +21,7 @@ from users.models import User from .models import ( JobWithOptions, + Digicode, ) @@ -65,4 +66,16 @@ class PrintAgainForm(JobWithOptionsForm): 'disposition', 'format', 'count', - ] + ] + +class CreateCodeForm(FieldPermissionFormMixin, FormRevMixin, ModelForm): + def __init__(self, *args, **kwargs): + prefix = kwargs.pop('prefix', self.Meta.model.__name__) + # user = kwargs.get('user') + super(CreateCodeForm, self).__init__(*args, prefix=prefix, **kwargs) + + class Meta: + model = Digicode + fields = [ + "user", + ] diff --git a/printer/locale/fr/LC_MESSAGES/django.mo b/printer/locale/fr/LC_MESSAGES/django.mo index 0a74ce46..ef396364 100644 Binary files a/printer/locale/fr/LC_MESSAGES/django.mo and b/printer/locale/fr/LC_MESSAGES/django.mo differ diff --git a/printer/locale/fr/LC_MESSAGES/django.po b/printer/locale/fr/LC_MESSAGES/django.po index efabf7f7..0b912564 100644 --- a/printer/locale/fr/LC_MESSAGES/django.po +++ b/printer/locale/fr/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2018-11-17 13:29+0100\n" +"POT-Creation-Date: 2018-11-17 15:15+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -22,83 +22,92 @@ msgstr "" msgid "You don't have the right to view Printer application." msgstr "Vous n'avez pas le droit de voir l'application d'impression" -#: printer/forms.py:33 +#: printer/forms.py:34 msgid "Print As" msgstr "Imprimer en tant que" -#: printer/models.py:87 +#: printer/models.py:83 +#, fuzzy +msgid "This is not your digicode !" +msgstr "Ceci n'est pas votre tache" + +#: printer/models.py:89 +msgid "You can't generate a digicode" +msgstr "Vous ne pouvez pas créer un digicode" + +#: printer/models.py:103 msgid "This is not your print operation task" msgstr "Ceci n'est pas votre tache" -#: printer/models.py:124 +#: printer/models.py:140 msgid "Pending" msgstr "En attente" -#: printer/models.py:125 +#: printer/models.py:141 msgid "Printable" msgstr "Imprimable" -#: printer/models.py:126 +#: printer/models.py:142 msgid "Running" msgstr "En cours..." -#: printer/models.py:127 +#: printer/models.py:143 msgid "Cancelled" msgstr "Annulée" -#: printer/models.py:128 +#: printer/models.py:144 msgid "Finished" msgstr "Terminée" -#: printer/models.py:140 +#: printer/models.py:156 msgid "File" msgstr "Fichier" -#: printer/models.py:145 printer/templates/printer/aff_jobs.html:35 +#: printer/models.py:161 printer/templates/printer/aff_jobs.html:35 msgid "File Name" msgstr "Nom du fichier" -#: printer/models.py:152 printer/templates/printer/aff_jobs.html:38 +#: printer/models.py:168 printer/templates/printer/aff_jobs.html:38 msgid "Status" msgstr "Status" -#: printer/models.py:161 +#: printer/models.py:177 msgid "Print as" msgstr "Imprimer en tant que" -#: printer/models.py:166 printer/templates/printer/aff_jobs.html:40 +#: printer/models.py:182 printer/templates/printer/aff_jobs.html:40 msgid "Price" msgstr "Prix" -#: printer/models.py:174 +#: printer/models.py:190 msgid "Format" msgstr "Format" -#: printer/models.py:180 printer/settings.py:25 +#: printer/models.py:196 printer/settings.py:25 msgid "Color" msgstr "Couleur" -#: printer/models.py:186 +#: printer/models.py:202 msgid "Disposition" msgstr "Disposition" -#: printer/models.py:190 +#: printer/models.py:206 msgid "Count" msgstr "Nombre" -#: printer/models.py:196 +#: printer/models.py:212 msgid "Stapling" msgstr "Agrafage" -#: printer/models.py:202 +#: printer/models.py:218 msgid "Perforation" msgstr "Perforation" -#: printer/models.py:243 +#: printer/models.py:259 msgid "This is not your print job" msgstr "Ceci n'est pas votre tache" -#: printer/models.py:251 +#: printer/models.py:267 msgid "This is not your print operation job" msgstr "Ceci n'est pas votre tâche" @@ -170,6 +179,18 @@ msgstr "Quatre trous à gauche" msgid "Four right sided holes" msgstr "Quatre trous à droite" +#: printer/templates/printer/aff_digicodes.html:36 +msgid "User" +msgstr "L'utilisateur" + +#: printer/templates/printer/aff_digicodes.html:37 +msgid "Code" +msgstr "Digicode" + +#: printer/templates/printer/aff_digicodes.html:38 +msgid "Created on" +msgstr "Créé le" + #: printer/templates/printer/aff_jobs.html:36 msgid "By user" msgstr "Par" @@ -190,10 +211,21 @@ msgstr "Imprimer à nouveau" msgid "for" msgstr "pour" +#: printer/templates/printer/create_code.html:15 +msgid "Create digicode for" +msgstr "Créer un digicode pour" + +#: printer/templates/printer/index_digicodes.html:28 #: printer/templates/printer/index_jobs.html:28 msgid "Printer" msgstr "Imprimer" +#: printer/templates/printer/index_digicodes.html:31 +#, fuzzy +#| msgid "List of jobs" +msgid "List of codes" +msgstr "Liste des taches" + #: printer/templates/printer/index_jobs.html:31 #: printer/templates/printer/sidebar.html:34 msgid "List of jobs" @@ -236,6 +268,16 @@ msgstr "Désolé, l'imprimante est actuellement hors-service..." msgid "Print document" msgstr "Imprimer un document" +#: printer/templates/printer/sidebar.html:38 +#, fuzzy +#| msgid "List of jobs" +msgid "List of digicodes" +msgstr "Liste des taches" + +#: printer/templates/printer/sidebar.html:43 +msgid "Create Digicode" +msgstr "Créer un digicode" + #: printer/validators.py:48 #, python-format msgid "" @@ -253,14 +295,18 @@ msgstr "" "Le fichier a une taille de %(size)s. La taille maximum autorisée est " "%(max_size)s." -#: printer/views.py:89 +#: printer/views.py:104 msgid "Next" msgstr "Suivant" -#: printer/views.py:121 printer/views.py:147 +#: printer/views.py:136 printer/views.py:162 msgid "Print" msgstr "Imprimer" -#: printer/views.py:176 +#: printer/views.py:191 msgid "You are not allowed to print" msgstr "Vous n'êtes pas autorisé à imprimer" + +#: printer/views.py:263 +msgid "Create Code" +msgstr "Créer un digicode" diff --git a/printer/models.py b/printer/models.py index 7bd2e11a..bbc9254f 100644 --- a/printer/models.py +++ b/printer/models.py @@ -53,7 +53,7 @@ def user_printing_path(instance, filename): return 'printings/user_{0}/{1}'.format(instance.user.id, unidecode.unidecode(filename)) -class Digicode(RevMixin, models.Model): +class Digicode(RevMixin, models.Model, AclMixin, FieldPermissionModelMixin): """ This is a model to represent a digicode, maybe should be an external app. """ @@ -74,6 +74,22 @@ class Digicode(RevMixin, models.Model): digicode.save() return (str(code) + '#') + def can_view(self, user_request, *args, **kwargs): + if user_request.has_perm('printer.view_Digicode'): + return True, None + elif user_request == self.user: + return True, None + else: + return False, _("This is not your digicode !") + + def can_create(user_request, *args, **kwargs): + if user_request.has_perm('printer.create_Digicode'): + return True, None + else: + return False, _("You can't generate a digicode") + + + class PrintOperation(RevMixin, AclMixin, models.Model): """Abstract printing operation""" user = models.ForeignKey('users.User', on_delete=models.PROTECT) @@ -258,8 +274,7 @@ class JobWithOptions(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model def can_change_printas(self, user_request, *_args, **_kwargs): return user_request.adherent.club_members.all(), None - + def save(self, *args, **kwargs): self._update_price() super(JobWithOptions, self).save(*args, **kwargs) - diff --git a/printer/templates/printer/aff_digicodes.html b/printer/templates/printer/aff_digicodes.html new file mode 100644 index 00000000..a2202244 --- /dev/null +++ b/printer/templates/printer/aff_digicodes.html @@ -0,0 +1,57 @@ +{% 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 © 2018 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. +{% endcomment %} + +{% load acl %} +{% load logs_extra %} +{% load i18n %} + + +
+ {% if digicodes_list.paginator %} + {% include "pagination.html" with list=digicodes_list %} + {% endif %} + + + + + + + + + + {% for digicode in digicodes_list %} + {% can_view digicode %} + + + {% with code=digicode.code %} + + {% endwith %} + + + {% acl_end %} + {% endfor %} +
{% trans "User" %}{% trans "Code" %}{% trans "Created on" %}
{{ digicode.user }}{{ code }}#{{ digicode.created }}
+ + {% if digicodes_list.paginator %} + {% include "pagination.html" with list=digicodes_list %} + {% endif %} +
diff --git a/printer/templates/printer/create_code.html b/printer/templates/printer/create_code.html new file mode 100644 index 00000000..7981bcb7 --- /dev/null +++ b/printer/templates/printer/create_code.html @@ -0,0 +1,20 @@ +{% extends "printer/sidebar.html" %} +{% load staticfiles %} + +{% load i18n %} +{% load bootstrap3 %} +{% load massive_bootstrap_form %} + +{% block title %}Printing interface{% endblock %} + +{% block content %} +{% bootstrap_form_errors codeform %} + +
+ {% csrf_token %} +

{% trans "Create digicode for" %}

+ {% massive_bootstrap_form codeform 'user' %} + {% bootstrap_button action_name button_type="submit" icon="ok" button_class="btn-succes" %} +
+{% endblock %} + diff --git a/printer/templates/printer/index_digicodes.html b/printer/templates/printer/index_digicodes.html new file mode 100644 index 00000000..19af40a0 --- /dev/null +++ b/printer/templates/printer/index_digicodes.html @@ -0,0 +1,33 @@ +{% extends "printer/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 © 2018 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. +{% endcomment %} + +{% load bootstrap3 %} +{% load acl %} +{% load i18n %} + +{% block title %}{% trans "Printer" %}{% endblock %} + +{% block content %} +

{% trans "List of codes" %}

+ {% include "printer/aff_digicodes.html" with digicodes_list=digicodes_list %} +{% endblock %} diff --git a/printer/templates/printer/sidebar.html b/printer/templates/printer/sidebar.html index 16a62ac8..2ae58f87 100644 --- a/printer/templates/printer/sidebar.html +++ b/printer/templates/printer/sidebar.html @@ -33,4 +33,15 @@ with this program; if not, write to the Free Software Foundation, Inc., {% trans "List of jobs" %} + + + {% trans "List of digicodes" %} + + {% can_create digicode %} + + + {% trans "Create Digicode" %} + + {% acl_end %} + {% endblock %} diff --git a/printer/urls.py b/printer/urls.py index fcf726d1..ce10f6be 100644 --- a/printer/urls.py +++ b/printer/urls.py @@ -15,6 +15,9 @@ urlpatterns = [ url(r'^new_job/$', views.new_job, name="new-job"), url(r'^print_job/(?P[0-9]+)$', views.print_job, name='print-job'), url(r'^index_jobs/$', views.index_jobs, name="index-jobs"), + url(r'^index_digicodes/$', views.index_digicodes, name="index-digicodes"), url(r'^print_job_again/(?P[0-9]+)$', views.print_job_again, name='print-job-again'), + url(r'^create_digicode/', views.create_code, name='create-digicode'), + ] diff --git a/printer/views.py b/printer/views.py index 0b795da6..d2976da4 100644 --- a/printer/views.py +++ b/printer/views.py @@ -6,6 +6,8 @@ Author : Maxime Bombar . from __future__ import unicode_literals +import datetime + from django.urls import reverse from django.shortcuts import render, redirect from django.forms import modelformset_factory, formset_factory @@ -20,13 +22,26 @@ from . import settings from .utils import pdfinfo, send_mail_printer, printer_enabled +from re2o.acl import ( + can_create, + can_edit, + can_delete_set, + can_delete, + can_view, + can_view_all, + can_change +) + + from .models import ( JobWithOptions, - PrintOperation + PrintOperation, + Digicode ) from .forms import ( JobWithOptionsForm, - PrintAgainForm + PrintAgainForm, + CreateCodeForm, ) from preferences.models import GeneralOption @@ -148,7 +163,7 @@ def print_job_again(request, jobwithoptions, **_kwargs): }, 'printer/print.html', request - ) + ) def payment(request, jobs): @@ -203,10 +218,7 @@ def payment(request, jobs): success=1 if success: send_mail_printer(request.user) - return redirect(reverse( - 'users:profil', - kwargs={'userid': str(request.user.id)} - )) + return redirect(reverse('printer:index-digicodes',)) @login_required def index_jobs(request): @@ -217,3 +229,39 @@ def index_jobs(request): .order_by('starttime').reverse() jobs_list = re2o_paginator(request, jobs, pagination_number) return render(request, 'printer/index_jobs.html', {'jobs_list': jobs_list}) + + +@login_required +def index_digicodes(request): + """Display available digicodes""" + pagination_number = GeneralOption.get_cached_value('pagination_number') + digicodes = Digicode.objects.filter(created__gte=(datetime.datetime.now() + -datetime.timedelta(3))) + digicodes_list = re2o_paginator(request, digicodes, pagination_number) + return render(request, + 'printer/index_digicodes.html', + {'digicodes_list': digicodes_list}, + ) + +@can_create(Digicode) +@login_required +def create_code(request): + """Generate a digicode""" + code = CreateCodeForm( + request.POST or None, + # form_kwargs={'user': request.user}, + user = request.user, + ) + if code.is_valid(): + user = code.cleaned_data['user'] + Digicode._gen_code(user) + return redirect(reverse('printer:index-digicodes',)) + + return form( + { + 'codeform': code, + 'action_name': _("Create Code"), + }, + 'printer/create_code.html', + request + ) diff --git a/templates/base.html b/templates/base.html index 7677188a..c20f6d73 100644 --- a/templates/base.html +++ b/templates/base.html @@ -107,6 +107,7 @@ with this program; if not, write to the Free Software Foundation, Inc., {% endif %}