def _process_ratings(request): data = request.POST try: referer = request.META['HTTP_REFERER'] except: referer = '' if urls['WISHLIST'] in referer: revert = 'wishlist' elif urls['SHITLIST'] in referer: revert = 'shitlist' elif urls['OWNED'] in referer: revert = 'collection' else: revert = 'main_page' if not data: data = request.session.get('rating_data') logger.info("RATING DATA FROM SESSION: %r", data) del request.session['rating_data'] if data: form_prefixes = FilmRatingForm.get_form_prefixes(data) for prefix in form_prefixes: film_id = prefix[4:] film = get_object_or_404(Film, id=film_id) form = FilmRatingForm(data, film=film, user=request.user) if form.is_valid(): form.save() next = data and data.get('next') return next and HttpResponseRedirect(next) or HttpResponseRedirect(reverse(revert))
def process_ratings(request): data = request.POST if not data: data = request.session.get('rating_data') logger.info("RATING DATA FROM SESSION: %r", data) if data: del request.session['rating_data'] if data: form_prefixes = FilmRatingForm.get_form_prefixes(data) for prefix in form_prefixes: film_id = prefix[4:] film = get_object_or_404(Film, id=film_id) form = FilmRatingForm(data, request, film) if form.is_valid(): form.save() form_prefixes = SingleRatingForm.get_form_prefixes(data) for prefix in form_prefixes: form = SingleRatingForm(data, request, prefix=prefix) if form.is_valid(): form.save() else: errors = form.errors assert 0 next = data and data.get('next') if not next: if request.is_ajax(): return HttpResponse('ok') try: referer = request.META['HTTP_REFERER'] except: referer = '' if urls['WISHLIST'] in referer: next = reverse('wishlist') elif urls['SHITLIST'] in referer: next = reverse('shitlist') elif urls['OWNED'] in referer: next = reverse('collection') elif referer: next = referer else: next = reverse('main_page') return HttpResponseRedirect(next)
def film_ratings_form(context, film, edit=False): request = context.get('request') form = FilmRatingForm(None, request, film, edit=edit) return { 'film': film, 'form': form, 'request': request, }