summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Scheibenpflug <zorchenhimer@gmail.com>2015-06-16 22:05:31 (GMT)
committerNick Scheibenpflug <zorchenhimer@gmail.com>2015-06-16 22:05:31 (GMT)
commit3ef793c7183d67529dad8ea6345a16142d2c7a9a (patch)
treef1ea9488d71a0266a19e967beb1a0f571b3b1280
parentf2915f16101ce3b73f9539a7658648bde4cfe809 (diff)
downloadmanga-reader-3ef793c7183d67529dad8ea6345a16142d2c7a9a.zip
manga-reader-3ef793c7183d67529dad8ea6345a16142d2c7a9a.tar.gz
Added oneshot checkbox. Doesn't work, but it validates.
-rw-r--r--file_management/forms.py1
-rw-r--r--file_management/views.py10
2 files changed, 7 insertions, 4 deletions
diff --git a/file_management/forms.py b/file_management/forms.py
index d554cdb..6f0d7ff 100644
--- a/file_management/forms.py
+++ b/file_management/forms.py
@@ -2,6 +2,7 @@ from django import forms
2 2
3class UploadPackedManga(forms.Form): 3class UploadPackedManga(forms.Form):
4 packed_file = forms.FileField(label='File to upload') 4 packed_file = forms.FileField(label='File to upload')
5 oneshot = forms.BooleanField(label="Oneshot", initial=False, required=False)
5 6
6class EditOrphanedManga(forms.Form): 7class EditOrphanedManga(forms.Form):
7 orphan_id = forms.HiddenInput() 8 orphan_id = forms.HiddenInput()
diff --git a/file_management/views.py b/file_management/views.py
index 1a15edf..8557e2a 100644
--- a/file_management/views.py
+++ b/file_management/views.py
@@ -27,15 +27,16 @@ def upload_file(request):
27 form = UploadPackedManga(request.POST, request.FILES) 27 form = UploadPackedManga(request.POST, request.FILES)
28 28
29 if form.is_valid(): 29 if form.is_valid():
30 manga_id = handle_upload(request.FILES['packed_file']) 30 manga_id = handle_upload(form.cleaned_data)
31 return HttpResponseRedirect(reverse('management:edit_orphan', kwargs={'oid':manga_id})) 31 return HttpResponseRedirect(reverse('management:edit_orphan', kwargs={'oid':manga_id}))
32 else: 32 else:
33 return HttpResponse('Invalid upload form!') 33 return HttpResponse('Invalid upload form!\n{}'.format(form.errors))
34 else: 34 else:
35 form = UploadPackedManga() 35 form = UploadPackedManga()
36 return render(request, 'file_management/upload_form.html', {'upload_form': form}) 36 return render(request, 'file_management/upload_form.html', {'upload_form': form})
37 37
38def handle_upload(uploaded_file): 38def handle_upload(form_data):
39 uploaded_file = form_data['packed_file']
39 #stamp = timezone.now().timestamp() 40 #stamp = timezone.now().timestamp()
40 stamp = int(time.time()) 41 stamp = int(time.time())
41 zip_name = os.path.join('tmp', str(stamp)) 42 zip_name = os.path.join('tmp', str(stamp))
@@ -49,8 +50,9 @@ def handle_upload(uploaded_file):
49 zf.close() 50 zf.close()
50 51
51 extracted_list = os.listdir(extracted_dir) 52 extracted_list = os.listdir(extracted_dir)
53 print('[handle_upload] form_data: {}'.format(form_data))
52 54
53 if len(extracted_list) == 1: 55 if len(extracted_list) == 1 and form_data['oneshot'] == False:
54 # One subdirectory, move everything up one level 56 # One subdirectory, move everything up one level
55 for file in os.listdir( os.path.join( extracted_dir, extracted_list[0]) ): 57 for file in os.listdir( os.path.join( extracted_dir, extracted_list[0]) ):
56 os.rename( os.path.join( extracted_dir, extracted_list[0], file), os.path.join(extracted_dir, file) ) 58 os.rename( os.path.join( extracted_dir, extracted_list[0], file), os.path.join(extracted_dir, file) )