local changes from server
[audio.git] / apps / archive / views.py
index e76da74..b5850a0 100644 (file)
@@ -7,7 +7,7 @@ from urllib import quote
 
 from archive import settings
 from django.contrib.auth import logout
-from django.contrib.auth.decorators import login_required, permission_required
+from django.contrib.auth.decorators import permission_required
 from django.core.urlresolvers import reverse
 from django.db.models import Q, Max
 from django.http import Http404, HttpResponse
@@ -23,7 +23,6 @@ from archive import tasks
 from archive.utils import all_files
 
 
-@login_required
 def list_new(request):
     division = 'new'
 
@@ -112,15 +111,22 @@ def remove_to_archive(request, aid):
     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()
+    success = False
+    try_new_path = new_path
+    try_number = 0
+    while not success:
+        try:
+            os.link(old_path, try_new_path)
+        except OSError:
+            # destination file exists, don't overwrite it
+            try_number += 1
+            parts = new_path.rsplit('.', 1)
+            parts[0] += '_%d' % try_number
+            try_new_path = ".".join(parts)
+        else:
+            os.unlink(old_path)
+            audiobook.delete()
+            success = True
 
     return redirect(list_unmanaged)
 
@@ -200,7 +206,6 @@ def download(request, aid, which="source"):
     return response
 
 
-@login_required
 def list_unpublished(request):
     division = 'unpublished'
 
@@ -208,7 +213,6 @@ def list_unpublished(request):
     return render(request, "archive/list_unpublished.html", locals())
 
 
-@login_required
 def list_publishing(request):
     division = 'publishing'
 
@@ -226,7 +230,6 @@ def list_publishing(request):
     return render(request, "archive/list_publishing.html", locals())
 
 
-@login_required
 def list_published(request):
     division = 'published'
 
@@ -250,7 +253,7 @@ def file_managed(request, id):
     path = audiobook.source_file.path[len(settings.FILES_PATH):].lstrip('/')
 
     # for tags update
-    tags = mutagen.File(audiobook.source_file.path)
+    tags = mutagen.File(audiobook.source_file.path.encode('utf-8'))
     if not tags:
         tags = {}
     form = AudiobookForm(instance=audiobook)
@@ -258,7 +261,6 @@ def file_managed(request, id):
     return render(request, "archive/file_managed.html", locals())
 
 
-@login_required
 def list_unmanaged(request):
     division = 'unmanaged'
 
@@ -266,7 +268,6 @@ def list_unmanaged(request):
     return render(request, "archive/list_unmanaged.html", locals())
 
 
-@login_required
 def file_unmanaged(request, filename):
     division = 'unmanaged'