From: root Date: Mon, 16 Aug 2010 10:42:38 +0000 (-0500) Subject: Merge branch 'master' of git@github.com:fnp/redakcja X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/d3a175f9e18a22afc425afb669a77c79d128df74?hp=8f5de4086a5456b580c4fd4de972da986d3cbb63 Merge branch 'master' of git@github.com:fnp/redakcja --- diff --git a/apps/wiki/forms.py b/apps/wiki/forms.py index e0c69fdd..e48c5eae 100644 --- a/apps/wiki/forms.py +++ b/apps/wiki/forms.py @@ -23,7 +23,7 @@ class DocumentCreateForm(forms.Form): Form used for creating new documents. """ title = forms.CharField() - id = forms.RegexField(regex=ur"\w+") + id = forms.RegexField(regex=ur"^[\wąćęłńóśźżĄĆĘŁŃÓŚŹŻ]+$") file = forms.FileField(required=False) text = forms.CharField(required=False, widget=forms.Textarea) @@ -42,6 +42,26 @@ class DocumentCreateForm(forms.Form): return self.cleaned_data +class DocumentsUploadForm(forms.Form): + """ + Form used for uploading new documents. + """ + file = forms.FileField(required=True, label=_('ZIP file')) + + def clean(self): + file = self.cleaned_data['file'] + + import zipfile + try: + z = self.cleaned_data['zip'] = zipfile.ZipFile(file) + except zipfile.BadZipfile: + raise forms.ValidationError("Should be a ZIP file.") + if z.testzip(): + raise forms.ValidationError("ZIP file corrupt.") + + return self.cleaned_data + + class DocumentTextSaveForm(forms.Form): """ Form for saving document's text: @@ -60,7 +80,7 @@ class DocumentTextSaveForm(forms.Form): author_name = forms.CharField( required=False, label=_(u"Author"), - help_text=_(u"Your name/"), + help_text=_(u"Your name"), ) author_email = forms.EmailField( diff --git a/apps/wiki/locale/pl/LC_MESSAGES/django.mo b/apps/wiki/locale/pl/LC_MESSAGES/django.mo index ffadebc8..07128051 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 159aa853..6df7bab4 100644 --- a/apps/wiki/locale/pl/LC_MESSAGES/django.po +++ b/apps/wiki/locale/pl/LC_MESSAGES/django.po @@ -3,15 +3,14 @@ # This file is distributed under the same license as the PACKAGE package. # FIRST AUTHOR , YEAR. # -#, fuzzy msgid "" msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" +"Project-Id-Version: Platforma Redakcyjna\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-08-03 12:13+0200\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"POT-Creation-Date: 2010-08-12 12:22+0200\n" +"PO-Revision-Date: 2010-08-12 12:24+0100\n" "Last-Translator: Radek Czajka \n" -"Language-Team: LANGUAGE \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" @@ -52,35 +51,39 @@ msgstr "Ostateczna redakcja techniczna" msgid "Ready to publish" msgstr "Gotowe do publikacji" -#: forms.py:62 +#: forms.py:49 +msgid "ZIP file" +msgstr "Plik ZIP" + +#: forms.py:82 msgid "Author" msgstr "Autor" -#: forms.py:63 -msgid "Your name/" -msgstr "Imię i nazwisko/" +#: forms.py:83 +msgid "Your name" +msgstr "Imię i nazwisko" -#: forms.py:68 +#: forms.py:88 msgid "Author's email" msgstr "E-mail autora" -#: forms.py:69 +#: forms.py:89 msgid "Your email address, so we can show a gravatar :)" msgstr "Adres e-mail, żebyśmy mogli pokazać gravatar :)" -#: forms.py:75 +#: forms.py:95 msgid "Your comments" msgstr "Twój komentarz" -#: forms.py:76 +#: forms.py:96 msgid "Describe changes you made." msgstr "Opisz swoje zmiany" -#: forms.py:82 +#: forms.py:102 msgid "Completed" msgstr "Ukończono" -#: forms.py:83 +#: forms.py:103 msgid "If you completed a life cycle stage, select it." msgstr "Jeśli został ukończony etap prac, wskaż go." @@ -101,7 +104,16 @@ msgstr "motyw" msgid "themes" msgstr "motywy" -#: views.py:279 +#: views.py:165 +#, python-format +msgid "Title already used for %s" +msgstr "Nazwa taka sama jak dla pliku %s" + +#: views.py:167 +msgid "Title already used in repository." +msgstr "Plik o tej nazwie już istnieje w repozytorium." + +#: views.py:339 msgid "Tag added" msgstr "Dodano tag" @@ -144,7 +156,7 @@ msgstr "Zapisz" #: templates/wiki/document_details_base.html:41 msgid "Save attempt in progress" -msgstr "" +msgstr "Trwa zapisywanie" #: templates/wiki/document_list.html:30 msgid "Clear filter" @@ -154,6 +166,46 @@ msgstr "Wyczyść filtr" msgid "Your last edited documents" msgstr "Twoje ostatnie edycje" +#: templates/wiki/document_upload.html:9 +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." + +#: 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." +msgstr "Wystąpiły błędy. Żadne pliki nie zostały dodane do repozytorium." + +#: templates/wiki/document_upload.html:25 +msgid "Offending files" +msgstr "Błędne pliki" + +#: templates/wiki/document_upload.html:33 +msgid "Correct files" +msgstr "Poprawne pliki" + +#: templates/wiki/document_upload.html:44 +msgid "Files have been successfully uploaded to the repository." +msgstr "Pliki zostały dodane do repozytorium." + +#: templates/wiki/document_upload.html:45 +msgid "Uploaded files" +msgstr "Dodane pliki" + +#: templates/wiki/document_upload.html:55 +msgid "Skipped files" +msgstr "Pominięte pliki" + +#: templates/wiki/document_upload.html:56 +msgid "Files skipped due to no .xml extension" +msgstr "Pliki pominięte z powodu braku rozszerzenia .xml." + #: templates/wiki/tag_dialog.html:16 msgid "Cancel" msgstr "Anuluj" @@ -270,3 +322,4 @@ msgstr "Wstaw przypis" #: templates/wiki/tabs/wysiwyg_editor_item.html:3 msgid "Visual editor" msgstr "Edytor wizualny" + diff --git a/apps/wiki/models.py b/apps/wiki/models.py index 5faf1d3b..da8681aa 100644 --- a/apps/wiki/models.py +++ b/apps/wiki/models.py @@ -35,7 +35,7 @@ def normalize_name(name): >>> normalize_name("gąska".decode('utf-8')) u'g\u0105ska' """ - return name.translate(_PCHARS_DICT).lower() + return unicode(name).translate(_PCHARS_DICT) STAGE_TAGS_RE = re.compile(r'^#stage-finished: (.*)$', re.MULTILINE) @@ -73,7 +73,7 @@ class DocumentStorage(object): return document def create_document(self, text, name): - title = u', '.join(p.title for p in split_name(name)) + title = u', '.join(p.title() for p in split_name(name)) if text is None: text = u'' diff --git a/apps/wiki/templates/wiki/document_details.html b/apps/wiki/templates/wiki/document_details.html index 9657e0f6..78612dd2 100644 --- a/apps/wiki/templates/wiki/document_details.html +++ b/apps/wiki/templates/wiki/document_details.html @@ -11,15 +11,15 @@ {% block tabs-menu %} {% include "wiki/tabs/summary_view_item.html" %} {% include "wiki/tabs/wysiwyg_editor_item.html" %} - {% include "wiki/tabs/history_view_item.html" %} {% include "wiki/tabs/source_editor_item.html" %} + {% include "wiki/tabs/history_view_item.html" %} {% endblock %} {% block tabs-content %} {% include "wiki/tabs/summary_view.html" %} {% include "wiki/tabs/wysiwyg_editor.html" %} - {% include "wiki/tabs/history_view.html" %} {% include "wiki/tabs/source_editor.html" %} + {% include "wiki/tabs/history_view.html" %} {% endblock %} {% block tabs-right %} diff --git a/apps/wiki/templates/wiki/document_upload.html b/apps/wiki/templates/wiki/document_upload.html new file mode 100644 index 00000000..f1e37f76 --- /dev/null +++ b/apps/wiki/templates/wiki/document_upload.html @@ -0,0 +1,69 @@ +{% extends "wiki/base.html" %} +{% load i18n %} +{% load wiki %} + + +{% block leftcolumn %} + + +

{% trans "Bulk documents upload" %}

+ +

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

+ +
+{{ form.as_p }} +

+
+ +
+ +{% if error_list %} + +

{% trans "There have been some errors. No files have been added to the repository." %} +

{% trans "Offending files" %}

+
    + {% for filename, title, error in error_list %} +
  • {{title|wiki_title}} ({{ filename }}): {{ error }}
  • + {% endfor %} +
+ + {% if ok_list %} +

{% trans "Correct files" %}

+
    + {% for filename, title in ok_list %} +
  • {{title|wiki_title}} ({{ filename }})
  • + {% endfor %} +
+ {% endif %} + +{% else %} + + {% if ok_list %} +

{% trans "Files have been successfully uploaded to the repository." %}

+

{% trans "Uploaded files" %}

+ + {% endif %} +{% endif %} + +{% if skipped_list %} +

{% trans "Skipped files" %}

+

{% trans "Files skipped due to no .xml extension" %}

+
    + {% for filename in skipped_list %} +
  • {{ filename }}
  • + {% endfor %} +
+{% endif %} + + +{% endblock leftcolumn %} + + +{% block rightcolumn %} +{% endblock rightcolumn %} diff --git a/apps/wiki/templates/wiki/save_dialog.html b/apps/wiki/templates/wiki/save_dialog.html index 71c999bf..b2f53bab 100644 --- a/apps/wiki/templates/wiki/save_dialog.html +++ b/apps/wiki/templates/wiki/save_dialog.html @@ -11,12 +11,20 @@ {% if request.user.is_anonymous %} -

- {{ forms.text_save.author.label }}: - {{ forms.text_save.author }} - {{ forms.text_save.author.help_text }} - -

+ + + + + + + + + +
{{ forms.text_save.author_name.label }}:{{ forms.text_save.author_name }} + {{ forms.text_save.author_name.help_text }} +
{{ forms.text_save.author_email.label }}:{{ forms.text_save.author_email }} + {{ forms.text_save.author_email.help_text }} +
{% else %}

{{ forms.text_save.stage_completed.label }}: diff --git a/apps/wiki/urls.py b/apps/wiki/urls.py index 351ecbc8..f4da5f37 100644 --- a/apps/wiki/urls.py +++ b/apps/wiki/urls.py @@ -20,6 +20,9 @@ urlpatterns = patterns('wiki.views', url(r'^(?P[^/]+)/readonly$', 'editor_readonly', name="wiki_editor_readonly"), + url(r'^upload/$', + 'upload', name='wiki_upload'), + url(r'^create/(?P[^/]+)', 'create_missing', name='wiki_create_missing'), diff --git a/apps/wiki/views.py b/apps/wiki/views.py index b57347c2..7417235b 100644 --- a/apps/wiki/views.py +++ b/apps/wiki/views.py @@ -13,7 +13,7 @@ from wiki.helpers import (JSONResponse, JSONFormInvalid, JSONServerError, from django import http from wiki.models import getstorage, DocumentNotFound, normalize_name, split_name, join_name, Theme -from wiki.forms import DocumentTextSaveForm, DocumentTagForm, DocumentCreateForm +from wiki.forms import DocumentTextSaveForm, DocumentTagForm, DocumentCreateForm, DocumentsUploadForm from datetime import datetime from django.utils.encoding import smart_unicode from django.utils.translation import ugettext_lazy as _ @@ -126,7 +126,7 @@ def create_missing(request, name): form = DocumentCreateForm(request.POST, request.FILES) if form.is_valid(): doc = storage.create_document( - id=form.cleaned_data['id'], + name=form.cleaned_data['id'], text=form.cleaned_data['text'], ) @@ -143,6 +143,58 @@ def create_missing(request, name): }) +def upload(request): + storage = getstorage() + + if request.method == "POST": + form = DocumentsUploadForm(request.POST, request.FILES) + if form.is_valid(): + zip = form.cleaned_data['zip'] + skipped_list = [] + ok_list = [] + error_list = [] + titles = {} + existing = storage.all() + for filename in zip.namelist(): + if filename[-1] == '/': + continue + title = normalize_name(os.path.basename(filename)[:-4]) + if not (title and filename.endswith('.xml')): + skipped_list.append(filename) + elif title in titles: + error_list.append((filename, title, _('Title already used for %s' % titles[title]))) + elif title in existing: + error_list.append((filename, title, _('Title already used in repository.'))) + else: + ok_list.append((filename, title)) + titles[title] = filename + if not error_list: + for filename, title in ok_list: + storage.create_document( + name=title, + text=zip.read(filename) + ) + + return direct_to_template(request, "wiki/document_upload.html", extra_context={ + "form": form, + "ok_list": ok_list, + "skipped_list": skipped_list, + "error_list": error_list, + }) + #doc = storage.create_document( + # name=base, + # text=form.cleaned_data['text'], + + + return http.HttpResponse('\n'.join(yeslist) + '\n\n' + '\n'.join(nolist)) + else: + form = DocumentsUploadForm() + + return direct_to_template(request, "wiki/document_upload.html", extra_context={ + "form": form, + }) + + @never_cache @normalized_name def text(request, name): diff --git a/redakcja/static/css/filelist.css b/redakcja/static/css/filelist.css index b2f51ed2..2ccf33ec 100644 --- a/redakcja/static/css/filelist.css +++ b/redakcja/static/css/filelist.css @@ -70,3 +70,20 @@ a:hover { #loading-overlay { display: none; } + +.error { + color: red; + font-weight: bold; +} + +.success { + color: green; +} + +#error-list { + color: red; +} + +#skipped-list { + color: #666; +} \ No newline at end of file diff --git a/redakcja/static/js/wiki/view_column_diff.js b/redakcja/static/js/wiki/view_column_diff.js index a212f813..33ffb6a0 100644 --- a/redakcja/static/js/wiki/view_column_diff.js +++ b/redakcja/static/js/wiki/view_column_diff.js @@ -19,6 +19,7 @@ }; DiffPerspective.prototype.destroy = function() { + $.wiki.switchToTab('#HistoryPerspective'); $('#' + this.base_id).remove(); $('#' + this.perspective_id).remove(); };