def show_page_numbers(request): # Make a displayable dict of everything. pagedata = [] for ed, edname in EDITIONS: voldata = [] for book, bookname in BOOKS: voldata.append((bookname, [(page, map_position(ed, book, page)) for page in PAGE_NUMS[ed][book]['pages']])) pagedata.append((edname, voldata)) return render(request, 'cards/pagenumbers.html', { 'pagedata': pagedata, })
def settings(request): if request.method == 'POST': # If the form has been submitted... form = PositionForm(request.POST) # A form bound to the POST data if form.is_valid(): # All validation rules pass # Process the data in form.cleaned_data # ... request.session['edition'] = form.cleaned_data['edition'] request.session['book'] = form.cleaned_data['book'] request.session['page'] = form.cleaned_data['page'] request.session['pos'] = map_position(form.cleaned_data['edition'], form.cleaned_data['book'], form.cleaned_data['page']) return HttpResponseRedirect('/') # Redirect after POST else: default_data = { 'book': request.session.get('book'), 'page': request.session.get('page') } form = PositionForm(default_data) # An unbound form return render(request, 'cards/settings.html', { 'form': form, })