コード例 #1
0
ファイル: views.py プロジェクト: stden/bonushouse
def view(request, offer_id):
    offer_id = int(offer_id)
    offer = get_object_or_404(Offers.all_objects, pk=offer_id)
    context = RequestContext(request)
    if offer.partner.admin_user == request.user:
        can_write_replies = True
    else:
        can_write_replies = False
    context['can_write_replies'] = can_write_replies
    context['offer'] = offer
    if request.method == 'POST':
        feedback_form = FeedbacksForm(request.POST)
        if (request.user.is_staff or can_write_replies) and request.POST.get('admin-reply'):
            admin_reply = request.POST.get('admin_reply')
            feedback_id = request.POST.get('feedback_id')
            if feedback_id:
                try:
                    feedback_id = int(feedback_id)
                    feedback = UserFeedbacks.objects.get(pk=feedback_id)
                    if not request.user.is_staff and feedback.content_object.partner.admin_user != request.user:
                        raise Http404
                    feedback.admin_reply = admin_reply
                    feedback.save()
                    return redirect(offer.get_url())
                except:
                    pass
        else:
            if feedback_form.is_valid():
                feedback_form.instance.content_object = offer
                feedback_form.instance.user = request.user
                feedback_form.save()
                rating = UserRatings(content_object=feedback_form.instance, user=request.user, rating=feedback_form.cleaned_data['rating'])
                rating.save()
                messages.info(request, 'Спасибо! Ваш отзыв отправлен на проверку администрации.')
                return redirect(offer.get_url())
    else:
        feedback_form = FeedbacksForm()
    context['feedback_form'] = feedback_form
    update_last_viewed_offers(request, offer)
    offer.views_count += 1
    offer.save()
    if offer.get_seo_meta_object():
        seo_meta = offer.get_seo_meta_object()
        context['META_TITLE'] = seo_meta.meta_title
        context['META_KEYWORDS'] = seo_meta.meta_keywords
        context['META_DESCRIPTION'] = seo_meta.meta_description
    return render_to_response('offers/view.html', context)
コード例 #2
0
ファイル: views.py プロジェクト: stden/bonushouse
def partner_page(request, partner_id):
    context = RequestContext(request)
    partner = get_object_or_404(Partner, pk=partner_id)
    if partner.admin_user == request.user:
        can_write_replies = True
    else:
        can_write_replies = False
    context['can_write_replies'] = can_write_replies
    context['partner'] = partner
    if request.method == 'POST':
        if (request.user.is_staff or can_write_replies) and request.POST.get('admin-reply'):
            feedback_form = FeedbacksForm()
            admin_reply = request.POST.get('admin_reply')
            feedback_id = request.POST.get('feedback_id')
            if feedback_id:
                try:
                    feedback_id = int(feedback_id)
                    feedback = UserFeedbacks.objects.get(pk=feedback_id)
                    if not request.user.is_staff and feedback.content_object.admin_user != request.user:
                        raise Http404
                    feedback.admin_reply = admin_reply
                    feedback.save()
                    return redirect(partner.get_url())
                except:
                    pass
        else:
            feedback_form = FeedbacksForm(request.POST)
            if feedback_form.is_valid():
                feedback_form.instance.content_object = partner
                feedback_form.instance.user = request.user
                feedback_form.save()
                rating = UserRatings(content_object=feedback_form.instance, user=request.user, rating=feedback_form.cleaned_data['rating'])
                rating.save()
                messages.info(request, 'Спасибо! Ваш отзыв отправлен на проверку администрации.')
                return redirect(partner.get_url())
    else:
        feedback_form  = FeedbacksForm()
    context['feedback_form'] = feedback_form
    return render_to_response('partners/partner_page.html', context)