From d4ae69daba9be2dc07e2ec064cffde51b82a9937 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Wed, 26 Oct 2011 12:44:41 +0200 Subject: [PATCH 1/1] remove to archive, urlencode weird filenames --- apps/archive/locale/pl/LC_MESSAGES/django.mo | Bin 2404 -> 2480 bytes apps/archive/locale/pl/LC_MESSAGES/django.po | 8 +++-- .../templates/archive/file_managed.html | 10 +++++++ apps/archive/templates/archive/list_new.html | 2 +- .../templates/archive/list_unmanaged.html | 2 +- apps/archive/templatetags/tags.py | 8 ++++- apps/archive/urls.py | 1 + apps/archive/views.py | 28 ++++++++++++++++++ 8 files changed, 54 insertions(+), 5 deletions(-) diff --git a/apps/archive/locale/pl/LC_MESSAGES/django.mo b/apps/archive/locale/pl/LC_MESSAGES/django.mo index a851bda9c55d942c92821abdd590fd34484ab6d3..7248dac5afa105aa9464cea109db1356ba3aa5a9 100644 GIT binary patch delta 1000 zcmZA0JxH5D9LMoXOq$r%m&E#7jgK~JEn=+(5sSEqcB|+h8LT#eS`nqb4w8Tru}d9P z)TuhTI7kC-862dm;wZRSp_C4lA~^c}r6-6-?)f}-&pr3Q`#+bT!M%dyS@x->b(duBx$<1 z$))2BYJve&z+ueBkEp;?_z=Hf5LdAjcTf`^px!&Np4$F%d_?~h7NLt(sa=9T;+rrx z+Cc*k%s8DdyuPYP_4-6)=Pf)W}7dY_si7RG=Qr!9L_wGmKjBXg2xR zg9$pc!-O5MhzhifnsCeZ?;x4X>_REj7@eIusuo^LRncyBeru@OphML{pHo$oZJmXB zeShuje$ff8zSmi4+pNKqP_?rPsur$)4xcyk{R>e45KgxVQy_Q R;b$jihtE!rt<3rV+yG?4Qse*t delta 923 zcmXxjJ1j&&6vpwh_F=si>;2qa@2KpG!X_FN3Q_40QRpP-Y_$a~A}Aypg+e2eO*9e- zi70fa6{12yh=_#5|GUOyXMS_%&dfRHj-!f)X!b4|*fvTRwUIjMGwZ|MJQ~V^-z*;& zu@W;_k840hcQZgo28=#OQ?X$Zo(?^vqR@GR`Gm_ z4S0)6>=kviAE-b<8toIoVywj)Y)8czK%M9aX0_3jdy#RjpaQL98SbOz9iswWqXOKc zzU{Mnen$oP!4eEJiLORlxacLYe^u8bWP2jvAjpPSDz^TG&L@Jl#zt zsKO=kl4?b*Rie5d3K*yA+pFj=)&-C0fuc_qwt27bHOfdAr<2;|jr=tU*KfuSs*d!( z@M*1u+T{jnv4Tq8-bv`#RrDXDOJ0}T@b~y~H-RQ!eos8vn@;v`eg+eN{ZuL!3vK0X IUWA{10cRLOPXGV_ diff --git a/apps/archive/locale/pl/LC_MESSAGES/django.po b/apps/archive/locale/pl/LC_MESSAGES/django.po index 0216929..3cdd29f 100644 --- a/apps/archive/locale/pl/LC_MESSAGES/django.po +++ b/apps/archive/locale/pl/LC_MESSAGES/django.po @@ -7,8 +7,8 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2011-10-20 13:19+0200\n" -"PO-Revision-Date: 2011-10-20 13:22+0100\n" +"POT-Creation-Date: 2011-10-26 12:43+0200\n" +"PO-Revision-Date: 2011-10-26 12:44+0100\n" "Last-Translator: Radek Czajka \n" "Language-Team: LANGUAGE \n" "Language: \n" @@ -136,6 +136,10 @@ msgstr "Uaktualnij tagi" msgid "Commit" msgstr "Zatwierdź" +#: templates/archive/file_managed.html:103 +msgid "Remove to archive" +msgstr "Usuń do archiwum" + #: templates/archive/file_new.html:8 msgid "Move to archive" msgstr "Przenieś do archiwum" diff --git a/apps/archive/templates/archive/file_managed.html b/apps/archive/templates/archive/file_managed.html index 92ee639..d43c97e 100755 --- a/apps/archive/templates/archive/file_managed.html +++ b/apps/archive/templates/archive/file_managed.html @@ -94,5 +94,15 @@ Last modified: {{ audiobook.modified }} +
+ + + +
+ {% csrf_token %} + +
+ + {% endblock %} diff --git a/apps/archive/templates/archive/list_new.html b/apps/archive/templates/archive/list_new.html index c837cfd..459593b 100644 --- a/apps/archive/templates/archive/list_new.html +++ b/apps/archive/templates/archive/list_new.html @@ -16,7 +16,7 @@ {% block file-list %} {% for file in objects %}
  • - {{ file }} + {{ file }}
  • {% endfor %} {% endblock %} diff --git a/apps/archive/templates/archive/list_unmanaged.html b/apps/archive/templates/archive/list_unmanaged.html index 96e45d3..6b7486b 100755 --- a/apps/archive/templates/archive/list_unmanaged.html +++ b/apps/archive/templates/archive/list_unmanaged.html @@ -13,7 +13,7 @@ {% block file-list %} {% for file in objects %}
  • - {{ file }} + {{ file }}
  • {% endfor %} {% endblock %} diff --git a/apps/archive/templatetags/tags.py b/apps/archive/templatetags/tags.py index 25389ef..1067a4d 100755 --- a/apps/archive/templatetags/tags.py +++ b/apps/archive/templatetags/tags.py @@ -4,7 +4,13 @@ register = template.Library() @register.inclusion_tag('archive/tags/multiple_tags_table.html') def multiple_tags_table(tags, table=True): - return locals() + new_tags = {} + for k, v in tags.items(): + if isinstance(v, list): + new_tags[k] = v + else: + new_tags[k] = [v] + return {"tags": new_tags, "table": table} @register.inclusion_tag('archive/tags/tags_table.html') diff --git a/apps/archive/urls.py b/apps/archive/urls.py index 29552a2..3889949 100644 --- a/apps/archive/urls.py +++ b/apps/archive/urls.py @@ -13,6 +13,7 @@ urlpatterns = patterns('', url(r'^file/(\d+)/$', 'archive.views.file_managed', name="file"), url(r'^publish/(\d+)/$', 'archive.views.publish', name="publish"), url(r'^cancel/(\d+)/$', 'archive.views.cancel_publishing', name="cancel_publishing"), + url(r'^remove_to_archive/(\d+)/$', 'archive.views.remove_to_archive', name="remove_to_archive"), url(r'^unmanaged/$', 'archive.views.list_unmanaged', name="list_unmanaged"), url(r'^unmanaged/(.+)/$', 'archive.views.file_unmanaged', name="file_unmanaged"), diff --git a/apps/archive/views.py b/apps/archive/views.py index 7a22232..59239d2 100644 --- a/apps/archive/views.py +++ b/apps/archive/views.py @@ -95,6 +95,34 @@ def move_to_archive(request, filename): return redirect(list_new) +@require_POST +@permission_required('archive.change_audiobook') +def remove_to_archive(request, aid): + """ move a managed file to the unmanaged files dir """ + + audiobook = get_object_or_404(models.Audiobook, id=aid) + old_path = audiobook.source_file.path + new_path = os.path.join(settings.UNMANAGED_PATH, + str(audiobook.source_file)[len(settings.FILES_SAVE_PATH):].lstrip('/')) + new_dir = os.path.split(new_path)[0] + if not os.path.isdir(new_dir): + os.makedirs(new_dir) + + if not os.path.isfile(old_path): + raise Http404 + + try: + os.link(old_path, new_path) + except OSError: + # destination file exists, don't overwrite it + # TODO: this should probably be more informative + return redirect(file_new, filename) + else: + os.unlink(old_path) + audiobook.delete() + + return redirect(list_unmanaged) + @require_POST @permission_required('archive.change_audiobook') def move_to_new(request, filename): -- 2.20.1