From 727387566db537a9afec3495eafaa6b2b49871b0 Mon Sep 17 00:00:00 2001 From: Alexandre Iooss Date: Fri, 15 Oct 2021 10:55:07 +0200 Subject: [PATCH] Add upload page --- photo21/locale/fr/LC_MESSAGES/django.po | 87 ++++++++++++------- photologue_custom/forms.py | 22 +++++ .../templates/photologue/upload.html | 69 +++++++++++++++ photologue_custom/urls.py | 7 +- photologue_custom/views.py | 33 ++++++- 5 files changed, 185 insertions(+), 33 deletions(-) create mode 100644 photologue_custom/forms.py create mode 100644 photologue_custom/templates/photologue/upload.html diff --git a/photo21/locale/fr/LC_MESSAGES/django.po b/photo21/locale/fr/LC_MESSAGES/django.po index 6ea60a9..d0965ce 100644 --- a/photo21/locale/fr/LC_MESSAGES/django.po +++ b/photo21/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: 2021-10-13 13:52+0000\n" +"POT-Creation-Date: 2021-10-15 08:52+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -42,19 +42,19 @@ msgstr "" msgid "hash" msgstr "" -#: photo21/settings.py:153 +#: photo21/settings.py:163 msgid "German" msgstr "" -#: photo21/settings.py:154 +#: photo21/settings.py:164 msgid "English" msgstr "" -#: photo21/settings.py:155 +#: photo21/settings.py:165 msgid "Spanish" msgstr "" -#: photo21/settings.py:156 +#: photo21/settings.py:166 msgid "French" msgstr "" @@ -108,7 +108,7 @@ msgstr "" msgid "E-mail Addresses" msgstr "" -#: photo21/templates/account/email.html:9 photo21/templates/base.html:51 +#: photo21/templates/account/email.html:9 photo21/templates/base.html:58 #: photo21/templates/socialaccount/connections.html:9 msgid "Account" msgstr "Compte" @@ -225,27 +225,34 @@ msgstr "" msgid "The ENS Paris-Saclay pictures server." msgstr "" -#: photo21/templates/base.html:35 +#: photo21/templates/base.html:36 msgid "Galleries" msgstr "Galeries" -#: photo21/templates/base.html:39 +#: photo21/templates/base.html:41 +#: photologue_custom/templates/photologue/upload.html:6 +#: photologue_custom/templates/photologue/upload.html:54 +#: photologue_custom/templates/photologue/upload.html:65 +msgid "Upload" +msgstr "Téléversement" + +#: photo21/templates/base.html:46 msgid "Manage" msgstr "Gestion" -#: photo21/templates/base.html:60 +#: photo21/templates/base.html:67 msgid "Log out" msgstr "" -#: photo21/templates/base.html:70 +#: photo21/templates/base.html:77 msgid "Log in" msgstr "" -#: photo21/templates/base.html:79 +#: photo21/templates/base.html:86 msgid "Sign up" msgstr "Inscription" -#: photo21/templates/index.html:50 +#: photo21/templates/index.html:49 msgid "Connected as" msgstr "Connecté en tant que" @@ -268,6 +275,24 @@ msgstr "" msgid "Add a 3rd Party Account" msgstr "" +#: photologue_custom/admin.py:45 photologue_custom/models.py:51 +msgid "owner" +msgstr "propriétaire" + +#: photologue_custom/forms.py:13 +msgid "Gallery" +msgstr "Galerie" + +#: photologue_custom/forms.py:15 +msgid "" +"Select a gallery to add these images to. Leave this empty to create a new " +"gallery from the supplied title." +msgstr "" + +#: photologue_custom/forms.py:19 +msgid "New gallery title" +msgstr "Titre de la nouvelle galerie" + #: photologue_custom/models.py:23 msgid "start date" msgstr "date de début" @@ -276,53 +301,57 @@ msgstr "date de début" msgid "end date" msgstr "date de fin" -#: photologue_custom/models.py:51 -msgid "owner" -msgstr "propriétaire" - -#: photologue_custom/templates/photologue/gallery_archive.html:4 -#: photologue_custom/templates/photologue/gallery_archive.html:9 +#: photologue_custom/templates/photologue/gallery_archive.html:7 +#: photologue_custom/templates/photologue/gallery_archive.html:12 msgid "Latest photo galleries" msgstr "" -#: photologue_custom/templates/photologue/gallery_archive.html:15 +#: photologue_custom/templates/photologue/gallery_archive.html:18 msgid "Filter by year" msgstr "" -#: photologue_custom/templates/photologue/gallery_archive.html:32 +#: photologue_custom/templates/photologue/gallery_archive.html:35 msgid "No galleries were found" msgstr "" -#: photologue_custom/templates/photologue/gallery_archive_year.html:4 -#: photologue_custom/templates/photologue/gallery_archive_year.html:9 +#: photologue_custom/templates/photologue/gallery_archive_year.html:7 +#: photologue_custom/templates/photologue/gallery_archive_year.html:12 #, python-format msgid "Galleries for %(show_year)s" msgstr "" -#: photologue_custom/templates/photologue/gallery_archive_year.html:14 +#: photologue_custom/templates/photologue/gallery_archive_year.html:17 msgid "View all galleries" msgstr "" -#: photologue_custom/templates/photologue/gallery_archive_year.html:26 +#: photologue_custom/templates/photologue/gallery_archive_year.html:29 msgid "No galleries were found." msgstr "" -#: photologue_custom/templates/photologue/gallery_detail.html:35 +#: photologue_custom/templates/photologue/gallery_detail.html:38 msgid "to" msgstr "au" -#: photologue_custom/templates/photologue/gallery_detail.html:49 +#: photologue_custom/templates/photologue/gallery_detail.html:54 msgid "All pictures" msgstr "Toutes les photos" -#: photologue_custom/templates/photologue/gallery_detail.html:63 +#: photologue_custom/templates/photologue/gallery_detail.html:75 msgid "Download all gallery" msgstr "Télécharger toute la galerie" -#: photologue_custom/templates/photologue/photo_detail.html:10 +#: photologue_custom/templates/photologue/photo_detail.html:13 msgid "Published" msgstr "" -#: photologue_custom/templates/photologue/photo_detail.html:22 +#: photologue_custom/templates/photologue/photo_detail.html:25 msgid "This photo is found in the following galleries" msgstr "" + +#: photologue_custom/templates/photologue/upload.html:59 +msgid "Drag and drop photos here" +msgstr "Glissez et déposez les photos ici" + +#: photologue_custom/templates/photologue/upload.html:63 +msgid "Owner will be" +msgstr "Le propriétaire sera" diff --git a/photologue_custom/forms.py b/photologue_custom/forms.py new file mode 100644 index 0000000..5db968f --- /dev/null +++ b/photologue_custom/forms.py @@ -0,0 +1,22 @@ +from django import forms +from django.utils.translation import gettext_lazy as _ +from photologue.models import Gallery + + +class UploadForm(forms.Form): + file_field = forms.FileField( + label="", + widget=forms.ClearableFileInput(attrs={'multiple': True}), + ) + gallery = forms.ModelChoiceField( + Gallery.objects.all(), + label=_('Gallery'), + required=False, + help_text=_('Select a gallery to add these images to. Leave this empty to ' + 'create a new gallery from the supplied title.') + ) + new_gallery_title = forms.CharField( + label=_('New gallery title'), + max_length=250, + required=False, + ) diff --git a/photologue_custom/templates/photologue/upload.html b/photologue_custom/templates/photologue/upload.html new file mode 100644 index 0000000..4e16371 --- /dev/null +++ b/photologue_custom/templates/photologue/upload.html @@ -0,0 +1,69 @@ +{% extends "base.html" %} +{% comment %} +SPDX-License-Identifier: GPL-3.0-or-later +{% endcomment %} +{% load i18n crispy_forms_tags %} +{% block title %}{% trans "Upload" %}{% endblock %} + +{% block extracss %} + +{% endblock %} + +{% block extrajs %} + +{% endblock %} + +{% block content %} +

{% trans "Upload" %}

+
+
+
{% csrf_token %} +
+ {% trans "Drag and drop photos here" %} +
+ {{ form|crispy }} +

+ {% trans "Owner will be" %} {{ request.user.get_full_name }} ({{ request.user.username}}). +

+ +
+
+
+{% endblock %} diff --git a/photologue_custom/urls.py b/photologue_custom/urls.py index 6ada0f6..c5fbc20 100644 --- a/photologue_custom/urls.py +++ b/photologue_custom/urls.py @@ -1,8 +1,8 @@ from django.urls import path, re_path -from .views import (CustomGalleryArchiveIndexView, - CustomGalleryYearArchiveView, CustomGalleryDetailView, - GalleryDownload, TagDetail) +from .views import (CustomGalleryArchiveIndexView, CustomGalleryDetailView, + CustomGalleryYearArchiveView, GalleryDownload, + GalleryUpload, TagDetail) urlpatterns = [ path('tag//', TagDetail.as_view(), name='tag-detail'), @@ -11,4 +11,5 @@ urlpatterns = [ path('gallery//', CustomGalleryDetailView.as_view(), name='pl-gallery'), path('gallery///', CustomGalleryDetailView.as_view(), name='pl-gallery-owner'), path('gallery//download/', GalleryDownload.as_view(), name='gallery-download'), + path('upload/', GalleryUpload.as_view(), name='gallery-upload'), ] diff --git a/photologue_custom/views.py b/photologue_custom/views.py index 33b2426..4332f77 100644 --- a/photologue_custom/views.py +++ b/photologue_custom/views.py @@ -6,12 +6,16 @@ import zipfile from io import BytesIO from django.contrib.auth.mixins import LoginRequiredMixin +from django.core.mail import mail_managers from django.http import HttpResponse -from django.views.generic import DetailView +from django.views.generic.detail import DetailView +from django.views.generic.edit import FormView from photologue.models import Gallery from photologue.views import GalleryArchiveIndexView, GalleryYearArchiveView from taggit.models import Tag +from .forms import UploadForm + class TagDetail(LoginRequiredMixin, DetailView): model = Tag @@ -89,3 +93,30 @@ class GalleryDownload(LoginRequiredMixin, DetailView): response = HttpResponse(byte_data.getvalue(), content_type='application/x-zip-compressed') response['Content-Disposition'] = f"attachment; filename={gallery.slug}.zip" return response + + +class GalleryUpload(FormView): + form_class = UploadForm + template_name = "photologue/upload.html" + # success_url = '...' # Replace with your URL or reverse(). + + def post(self, request, *args, **kwargs): + form_class = self.get_form_class() + form = self.get_form(form_class) + files = request.FILES.getlist('file_field') + if form.is_valid(): + for f in files: + print("upload", f) + return self.form_valid(form) + else: + return self.form_invalid(form) + + def form_valid(self, form): + """ + Notify moderators about successful upload + """ + mail_managers( + subject="New upload", + message="", # TODO: put username, gallery and photo names + ) + return super().form_valid(form)