summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Scheibenpflug <zorchenhimer@gmail.com>2015-06-18 02:25:06 (GMT)
committerNick Scheibenpflug <zorchenhimer@gmail.com>2015-06-18 02:25:06 (GMT)
commit32e0f117ae87ce98725c8f003f1e2aedb12ee87d (patch)
tree6e52733ba9f636a6834eadadd13aa17922f5e875
parent07fe15f85f0221d984e9a434a99970a7ff1042e2 (diff)
downloadmanga-reader-32e0f117ae87ce98725c8f003f1e2aedb12ee87d.zip
manga-reader-32e0f117ae87ce98725c8f003f1e2aedb12ee87d.tar.gz
Move orphans to chapter folder inside manga folder, instead of just the manga folder.
-rw-r--r--file_management/views.py34
1 files changed, 25 insertions, 9 deletions
diff --git a/file_management/views.py b/file_management/views.py
index 27c7c60..dff54bd 100644
--- a/file_management/views.py
+++ b/file_management/views.py
@@ -72,11 +72,15 @@ def edit_orphan(request, oid):
72 form = EditOrphanedManga(request.POST) 72 form = EditOrphanedManga(request.POST)
73 73
74 if form.is_valid(): 74 if form.is_valid():
75 manga = Manga.objects.create( 75 manga = None
76 full_name=form['manga_name'].value(), 76 if Manga.objects.filter(system_name=form['system_name'].value()).exists():
77 system_name=form['system_name'].value(), 77 manga = Manga.objects.get(system_name=form['system_name'].value())
78 oneshot = form['oneshot'].value() 78 else:
79 ) 79 manga = Manga.objects.create(
80 full_name=form['manga_name'].value(),
81 system_name=form['system_name'].value(),
82 oneshot = form['oneshot'].value()
83 )
80 move_orphan(oid, manga.id) 84 move_orphan(oid, manga.id)
81 #return HttpResponse('Given name: {n}<br />System: {s}'.format(n=form['manga_name'].value(), s=form['system_name'].value())) 85 #return HttpResponse('Given name: {n}<br />System: {s}'.format(n=form['manga_name'].value(), s=form['system_name'].value()))
82 return HttpResponseRedirect(reverse('management:edit', kwargs={'mid': manga.id})) 86 return HttpResponseRedirect(reverse('management:edit', kwargs={'mid': manga.id}))
@@ -106,20 +110,32 @@ def move_orphan(oid, mid):
106 orphan = get_object_or_404(UploadedOrphan, pk=oid) 110 orphan = get_object_or_404(UploadedOrphan, pk=oid)
107 manga = get_object_or_404(Manga, pk=mid) 111 manga = get_object_or_404(Manga, pk=mid)
108 112
109 ## This needs the trailing slash. 113 ## Manga root directory.
114 # This needs the trailing slash.
110 new_directory = os.path.join(manga.system_name[0:1], manga.system_name[1:2], manga.system_name, "") 115 new_directory = os.path.join(manga.system_name[0:1], manga.system_name[1:2], manga.system_name, "")
111 os.makedirs(os.path.join('manga_data', new_directory), exist_ok=True) 116 os.makedirs(os.path.join('manga_data', new_directory), exist_ok=True)
112 117
118 chapter_list = Chapter.objects.filter(manga=manga)
119 highest_chapter = -1.0
120
121 for c in chapter_list:
122 if c.number > highest_chapter:
123 highest_chatper = c.number
124
125 chapter_number = highest_chapter + 1
126 chapter_directory = os.path.join(new_directory, str(chapter_number), "")
127
113 chapter = Chapter.objects.create( 128 chapter = Chapter.objects.create(
114 number=0, 129 number=chapter_number,
115 directory=new_directory, 130 directory=chapter_directory,
116 manga=manga, 131 manga=manga,
117 ) 132 )
118 133
119 orphan_dir = os.path.join( 'tmp', '{n}_extracted'.format(n=orphan.filename)) 134 orphan_dir = os.path.join( 'tmp', '{n}_extracted'.format(n=orphan.filename))
120 for f in os.listdir(orphan_dir): 135 for f in os.listdir(orphan_dir):
121 os.rename( os.path.join(orphan_dir, f), os.path.join('manga_data', new_directory, f) ) 136 os.rename( os.path.join(orphan_dir, f), os.path.join('manga_data', chapter_directory) )
122 137
123 ## Remove orphan files. 138 ## Remove orphan files.
124 rmtree(orphan_dir) 139 rmtree(orphan_dir)
125 os.remove(os.path.join('tmp', orphan.filename)) 140 os.remove(os.path.join('tmp', orphan.filename))
141 orphan.delete()