mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-21 21:53:30 +00:00
move SAS forms to their own file
This commit is contained in:
parent
cdf9519a9f
commit
83ae21140d
@ -997,7 +997,7 @@ msgstr "Vous ne pouvez pas ajouter deux fois le même utilisateur"
|
|||||||
msgid "You should specify a role"
|
msgid "You should specify a role"
|
||||||
msgstr "Vous devez choisir un rôle"
|
msgstr "Vous devez choisir un rôle"
|
||||||
|
|
||||||
#: club/forms.py:283 sas/views.py:117 sas/views.py:241
|
#: club/forms.py:283 sas/views.py:52 sas/views.py:176
|
||||||
msgid "You do not have the permission to do that"
|
msgid "You do not have the permission to do that"
|
||||||
msgstr "Vous n'avez pas la permission de faire cela"
|
msgstr "Vous n'avez pas la permission de faire cela"
|
||||||
|
|
||||||
@ -2246,7 +2246,7 @@ msgstr "avoir une notification pour chaque click"
|
|||||||
msgid "get a notification for every refilling"
|
msgid "get a notification for every refilling"
|
||||||
msgstr "avoir une notification pour chaque rechargement"
|
msgstr "avoir une notification pour chaque rechargement"
|
||||||
|
|
||||||
#: core/models.py:914 sas/views.py:309
|
#: core/models.py:914 sas/forms.py:86
|
||||||
msgid "file name"
|
msgid "file name"
|
||||||
msgstr "nom du fichier"
|
msgstr "nom du fichier"
|
||||||
|
|
||||||
@ -3496,12 +3496,12 @@ msgid "Error creating folder %(folder_name)s: %(msg)s"
|
|||||||
msgstr "Erreur de création du dossier %(folder_name)s : %(msg)s"
|
msgstr "Erreur de création du dossier %(folder_name)s : %(msg)s"
|
||||||
|
|
||||||
#: core/views/files.py:153 core/views/forms.py:277 core/views/forms.py:284
|
#: core/views/files.py:153 core/views/forms.py:277 core/views/forms.py:284
|
||||||
#: sas/views.py:81
|
#: sas/forms.py:57
|
||||||
#, python-format
|
#, python-format
|
||||||
msgid "Error uploading file %(file_name)s: %(msg)s"
|
msgid "Error uploading file %(file_name)s: %(msg)s"
|
||||||
msgstr "Erreur d'envoi du fichier %(file_name)s : %(msg)s"
|
msgstr "Erreur d'envoi du fichier %(file_name)s : %(msg)s"
|
||||||
|
|
||||||
#: core/views/files.py:228 sas/views.py:313
|
#: core/views/files.py:228 sas/forms.py:90
|
||||||
msgid "Apply rights recursively"
|
msgid "Apply rights recursively"
|
||||||
msgstr "Appliquer les droits récursivement"
|
msgstr "Appliquer les droits récursivement"
|
||||||
|
|
||||||
@ -5267,11 +5267,29 @@ msgstr "Utilisateur qui sera supprimé"
|
|||||||
msgid "User to be selected"
|
msgid "User to be selected"
|
||||||
msgstr "Utilisateur à sélectionner"
|
msgstr "Utilisateur à sélectionner"
|
||||||
|
|
||||||
|
#: sas/forms.py:13
|
||||||
|
msgid "Add a new album"
|
||||||
|
msgstr "Ajouter un nouvel album"
|
||||||
|
|
||||||
|
#: sas/forms.py:16
|
||||||
|
msgid "Upload images"
|
||||||
|
msgstr "Envoyer les images"
|
||||||
|
|
||||||
|
#: sas/forms.py:34
|
||||||
|
#, python-format
|
||||||
|
msgid "Error creating album %(album)s: %(msg)s"
|
||||||
|
msgstr "Erreur de création de l'album %(album)s : %(msg)s"
|
||||||
|
|
||||||
|
#: sas/forms.py:69 trombi/templates/trombi/detail.jinja:15
|
||||||
|
msgid "Add user"
|
||||||
|
msgstr "Ajouter une personne"
|
||||||
|
|
||||||
#: sas/models.py:282
|
#: sas/models.py:282
|
||||||
msgid "picture"
|
msgid "picture"
|
||||||
msgstr "photo"
|
msgstr "photo"
|
||||||
|
|
||||||
#: sas/templates/sas/album.jinja:9 sas/templates/sas/main.jinja:8
|
#: sas/templates/sas/album.jinja:9
|
||||||
|
#: sas/templates/sas/ask_picture_removal.jinja:4 sas/templates/sas/main.jinja:8
|
||||||
#: sas/templates/sas/main.jinja:17 sas/templates/sas/picture.jinja:12
|
#: sas/templates/sas/main.jinja:17 sas/templates/sas/picture.jinja:12
|
||||||
msgid "SAS"
|
msgid "SAS"
|
||||||
msgstr "SAS"
|
msgstr "SAS"
|
||||||
@ -5333,23 +5351,6 @@ msgstr "Image précédente"
|
|||||||
msgid "People"
|
msgid "People"
|
||||||
msgstr "Personne(s)"
|
msgstr "Personne(s)"
|
||||||
|
|
||||||
#: sas/views.py:37
|
|
||||||
msgid "Add a new album"
|
|
||||||
msgstr "Ajouter un nouvel album"
|
|
||||||
|
|
||||||
#: sas/views.py:40
|
|
||||||
msgid "Upload images"
|
|
||||||
msgstr "Envoyer les images"
|
|
||||||
|
|
||||||
#: sas/views.py:58
|
|
||||||
#, python-format
|
|
||||||
msgid "Error creating album %(album)s: %(msg)s"
|
|
||||||
msgstr "Erreur de création de l'album %(album)s : %(msg)s"
|
|
||||||
|
|
||||||
#: sas/views.py:93 trombi/templates/trombi/detail.jinja:15
|
|
||||||
msgid "Add user"
|
|
||||||
msgstr "Ajouter une personne"
|
|
||||||
|
|
||||||
#: sith/settings.py:255 sith/settings.py:474
|
#: sith/settings.py:255 sith/settings.py:474
|
||||||
msgid "English"
|
msgid "English"
|
||||||
msgstr "Anglais"
|
msgstr "Anglais"
|
||||||
|
90
sas/forms.py
Normal file
90
sas/forms.py
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
from ajax_select import make_ajax_field
|
||||||
|
from ajax_select.fields import AutoCompleteSelectMultipleField
|
||||||
|
from django import forms
|
||||||
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
|
from core.views import MultipleImageField
|
||||||
|
from core.views.forms import SelectDate
|
||||||
|
from sas.models import Album, PeoplePictureRelation, Picture
|
||||||
|
|
||||||
|
|
||||||
|
class SASForm(forms.Form):
|
||||||
|
album_name = forms.CharField(
|
||||||
|
label=_("Add a new album"), max_length=Album.NAME_MAX_LENGTH, required=False
|
||||||
|
)
|
||||||
|
images = MultipleImageField(
|
||||||
|
label=_("Upload images"),
|
||||||
|
required=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
def process(self, parent, owner, files, *, automodere=False):
|
||||||
|
try:
|
||||||
|
if self.cleaned_data["album_name"] != "":
|
||||||
|
album = Album(
|
||||||
|
parent=parent,
|
||||||
|
name=self.cleaned_data["album_name"],
|
||||||
|
owner=owner,
|
||||||
|
is_moderated=automodere,
|
||||||
|
)
|
||||||
|
album.clean()
|
||||||
|
album.save()
|
||||||
|
except Exception as e:
|
||||||
|
self.add_error(
|
||||||
|
None,
|
||||||
|
_("Error creating album %(album)s: %(msg)s")
|
||||||
|
% {"album": self.cleaned_data["album_name"], "msg": repr(e)},
|
||||||
|
)
|
||||||
|
for f in files:
|
||||||
|
new_file = Picture(
|
||||||
|
parent=parent,
|
||||||
|
name=f.name,
|
||||||
|
file=f,
|
||||||
|
owner=owner,
|
||||||
|
mime_type=f.content_type,
|
||||||
|
size=f.size,
|
||||||
|
is_folder=False,
|
||||||
|
is_moderated=automodere,
|
||||||
|
)
|
||||||
|
if automodere:
|
||||||
|
new_file.moderator = owner
|
||||||
|
try:
|
||||||
|
new_file.clean()
|
||||||
|
new_file.generate_thumbnails()
|
||||||
|
new_file.save()
|
||||||
|
except Exception as e:
|
||||||
|
self.add_error(
|
||||||
|
None,
|
||||||
|
_("Error uploading file %(file_name)s: %(msg)s")
|
||||||
|
% {"file_name": f, "msg": repr(e)},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class RelationForm(forms.ModelForm):
|
||||||
|
class Meta:
|
||||||
|
model = PeoplePictureRelation
|
||||||
|
fields = ["picture"]
|
||||||
|
widgets = {"picture": forms.HiddenInput}
|
||||||
|
|
||||||
|
users = AutoCompleteSelectMultipleField(
|
||||||
|
"users", show_help_text=False, help_text="", label=_("Add user"), required=False
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class PictureEditForm(forms.ModelForm):
|
||||||
|
class Meta:
|
||||||
|
model = Picture
|
||||||
|
fields = ["name", "parent"]
|
||||||
|
|
||||||
|
parent = make_ajax_field(Picture, "parent", "files", help_text="")
|
||||||
|
|
||||||
|
|
||||||
|
class AlbumEditForm(forms.ModelForm):
|
||||||
|
class Meta:
|
||||||
|
model = Album
|
||||||
|
fields = ["name", "date", "file", "parent", "edit_groups"]
|
||||||
|
|
||||||
|
name = forms.CharField(max_length=Album.NAME_MAX_LENGTH, label=_("file name"))
|
||||||
|
date = forms.DateField(label=_("Date"), widget=SelectDate, required=True)
|
||||||
|
parent = make_ajax_field(Album, "parent", "files", help_text="")
|
||||||
|
edit_groups = make_ajax_field(Album, "edit_groups", "groups", help_text="")
|
||||||
|
recursive = forms.BooleanField(label=_("Apply rights recursively"), required=False)
|
91
sas/views.py
91
sas/views.py
@ -13,9 +13,6 @@
|
|||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
from ajax_select import make_ajax_field
|
|
||||||
from ajax_select.fields import AutoCompleteSelectMultipleField
|
|
||||||
from django import forms
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.exceptions import PermissionDenied
|
from django.core.exceptions import PermissionDenied
|
||||||
from django.http import Http404, HttpResponse
|
from django.http import Http404, HttpResponse
|
||||||
@ -27,71 +24,9 @@ from django.views.generic.edit import FormMixin, FormView, UpdateView
|
|||||||
|
|
||||||
from core.models import SithFile, User
|
from core.models import SithFile, User
|
||||||
from core.views import CanEditMixin, CanViewMixin
|
from core.views import CanEditMixin, CanViewMixin
|
||||||
from core.views.files import FileView, MultipleImageField, send_file
|
from core.views.files import FileView, send_file
|
||||||
from core.views.forms import SelectDate
|
from sas.forms import AlbumEditForm, PictureEditForm, SASForm
|
||||||
from sas.models import Album, PeoplePictureRelation, Picture
|
from sas.models import Album, Picture
|
||||||
|
|
||||||
|
|
||||||
class SASForm(forms.Form):
|
|
||||||
album_name = forms.CharField(
|
|
||||||
label=_("Add a new album"), max_length=Album.NAME_MAX_LENGTH, required=False
|
|
||||||
)
|
|
||||||
images = MultipleImageField(
|
|
||||||
label=_("Upload images"),
|
|
||||||
required=False,
|
|
||||||
)
|
|
||||||
|
|
||||||
def process(self, parent, owner, files, *, automodere=False):
|
|
||||||
try:
|
|
||||||
if self.cleaned_data["album_name"] != "":
|
|
||||||
album = Album(
|
|
||||||
parent=parent,
|
|
||||||
name=self.cleaned_data["album_name"],
|
|
||||||
owner=owner,
|
|
||||||
is_moderated=automodere,
|
|
||||||
)
|
|
||||||
album.clean()
|
|
||||||
album.save()
|
|
||||||
except Exception as e:
|
|
||||||
self.add_error(
|
|
||||||
None,
|
|
||||||
_("Error creating album %(album)s: %(msg)s")
|
|
||||||
% {"album": self.cleaned_data["album_name"], "msg": repr(e)},
|
|
||||||
)
|
|
||||||
for f in files:
|
|
||||||
new_file = Picture(
|
|
||||||
parent=parent,
|
|
||||||
name=f.name,
|
|
||||||
file=f,
|
|
||||||
owner=owner,
|
|
||||||
mime_type=f.content_type,
|
|
||||||
size=f.size,
|
|
||||||
is_folder=False,
|
|
||||||
is_moderated=automodere,
|
|
||||||
)
|
|
||||||
if automodere:
|
|
||||||
new_file.moderator = owner
|
|
||||||
try:
|
|
||||||
new_file.clean()
|
|
||||||
new_file.generate_thumbnails()
|
|
||||||
new_file.save()
|
|
||||||
except Exception as e:
|
|
||||||
self.add_error(
|
|
||||||
None,
|
|
||||||
_("Error uploading file %(file_name)s: %(msg)s")
|
|
||||||
% {"file_name": f, "msg": repr(e)},
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class RelationForm(forms.ModelForm):
|
|
||||||
class Meta:
|
|
||||||
model = PeoplePictureRelation
|
|
||||||
fields = ["picture"]
|
|
||||||
widgets = {"picture": forms.HiddenInput}
|
|
||||||
|
|
||||||
users = AutoCompleteSelectMultipleField(
|
|
||||||
"users", show_help_text=False, help_text="", label=_("Add user"), required=False
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class SASMainView(FormView):
|
class SASMainView(FormView):
|
||||||
@ -293,26 +228,6 @@ class ModerationView(TemplateView):
|
|||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
|
|
||||||
class PictureEditForm(forms.ModelForm):
|
|
||||||
class Meta:
|
|
||||||
model = Picture
|
|
||||||
fields = ["name", "parent"]
|
|
||||||
|
|
||||||
parent = make_ajax_field(Picture, "parent", "files", help_text="")
|
|
||||||
|
|
||||||
|
|
||||||
class AlbumEditForm(forms.ModelForm):
|
|
||||||
class Meta:
|
|
||||||
model = Album
|
|
||||||
fields = ["name", "date", "file", "parent", "edit_groups"]
|
|
||||||
|
|
||||||
name = forms.CharField(max_length=Album.NAME_MAX_LENGTH, label=_("file name"))
|
|
||||||
date = forms.DateField(label=_("Date"), widget=SelectDate, required=True)
|
|
||||||
parent = make_ajax_field(Album, "parent", "files", help_text="")
|
|
||||||
edit_groups = make_ajax_field(Album, "edit_groups", "groups", help_text="")
|
|
||||||
recursive = forms.BooleanField(label=_("Apply rights recursively"), required=False)
|
|
||||||
|
|
||||||
|
|
||||||
class PictureEditView(CanEditMixin, UpdateView):
|
class PictureEditView(CanEditMixin, UpdateView):
|
||||||
model = Picture
|
model = Picture
|
||||||
form_class = PictureEditForm
|
form_class = PictureEditForm
|
||||||
|
Loading…
Reference in New Issue
Block a user