From 193b26891b312d8ab98457e1d29b54c0ffd94712 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Mon, 23 Aug 2010 11:34:40 +0200 Subject: [PATCH 1/1] xml upload: handle utf-8 properly --- apps/wiki/locale/pl/LC_MESSAGES/django.mo | Bin 4896 -> 5011 bytes apps/wiki/locale/pl/LC_MESSAGES/django.po | 23 ++++++++++++------ apps/wiki/templates/wiki/document_upload.html | 2 +- apps/wiki/views.py | 9 +++++-- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/apps/wiki/locale/pl/LC_MESSAGES/django.mo b/apps/wiki/locale/pl/LC_MESSAGES/django.mo index d89c93500af55f33727924405065803b84dbd307..0e5d4a7c89b2f695f79f854a99db6cec297ad009 100644 GIT binary patch delta 1863 zcmY+_OKeP09LMp0ORKGFM?I_5^=du(P^GHWv#4h!Sk#8<3`%tfRSR;f64WbcP!b|G zO^8a!EYw1fNLYA8A{Jg7HW~|wG!YAYe=}!Dt$DEbZ&4 z=bvIVzC>TgJd&rgF&D>SIclIys0X&9cA~-cA4E;G6*Yk~&dWHR_6^h#zC}%>54G~& zsBu$xSnWVM`>z#d)1isvq7qKT)&#R@=+W*biynB6y6+7t@q0e>PV}OlOJSC3XQFnn z5XWOB>fP9aEZX)We|9K?{nv$4wDiCg)Yf(*x$OaJz-KrSdod3)xp@JW;SfB4EY41% zp6^7h^ag6ecTfwsi^cd5b^V)9MJxG%Lou1zXrLU_ndc*yY$1}{)}az^M%}j$wZ*=> z-j161B~;=rJc>6_D=+3v*Zmc!e0~)b&7>A}Lmg@bji@d4k!S6gYhOhE?5gX(jhf&i zRN_~taXz9FeZgG(jv6nE!Ixn+()Mi&6_1YXSd1r7Th)VF!6VebPf!EAM(xBqRN`Le zPnrvwcQ4`wj+AWx*?|*Bw!U|CdP9yK0%_4>qdXpCsnvA|iI(Pk2 zP9byz@uH;scv?PDL@XvM2^H-?6%jpRBt^7LCBMyc4XsjVu5W~jzLN1WpGrSMD_5x| zv|5#=F`~!js#Zot+pKqMh3nMMuwG^r?Sx)vKaYk~b1Pq?L_sUg(l?QRG?KJM)b2g5CObi~FgirmV0nvmtS{Jqc|yAWv(+)Vrf D6MCb5 delta 1753 zcmYk-O-PhM9LMol^CfeA-OMaqwS3J?)6A{ZtkhO3?L|72WKsvg0=?96jSgLm3JD>i zyc9+t#Nxq-po9dmL!_tPL?OJG3PBhWeSgo+MuY$T%*;N|{AcEwXB{XQ$`5=^iM($p zEkp*Y`Y6fY4_kp z9KvMsn^7v8>6k#xcowy?MbyOBY`>dnGh>sEN>qSKP=UJ6XZ!uA3AAB5wj)EBG28zZ zwG)$Sliz%zqQvv4ftJzP{SBdsMIpOtyr>oDp(f%(O{5W(@HBF(IcM9KF^l#U)cyVF z#{rDO&lpIjGDjr`*H8m_8C5srqjsVM)nAR8Xgz8Ir>q@VM*Ax2(LF*TG{&0{gEUF4Cc`?Ln>ZCMv;Q%*PQth%@NHRBmF9rU-RkC2EC!)I?9B zCVm!6u>i);rh)->M5wmIk#8SQgsbtqyHK10|f*QCDH9#k7rCq4R*R8j(oc18<_hAxQ zgPBE*w}P6`Z`+P!8#R8s)q~M`|I?{(=FA>K1L=*ZBXqG=QcLI;tdP(n2p4T9KbFq< zD8WNSHKC%jbA(`MXAyfbTn^ZZ7MVu=(7TR${^3$XWgVfFs~jbEJ2jp$77;A$U#X`LT5Lv`7;y9sgRw*EOM$Z2RwN;8kIIowjIyCXA zbFkyT&MNAgh+JYPkxl5)sO%$nqspCUsOQ#9oFH^qbVAFBaLJ*\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={ -- 2.20.1