From: Radek Czajka Date: Mon, 23 Aug 2010 09:34:40 +0000 (+0200) Subject: xml upload: handle utf-8 properly X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/193b26891b312d8ab98457e1d29b54c0ffd94712?ds=sidebyside;hp=b13038d172d0ac2bb1582452e55b43e727805031 xml upload: handle utf-8 properly --- diff --git a/apps/wiki/locale/pl/LC_MESSAGES/django.mo b/apps/wiki/locale/pl/LC_MESSAGES/django.mo index d89c9350..0e5d4a7c 100644 Binary files a/apps/wiki/locale/pl/LC_MESSAGES/django.mo and b/apps/wiki/locale/pl/LC_MESSAGES/django.mo differ diff --git a/apps/wiki/locale/pl/LC_MESSAGES/django.po b/apps/wiki/locale/pl/LC_MESSAGES/django.po index b818527f..4eb2c76e 100644 --- a/apps/wiki/locale/pl/LC_MESSAGES/django.po +++ b/apps/wiki/locale/pl/LC_MESSAGES/django.po @@ -7,10 +7,11 @@ msgid "" msgstr "" "Project-Id-Version: Platforma Redakcyjna\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-08-16 16:22+0200\n" +"POT-Creation-Date: 2010-08-23 11:22+0200\n" "PO-Revision-Date: 2010-08-16 16:24+0100\n" "Last-Translator: Radek Czajka \n" -"Language-Team: Fundacja Nowoczesna Polska \n" +"Language-Team: Fundacja Nowoczesna Polska \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -117,7 +118,11 @@ msgstr "Nazwa taka sama jak dla pliku %s" msgid "Title already used in repository." msgstr "Plik o tej nazwie już istnieje w repozytorium." -#: views.py:339 +#: views.py:173 +msgid "File should be UTF-8 encoded." +msgstr "Plik powinien mieć kodowanie UTF-8." + +#: views.py:344 msgid "Tag added" msgstr "Dodano tag" @@ -175,15 +180,20 @@ msgid "Bulk documents upload" msgstr "Hurtowe dodawanie dokumentów" #: templates/wiki/document_upload.html:12 -msgid "Please submit a ZIP with XML files. Files not ending with .xml will be ignored." -msgstr "Proszę wskazać archiwum ZIP z plikami XML. Pliki nie kończące się na .xml zostaną zignorowane." +msgid "" +"Please submit a ZIP with UTF-8 encoded XML files. Files not ending with " +".xml will be ignored." +msgstr "" +"Proszę wskazać archiwum ZIP z plikami XML w kodowaniu UTF-8. Pliki nie kończące się na ." +"xml zostaną zignorowane." #: templates/wiki/document_upload.html:17 msgid "Upload" msgstr "Dodaj" #: templates/wiki/document_upload.html:24 -msgid "There have been some errors. No files have been added to the repository." +msgid "" +"There have been some errors. No files have been added to the repository." msgstr "Wystąpiły błędy. Żadne pliki nie zostały dodane do repozytorium." #: templates/wiki/document_upload.html:25 @@ -330,4 +340,3 @@ msgstr "Wstaw znak specjalny" #: templates/wiki/tabs/wysiwyg_editor_item.html:3 msgid "Visual editor" msgstr "Edytor wizualny" - diff --git a/apps/wiki/templates/wiki/document_upload.html b/apps/wiki/templates/wiki/document_upload.html index f1e37f76..d4c89d35 100644 --- a/apps/wiki/templates/wiki/document_upload.html +++ b/apps/wiki/templates/wiki/document_upload.html @@ -9,7 +9,7 @@

{% trans "Bulk documents upload" %}

-{% trans "Please submit a ZIP with XML files. Files not ending with .xml will be ignored." %} +{% trans "Please submit a ZIP with UTF-8 encoded XML files. Files not ending with .xml will be ignored." %}

diff --git a/apps/wiki/views.py b/apps/wiki/views.py index 1bc40617..319cdbad 100644 --- a/apps/wiki/views.py +++ b/apps/wiki/views.py @@ -166,13 +166,18 @@ def upload(request): elif title in existing: error_list.append((filename, title, _('Title already used in repository.'))) else: - ok_list.append((filename, title)) + try: + zip.read(filename).decode('utf-8') # test read + ok_list.append((filename, title)) + except UnicodeDecodeError: + error_list.append((filename, title, _('File should be UTF-8 encoded.'))) titles[title] = filename + if not error_list: for filename, title in ok_list: storage.create_document( name=title, - text=zip.read(filename) + text=zip.read(filename).decode('utf-8') ) return direct_to_template(request, "wiki/document_upload.html", extra_context={