remove to archive,
authorRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Wed, 26 Oct 2011 10:44:41 +0000 (12:44 +0200)
committerRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Wed, 26 Oct 2011 10:44:41 +0000 (12:44 +0200)
urlencode weird filenames

apps/archive/locale/pl/LC_MESSAGES/django.mo
apps/archive/locale/pl/LC_MESSAGES/django.po
apps/archive/templates/archive/file_managed.html
apps/archive/templates/archive/list_new.html
apps/archive/templates/archive/list_unmanaged.html
apps/archive/templatetags/tags.py
apps/archive/urls.py
apps/archive/views.py

index a851bda..7248dac 100644 (file)
Binary files a/apps/archive/locale/pl/LC_MESSAGES/django.mo and b/apps/archive/locale/pl/LC_MESSAGES/django.mo differ
index 0216929..3cdd29f 100644 (file)
@@ -7,8 +7,8 @@ msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: \n"
 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 <radoslaw.czajka@nowoczesnapolska.org.pl>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
 "Language: \n"
 "Last-Translator: Radek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
 "Language: \n"
@@ -136,6 +136,10 @@ msgstr "Uaktualnij tagi"
 msgid "Commit"
 msgstr "Zatwierdź"
 
 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"
 #: templates/archive/file_new.html:8
 msgid "Move to archive"
 msgstr "Przenieś do archiwum"
index 92ee639..d43c97e 100755 (executable)
@@ -94,5 +94,15 @@ Last modified: {{ audiobook.modified }}
 
 
 
 
 
 
+<hr />
+
+
+
+<form method="post" action="{% url remove_to_archive audiobook.id %}">
+    {% csrf_token %}
+    <input type="submit" value="{% trans "Remove to archive" %}" />
+</form>
+
+
 
 {% endblock %}
 
 {% endblock %}
index c837cfd..459593b 100644 (file)
@@ -16,7 +16,7 @@
 {% block file-list %}
     {% for file in objects %}
         <li>
 {% block file-list %}
     {% for file in objects %}
         <li>
-            <a href='{% url file_new file %}'>{{ file }}</a>
+            <a href='{% url file_new file|urlencode %}'>{{ file }}</a>
         </li>
     {% endfor %}
 {% endblock %}
         </li>
     {% endfor %}
 {% endblock %}
index 96e45d3..6b7486b 100755 (executable)
@@ -13,7 +13,7 @@
 {% block file-list %}
     {% for file in objects %}
         <li>
 {% block file-list %}
     {% for file in objects %}
         <li>
-            <a href='{% url file_unmanaged file %}'>{{ file }}</a>
+            <a href='{% url file_unmanaged file|urlencode %}'>{{ file }}</a>
         </li>
     {% endfor %}
 {% endblock %}
         </li>
     {% endfor %}
 {% endblock %}
index 25389ef..1067a4d 100755 (executable)
@@ -4,7 +4,13 @@ register = template.Library()
 
 @register.inclusion_tag('archive/tags/multiple_tags_table.html')
 def multiple_tags_table(tags, table=True):
 
 @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')
 
 
 @register.inclusion_tag('archive/tags/tags_table.html')
index 29552a2..3889949 100644 (file)
@@ -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'^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"),
 
     url(r'^unmanaged/$', 'archive.views.list_unmanaged', name="list_unmanaged"),
     url(r'^unmanaged/(.+)/$', 'archive.views.file_unmanaged', name="file_unmanaged"),
index 7a22232..59239d2 100644 (file)
@@ -95,6 +95,34 @@ def move_to_archive(request, filename):
     return redirect(list_new)
 
 
     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):
 @require_POST
 @permission_required('archive.change_audiobook')
 def move_to_new(request, filename):