def moveright_page(request): user = request.user if user.is_authenticated(): page_id = request.POST['page_id'] page = Page.objects.get(id=page_id) pages = Page.objects.filter(album=page.album) if page.number < len(pages): try: number = page.number + 1 page_left = Page.objects.get(album=page.album, number=number) page_tmp = page page_left_tmp = page_left page_b = Page(album=page_tmp.album, name=page_tmp.name, layout=page_tmp.layout, number=page_left_tmp.number) page_a = Page(album=page_tmp.album, name=page_left_tmp.name, layout=page_left_tmp.layout, number=page_tmp.number) page_b.save() page_a.save() pic_p_left = Picture.objects.filter( page=page_left).order_by('number') pic_p = Picture.objects.filter(page=page).order_by('number') for pic in pic_p_left: pic.page = page_a pic.save() for pic in pic_p: pic.page = page_b pic.save() page.delete() page_left.delete() pictures = Picture.objects.filter( page=page_b).order_by('number') url = "album/" + str(page_b.layout) + ".html" album = Album.objects.get(id=page_b.album.id) album_pages = Page.objects.filter( album=album).order_by('number') data = { 'id': page_b.id, 'number': page_b.number, 'name': page_b.name, 'layout': page_b.layout, 'album_id': page_b.album, 'album_pages': album_pages } data['pictures'] = pictures return render(request, url, data) except Page.DoesNotExist: return render(request, "album/album.html") return (request, "album/album.html") else: return redirect('/')
def index(request): #print("home index") albums = [] thumbnails = [] user = request.user #print("user: "******"", number="1", layout="") picture = Picture(page=page, number=0, url="", caption="", price=0) thumbnails.append(picture) registration_form = RegistrationForm() album_and_thumbs = zip(albums, thumbnails) return render( request, 'home/index.html', { 'registration_form': registration_form, 'album_and_thumbs': album_and_thumbs })
def create_page(request): if request.method == 'POST': user = request.user if user.is_authenticated(): layout = request.POST['layout'] album_id = request.POST['album_id'] url = request.POST['url'] page_name = request.POST['page_name'] try: album = Album.objects.get(id=album_id) except Album.DoesNotExist: album = None if album != None: #all pages for the first time album_pages = album.page_set.all().order_by('number') page = Page(number=(len(album_pages) + 1), name=page_name, layout=layout, album=album) page.save() layout_num = int(layout[len(layout) - 1]) for i in range(layout_num): picture = Picture(page=page, number=i + 1, url=url, caption="", price=0) picture.save() if layout_num == 3 and i == 1: break #add first page idx to album field if album.firstpage == 0: album.firstpage = page.id album.save() #all pages after saving to database album_pages = album.page_set.all().order_by('number') page = { 'id': page.id, 'number': page.number, 'name': page.name, 'layout': page.layout, 'album_id': album_id, 'album_pages': album_pages } url = "album/" + layout + ".html" return render(request, url, page) else: return redirect('/')