Link to existing cover when trying to add a duplicate.
authorRadek Czajka <radekczajka@nowoczesnapolska.org.pl>
Tue, 25 Feb 2014 12:33:46 +0000 (13:33 +0100)
committerRadek Czajka <radekczajka@nowoczesnapolska.org.pl>
Tue, 25 Feb 2014 12:34:33 +0000 (13:34 +0100)
apps/cover/forms.py
apps/cover/locale/pl/LC_MESSAGES/django.mo
apps/cover/locale/pl/LC_MESSAGES/django.po
lib/librarian

index 5b514f0..f49f4f5 100755 (executable)
@@ -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 <a href="%(url)s">already in repository</a>.'
+                        ) % {'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:
index 3a84d1d..1c297fe 100644 (file)
Binary files a/apps/cover/locale/pl/LC_MESSAGES/django.mo and b/apps/cover/locale/pl/LC_MESSAGES/django.mo differ
index 7b8ba0f..67547ce 100644 (file)
@@ -7,62 +7,67 @@ msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2012-06-18 12:36+0200\n"
-"PO-Revision-Date: 2012-06-18 12:38+0100\n"
+"POT-Creation-Date: 2014-02-25 13:29+0100\n"
+"PO-Revision-Date: 2014-02-25 13:30+0100\n"
 "Last-Translator: Radek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>\n"
 "Language-Team: LANGUAGE <LL@li.org>\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 <a href=\"%(url)s\">already in repository</a>."
+msgstr "Obraz <a href=\"%(url)s\">jest już w repozytorium</a>."
+
+#: 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"
-
index ca1a738..6351b43 160000 (submodule)
@@ -1 +1 @@
-Subproject commit ca1a73838b1045835171dfa243f9c2c0dfa735fe
+Subproject commit 6351b433475b8119c8cd0cf7a8c72c623308c5d3