From 44f4112a8796f5d2c555bed63f34b9ce98e5fe65 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Tue, 25 Feb 2014 13:33:46 +0100 Subject: [PATCH] Link to existing cover when trying to add a duplicate. --- apps/cover/forms.py | 19 +++++--- apps/cover/locale/pl/LC_MESSAGES/django.mo | Bin 1304 -> 1502 bytes apps/cover/locale/pl/LC_MESSAGES/django.po | 54 +++++++++++++-------- lib/librarian | 2 +- 4 files changed, 47 insertions(+), 28 deletions(-) diff --git a/apps/cover/forms.py b/apps/cover/forms.py index 5b514f08..f49f4f54 100755 --- a/apps/cover/forms.py +++ b/apps/cover/forms.py @@ -6,8 +6,9 @@ import re from urllib2 import urlopen from django import forms -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import ugettext_lazy as _, ugettext from cover.models import Image +from django.utils.text import mark_safe class ImageAddForm(forms.ModelForm): class Meta: @@ -18,10 +19,17 @@ class ImageAddForm(forms.ModelForm): self.fields['file'].required = False def clean_download_url(self): - return self.cleaned_data['download_url'] or None - - def clean_source_url(self): - return self.cleaned_data['source_url'] or None + cl = self.cleaned_data['download_url'] or None + if cl is not None: + try: + img = Image.objects.get(download_url=cl) + except Image.DoesNotExist: + pass + else: + raise forms.ValidationError(mark_safe( + ugettext('Image already in repository.' + ) % {'url': img.get_absolute_url()})) + return cl def clean(self): cleaned_data = super(ImageAddForm, self).clean() @@ -29,7 +37,6 @@ class ImageAddForm(forms.ModelForm): raise forms.ValidationError('No image specified') return cleaned_data - class ImageEditForm(forms.ModelForm): """Form used for editing a Book.""" class Meta: diff --git a/apps/cover/locale/pl/LC_MESSAGES/django.mo b/apps/cover/locale/pl/LC_MESSAGES/django.mo index 3a84d1d3414ccc65b035dcefe18e2497580ce5a2..1c297fe04ceca54bd840ece7384be86ab5307166 100644 GIT binary patch delta 730 zcmZwDO=uHA6u|LG8mp$(kF=irV5kTcN!+9jXsiWA6h%xbMC?f>W?HxT*fQBzl1mSQ zcoD><;N6QLf(I{RMT8a9QN&RKi<4~Gmn!SL(3bf#EN3< zCk_&8#37;{)%KSxS{<2!) zK?>YONqmSYTI$TxKvWyeM2QnTEoz)h3_AxhqTlv8_vvVkYK8(*Nze~Yrv2b4y>Abs|7 zB~Qkv9El{SqH^p=Udl=70YZixpd7j!w2VD{di#@>rJdpEdF<@WrG}ZeddleA&d!|~ zJ38KW^<%BEX;XLBR6E*lYG)UNmLCSLGj+mDXVjIzRP~$-8u~)rzg2VUYS6T*+_F`& z3(=q0>-=Qe%cXO9ot-G;P968Mo|h~Y)7R`BzvTzb^m!B7g3fu_fAS{0=ttZ|wShMW zPA6}qFWRPchD8gy6xgaC>TD*TnT*C0v)79iXS)CCdBL_qz0h7?)l0pmyB+5H?MA=t eQc&@&>+0@S+eV#prl!j4tDVs5r9$*5aqlkx_kIZg delta 530 zcmYk&Jxjw-6oBEhX)C6F^g}nrfKEyvjkK2HA{7TISX`=8NwwCXHjt`Am*Sv*APD*s z1QDGJf;tFJPHyeu=HTw6@6i@KT-za&J;9p(>Lp)C*JzL5QHOUR>aETR-FVHhj; zK(SpM=6RMXvYtiB&*K=bViL}xZzSBna1%M<&Qczf*&X+ z@P$%PrHV9+Bj5A8CO;q{jU-0>)4+6E&Xi4xDz6CHEoayd>CzABB\n" "Language-Team: LANGUAGE \n" -"Language: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2)\n" +"Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 " +"|| n%100>=20) ? 1 : 2);\n" +"X-Generator: Poedit 1.5.4\n" -#: forms.py:37 +#: forms.py:29 +#, python-format +msgid "Image already in repository." +msgstr "Obraz jest już w repozytorium." + +#: forms.py:60 msgid "Flickr URL" msgstr "URL z Flickra" -#: models.py:18 +#: models.py:19 msgid "title" msgstr "tytuł" -#: models.py:19 +#: models.py:20 msgid "author" msgstr "autor" -#: models.py:20 +#: models.py:21 msgid "license name" msgstr "nazwa licencji" -#: models.py:21 +#: models.py:22 msgid "license URL" msgstr "URL licencji" -#: models.py:22 +#: models.py:23 msgid "source URL" msgstr "URL źródła" -#: models.py:23 +#: models.py:24 msgid "image download URL" msgstr "URL pliku do pobrania" -#: models.py:24 +#: models.py:25 msgid "file" msgstr "plik" -#: models.py:27 +#: models.py:28 msgid "cover image" msgstr "obrazek na okładkę" -#: models.py:28 +#: models.py:29 msgid "cover images" msgstr "obrazki na okładki" -#: templates/cover/add_image.html:6 -#: templates/cover/add_image.html.py:21 +#: templates/cover/add_image.html:33 templates/cover/add_image.html.py:62 msgid "Add image" msgstr "Dodaj obrazek" -#: templates/cover/add_image.html:13 +#: templates/cover/add_image.html:40 msgid "Load from Flickr" msgstr "Pobierz z Flickra" @@ -74,15 +79,22 @@ msgstr "Obrazek na okładkę" msgid "source" msgstr "źródło" -#: templates/cover/image_detail.html:31 +#: templates/cover/image_detail.html:35 msgid "Change" msgstr "Zmień" -#: templates/cover/image_list.html:8 +#: templates/cover/image_detail.html:41 +msgid "Used in:" +msgstr "Użyte w:" + +#: templates/cover/image_detail.html:49 +msgid "None" +msgstr "Brak" + +#: templates/cover/image_list.html:7 msgid "Cover images" msgstr "Obrazki na okładki" -#: templates/cover/image_list.html:11 +#: templates/cover/image_list.html:10 msgid "Add new" msgstr "Dodaj nowy" - diff --git a/lib/librarian b/lib/librarian index ca1a7383..6351b433 160000 --- a/lib/librarian +++ b/lib/librarian @@ -1 +1 @@ -Subproject commit ca1a73838b1045835171dfa243f9c2c0dfa735fe +Subproject commit 6351b433475b8119c8cd0cf7a8c72c623308c5d3 -- 2.20.1