Add tags to upload form
This commit is contained in:
parent
04951b2ee4
commit
a2e06185ad
3 changed files with 69 additions and 21 deletions
|
|
@ -8,7 +8,7 @@ msgid ""
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: PACKAGE VERSION\n"
|
"Project-Id-Version: PACKAGE VERSION\n"
|
||||||
"Report-Msgid-Bugs-To: \n"
|
"Report-Msgid-Bugs-To: \n"
|
||||||
"POT-Creation-Date: 2021-10-22 16:05+0000\n"
|
"POT-Creation-Date: 2021-10-23 15:29+0000\n"
|
||||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||||
|
|
@ -42,19 +42,19 @@ msgstr ""
|
||||||
msgid "hash"
|
msgid "hash"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: photo21/settings.py:163
|
#: photo21/settings.py:162
|
||||||
msgid "German"
|
msgid "German"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: photo21/settings.py:164
|
#: photo21/settings.py:163
|
||||||
msgid "English"
|
msgid "English"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: photo21/settings.py:165
|
#: photo21/settings.py:164
|
||||||
msgid "Spanish"
|
msgid "Spanish"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: photo21/settings.py:166
|
#: photo21/settings.py:165
|
||||||
msgid "French"
|
msgid "French"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
|
@ -229,10 +229,9 @@ msgstr ""
|
||||||
msgid "Galleries"
|
msgid "Galleries"
|
||||||
msgstr "Galeries"
|
msgstr "Galeries"
|
||||||
|
|
||||||
#: photo21/templates/base.html:41
|
#: photo21/templates/base.html:41 photologue_custom/forms.py:76
|
||||||
#: photologue_custom/templates/photologue/upload.html:6
|
#: photologue_custom/templates/photologue/upload.html:6
|
||||||
#: photologue_custom/templates/photologue/upload.html:54
|
#: photologue_custom/templates/photologue/upload.html:54
|
||||||
#: photologue_custom/templates/photologue/upload.html:65
|
|
||||||
msgid "Upload"
|
msgid "Upload"
|
||||||
msgstr "Téléversement"
|
msgstr "Téléversement"
|
||||||
|
|
||||||
|
|
@ -279,33 +278,46 @@ msgstr ""
|
||||||
msgid "owner"
|
msgid "owner"
|
||||||
msgstr "propriétaire"
|
msgstr "propriétaire"
|
||||||
|
|
||||||
#: photologue_custom/forms.py:22
|
#: photologue_custom/forms.py:34
|
||||||
msgid "Gallery"
|
msgid "Gallery"
|
||||||
msgstr "Galerie"
|
msgstr "Galerie"
|
||||||
|
|
||||||
#: photologue_custom/forms.py:24
|
#: photologue_custom/forms.py:36
|
||||||
|
msgid "-- Create a new gallery --"
|
||||||
|
msgstr "-- Créer une nouvelle galerie --"
|
||||||
|
|
||||||
|
#: photologue_custom/forms.py:37
|
||||||
msgid ""
|
msgid ""
|
||||||
"Select a gallery to add these images to. Leave this empty to create a new "
|
"Select a gallery to add these images to. Leave this empty to create a new "
|
||||||
"gallery from the supplied title."
|
"gallery from the supplied title."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: photologue_custom/forms.py:28
|
#: photologue_custom/forms.py:41
|
||||||
msgid "New gallery title"
|
msgid "New gallery title"
|
||||||
msgstr "Titre de la nouvelle galerie"
|
msgstr "Titre de la nouvelle galerie"
|
||||||
|
|
||||||
#: photologue_custom/forms.py:33
|
#: photologue_custom/forms.py:46
|
||||||
msgid "New gallery event start date"
|
msgid "New gallery event start date"
|
||||||
msgstr "Date de début de l'évènement de la nouvelle galerie"
|
msgstr "Date de début de l'évènement de la nouvelle galerie"
|
||||||
|
|
||||||
#: photologue_custom/forms.py:38
|
#: photologue_custom/forms.py:51
|
||||||
msgid "New gallery event end date"
|
msgid "New gallery event end date"
|
||||||
msgstr "Date de fin de l'évènement de la nouvelle galerie"
|
msgstr "Date de fin de l'évènement de la nouvelle galerie"
|
||||||
|
|
||||||
#: photologue_custom/forms.py:46
|
#: photologue_custom/forms.py:57
|
||||||
|
msgid "New gallery tags"
|
||||||
|
msgstr "Tags de la nouvelle galerie"
|
||||||
|
|
||||||
|
#: photologue_custom/forms.py:59
|
||||||
|
msgid ""
|
||||||
|
"Hold down \"Control\", or \"Command\" on a Mac, to select more than one."
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: photologue_custom/forms.py:82
|
||||||
msgid "A gallery with that title already exists."
|
msgid "A gallery with that title already exists."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: photologue_custom/forms.py:55
|
#: photologue_custom/forms.py:91
|
||||||
msgid "Select an existing gallery, or enter a title for a new gallery."
|
msgid "Select an existing gallery, or enter a title for a new gallery."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,25 @@
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
|
from crispy_forms.helper import FormHelper
|
||||||
|
from crispy_forms.layout import Div, Layout, Submit
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.utils.text import slugify
|
from django.utils.text import slugify
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from photologue.models import Gallery
|
from photologue.models import Gallery
|
||||||
|
from taggit.models import Tag
|
||||||
|
|
||||||
from .models import GalleryExtended
|
from .models import GalleryExtended
|
||||||
|
|
||||||
|
|
||||||
|
class GalleryChoiceField(forms.ModelChoiceField):
|
||||||
|
def label_from_instance(self, obj):
|
||||||
|
"""Show gallery event date."""
|
||||||
|
if hasattr(obj, 'extended'):
|
||||||
|
return f"{ obj.title } ({obj.extended.date_start})"
|
||||||
|
else:
|
||||||
|
return obj.title
|
||||||
|
|
||||||
|
|
||||||
class UploadForm(forms.Form):
|
class UploadForm(forms.Form):
|
||||||
file_field = forms.FileField(
|
file_field = forms.FileField(
|
||||||
label="",
|
label="",
|
||||||
|
|
@ -17,10 +29,11 @@ class UploadForm(forms.Form):
|
||||||
'class': 'mb-3',
|
'class': 'mb-3',
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
gallery = forms.ModelChoiceField(
|
gallery = GalleryChoiceField(
|
||||||
Gallery.objects.all(),
|
Gallery.objects.all(),
|
||||||
label=_('Gallery'),
|
label=_('Gallery'),
|
||||||
required=False,
|
required=False,
|
||||||
|
empty_label=_('-- Create a new gallery --'),
|
||||||
help_text=_('Select a gallery to add these images to. Leave this empty to '
|
help_text=_('Select a gallery to add these images to. Leave this empty to '
|
||||||
'create a new gallery from the supplied title.')
|
'create a new gallery from the supplied title.')
|
||||||
)
|
)
|
||||||
|
|
@ -29,16 +42,39 @@ class UploadForm(forms.Form):
|
||||||
max_length=250,
|
max_length=250,
|
||||||
required=False,
|
required=False,
|
||||||
)
|
)
|
||||||
date_start = forms.DateField(
|
new_gallery_date_start = forms.DateField(
|
||||||
label=_('New gallery event start date'),
|
label=_('New gallery event start date'),
|
||||||
initial=datetime.date.today,
|
initial=datetime.date.today,
|
||||||
required=False,
|
required=False,
|
||||||
)
|
)
|
||||||
date_end = forms.DateField(
|
new_gallery_date_end = forms.DateField(
|
||||||
label=_('New gallery event end date'),
|
label=_('New gallery event end date'),
|
||||||
initial=datetime.date.today,
|
initial=datetime.date.today,
|
||||||
required=False,
|
required=False,
|
||||||
)
|
)
|
||||||
|
new_gallery_tags = forms.ModelMultipleChoiceField(
|
||||||
|
Tag.objects.all(),
|
||||||
|
label=_('New gallery tags'),
|
||||||
|
required=False,
|
||||||
|
help_text=_('Hold down "Control", or "Command" on a Mac, to select more than one.')
|
||||||
|
)
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
self.helper = FormHelper()
|
||||||
|
self.helper.use_custom_control = False
|
||||||
|
self.helper.layout = Layout(
|
||||||
|
'file_field',
|
||||||
|
'gallery',
|
||||||
|
'new_gallery_title',
|
||||||
|
Div(
|
||||||
|
Div('new_gallery_date_start', css_class='col'),
|
||||||
|
Div('new_gallery_date_end', css_class='col'),
|
||||||
|
css_class='row'
|
||||||
|
),
|
||||||
|
'new_gallery_tags',
|
||||||
|
Submit('submit', _('Upload'), css_class='btn btn-success mt-2')
|
||||||
|
)
|
||||||
|
|
||||||
def clean_new_gallery_title(self):
|
def clean_new_gallery_title(self):
|
||||||
title = self.cleaned_data['new_gallery_title']
|
title = self.cleaned_data['new_gallery_title']
|
||||||
|
|
@ -67,7 +103,8 @@ class UploadForm(forms.Form):
|
||||||
gallery = Gallery.objects.create(title=title, slug=slugify(title))
|
gallery = Gallery.objects.create(title=title, slug=slugify(title))
|
||||||
GalleryExtended.objects.create(
|
GalleryExtended.objects.create(
|
||||||
gallery=gallery,
|
gallery=gallery,
|
||||||
date_start=self.cleaned_data['date_start'],
|
tags=self.cleaned_data['new_gallery_tags'],
|
||||||
date_end=self.cleaned_data['date_end'],
|
date_start=self.cleaned_data['new_gallery_date_start'],
|
||||||
|
date_end=self.cleaned_data['new_gallery_date_end'],
|
||||||
)
|
)
|
||||||
return gallery
|
return gallery
|
||||||
|
|
|
||||||
|
|
@ -58,11 +58,10 @@ dropZone.ondragleave = function() {
|
||||||
<div class="upload-drop-zone" id="drop-zone">
|
<div class="upload-drop-zone" id="drop-zone">
|
||||||
{% trans "Drag and drop photos here" %}
|
{% trans "Drag and drop photos here" %}
|
||||||
</div>
|
</div>
|
||||||
{{ form|crispy }}
|
{% crispy form %}
|
||||||
<p class="mt-3">
|
<p class="mt-3">
|
||||||
{% trans "Owner will be" %} <code>{{ request.user.get_full_name }} ({{ request.user.username}})</code>.
|
{% trans "Owner will be" %} <code>{{ request.user.get_full_name }} ({{ request.user.username}})</code>.
|
||||||
</p>
|
</p>
|
||||||
<button type="submit" class="btn btn-success">{% trans "Upload" %}</button>
|
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue