def add_review(request, bbl=None): lot = get_object_or_404(Lot, bbl=bbl) if request.method == 'POST': form = ReviewForm(request.POST) if form.is_valid(): form.save() return redirect('lots.views.details', bbl=bbl) else: initial_data = { 'reviewer': request.user, 'lot': lot, 'in_use': not lot.is_vacant, 'actual_use': lot.actual_use, } reviews = Review.objects.filter(lot=lot).order_by('-added') fields = ('in_use', 'actual_use', 'accessible', 'needs_further_review', 'nearby_lots', 'hpd_plans', 'hpd_plans_details') if reviews: last_review = reviews[0] for field in fields: initial_data[field] = last_review.__dict__[field] form = ReviewForm(initial=initial_data) return render_to_response('lots/add_review.html', { 'form': form, 'lot': lot, }, context_instance=RequestContext(request))
def add_review(request, bbl=None): lot = get_object_or_404(Lot, bbl=bbl) if request.method == 'POST': form = ReviewForm(request.POST) if form.is_valid(): form.save() return redirect('lots.views.details', bbl=bbl) else: initial_data = { 'reviewer': request.user, 'lot': lot, 'in_use': not lot.is_vacant, 'actual_use': lot.actual_use, } reviews = Review.objects.filter(lot=lot).order_by('-added') fields = ('in_use', 'actual_use', 'accessible', 'needs_further_review', 'nearby_lots', 'hpd_plans', 'hpd_plans_details') if reviews: last_review = reviews[0] for field in fields: initial_data[field] = last_review.__dict__[field] form = ReviewForm(initial=initial_data) return render_to_response('lots/add_review.html', { 'form': form, 'lot': lot, }, context_instance=RequestContext(request))
def adicionar(request): form = ReviewForm() if request.method == 'POST': form = ReviewForm(request.POST) if form.is_valid(): review = Review(user = request.user) form = ReviewForm(request.POST, instance=review) form.save() return redirect('/review/') return render(request, 'review/adicionar.html', locals())
def show_book(request, id_book): authenticated = False if request.user.is_authenticated(): authenticated = True book = Book.objects.get(id_book=id_book) if request.method == 'POST': review_form = ReviewForm(request.POST) if review_form.is_valid(): new_review = review_form.save(commit=False) new_review.book = book new_review.user = request.user new_review.save() # TODO: Get reviews by ISBN not by book reviews = Review.objects.filter(book=book) review_form = ReviewForm() if len(reviews): rating = round(sum([float(review.rating) for review in reviews]) / len(reviews), 2) else: rating = "No reviews yet" return render_to_response("book.html", context_instance=RequestContext(request, {'authenticated': authenticated, 'book': book, 'reviews': reviews, 'review_form': review_form, 'rating': rating}))
def show_book(request, id_book): authenticated = False if request.user.is_authenticated(): authenticated = True book = Book.objects.get(id_book=id_book) if request.method == 'POST': review_form = ReviewForm(request.POST) if review_form.is_valid(): new_review = review_form.save(commit=False) new_review.book = book new_review.user = request.user new_review.save() # TODO: Get reviews by ISBN not by book reviews = Review.objects.filter(book=book) review_form = ReviewForm() if len(reviews): rating = round( sum([float(review.rating) for review in reviews]) / len(reviews), 2) else: rating = "No reviews yet" return render_to_response("book.html", context_instance=RequestContext( request, { 'authenticated': authenticated, 'book': book, 'reviews': reviews, 'review_form': review_form, 'rating': rating }))
def single_product(request, slug): product = get_object_or_404(Product, slug=slug) prod = Product.objects.get(slug=slug) reviews = Review.objects.get(product=prod.id) reviewmatrix = {} user = request.user i = 0 try: for rev in reviews: reviewmatrix[str(i)] = [[review.review_text]] u = User.objects.get(username=rev.user) i = i + 1 except: u = User.objects.get(username=reviews.user) reviewmatrix[str(i)] = [[reviews.review_text]] if request.method=="POST": form = ReviewForm(request.POST) if form.is_valid(): user2 = get_object_or_404(User, pk=user.id) response = form.save(user=user2.id, product=prod.id) msg = 'Obrigado por avaliar ' + prod.name else: msg = 'Houve algum erro no servidor :(' return render(request, 'product_detail.html', {'prod':prod, 'reviews':reviews, 'user':u.first_name, 'msg':msg}) else: form = ReviewForm() args = {} args.update(csrf(request)) return render(request, 'product_detail.html', {'prod':prod, 'reviews':reviews, 'user':u.first_name, 'form':form})
def create_review(request, series_id): if request.POST: form = ReviewForm(request.POST, series_id) if form.is_valid(): form.save() return HttpResponseRedirect('/genre/all/') #stuck this here, trying to get past it else: form = ReviewForm() args = {} args.update(csrf(request)) args['form'] = form args['series_id'] = series_id return render_to_response('create_review.html', args)
def add_review(request, id): product = get_object_or_404(models.Product, pk=id) form = ReviewForm(request.POST) if form.is_valid(): review_text = form.cleaned_data['review_text'] review = form.save(commit=False) review.review_text = review_text review.user = request.user review.product = product review.date_published = timezone.now() review.save() return HttpResponseRedirect(reverse('details', args=(product.id,))) else: form = ReviewForm() return render(request, 'store/product-details.html', {'product': product, 'form': form}) return render(request, 'store/')
def review(request): import ep2Site.models plugin = ep2Site.plugins.reviewType.get_plugin(plugin) if request.method == 'POST': form = ReviewForm(request.POST) if form.is_valid(): review = form.save(commit=False) review.plugin = plugin.get_model() review.save() return HttpResponseRedirect(review.get_absolute_url()) else: return "[ERROR] from views: {0}".format(form.errors) else: form = ep2Site.forms.ReviewForm() return render_to_response('ep2Site/review.html', {'form': form}, context_instance=RequestContext(request))
def add_review(request, id): product = get_object_or_404(models.Product, pk=id) form = ReviewForm(request.POST) if form.is_valid(): review_text = form.cleaned_data['review_text'] review = form.save(commit=False) review.review_text = review_text review.user = request.user review.product = product review.date_published = timezone.now() review.save() return HttpResponseRedirect(reverse('details', args=(product.id, ))) else: form = ReviewForm() return render(request, 'store/product-details.html', { 'product': product, 'form': form }) return render(request, 'store/')
def add_review(request, movie_id): rm = Movie.objects.get(id=movie_id) if request.method == "POST": f = ReviewForm(request.POST) if f.is_valid(): r = f.save(commit=False) r.user = request.session['user'] r.post_date = timezone.now() r.movie = rm r.save() return HttpResponseRedirect('/movies/get/%s' % movie_id) else: f = ReviewForm() args = {} args.update(csrf(request)) args['movie'] = rm args['form'] = f if 'user' in request.session: args['result'] = request.session['user'] return render_to_response('add_review.html', args)
def add_review(request,movie_id): rm=Movie.objects.get(id=movie_id) if request.method == "POST": f=ReviewForm(request.POST) if f.is_valid(): r=f.save(commit=False) r.user=request.session['user'] r.post_date = timezone.now() r.movie =rm r.save() return HttpResponseRedirect('/movies/get/%s' % movie_id) else: f=ReviewForm() args={} args.update(csrf(request)) args['movie']=rm args['form']=f; if 'user' in request.session: args['result']=request.session['user'] return render_to_response('add_review.html',args)
def create_review(request, template="create_project.html"): project_id = request.GET.get("project_id") print "create application review for project:{}".format(project_id) project = None if project_id is not None: project = get_object_or_404(Project, pk=project_id) if request.method == "POST": # Must pass request.FILES to ModelForm so it can handle file upload form = ReviewForm(request.POST, request.FILES, initial={"project": project}) new_review = form.save() print new_review if project_id is None: project_id = new_review.project.id event = {"time": datetime.now(), "project_id": int(project_id), "message": _("Create ApplicationReview")} create_log(event) return redirect("enterprise.reviews") else: form = ReviewForm(initial={"project": project}) context = {"form": form, "title": _("Create ApplicationReview")} return render(request, template, context)