Exemple #1
0
def menu_offers_add(request):
    context = RequestContext(request)
    context = load_menu_context(context)
    context['ADMIN_MENU_ACTIVE'] = 'Акции'
    if request.method == 'POST':
        offers_form = OffersForm(request.POST, partner_user=request.user)
        seo_meta_form = SeoModelMetaForm(request.POST)
        seo_url_form = SeoModelUrlForm(request.POST)
        if offers_form.is_valid() and seo_meta_form.is_valid() and seo_url_form.is_valid():
            offers_form.instance.type = 1
            instance = offers_form.save()
            instance.is_published = False
            instance.save()
            seo_meta_form.instance.content_object = offers_form.instance
            seo_meta_form.save()
            seo_url_form.instance.content_object = offers_form.instance
            seo_url_form.save()
            return redirect('partners.views.menu_offers_index')
    else:
        offers_form = OffersForm(partner_user=request.user)
        seo_meta_form = SeoModelMetaForm()
        seo_url_form = SeoModelUrlForm()
    context['offers_form'] = offers_form
    context['seo_meta_form'] = seo_meta_form
    context['seo_url_form'] = seo_url_form
    context['page_title'] = 'Добавить акцию'
    return render_to_response('partners/menu/offers/form.html', context)
Exemple #2
0
def menu_offers_edit(request, offer_id):
    offer_id = int(offer_id)
    offer = get_object_or_404(Offers.all_objects, pk=offer_id, partner__admin_user=request.user)
    context = RequestContext(request)
    context = load_menu_context(context)
    context['ADMIN_MENU_ACTIVE'] = 'Акции'
    if request.method == 'POST':
        offers_form = OffersForm(request.POST, request.FILES, instance=offer, partner_user=request.user)
        seo_meta_form = SeoModelMetaForm(request.POST, instance=offer.get_seo_meta_object())
        seo_url_form = SeoModelUrlForm(request.POST, instance=offer.get_seo_url_object())
        if request.POST.get('delete') is not None:
            offer.delete()
            return redirect('partners.views.menu_offers_index')
        else:
            if offers_form.is_valid() and seo_meta_form.is_valid() and seo_url_form.is_valid():
                offers_form.instance.type = 1
                instance = offers_form.save()
                instance.is_published = False
                instance.save()
                seo_meta_form.save()
                seo_url_form.save()
                return redirect('partners.views.menu_offers_index')
    else:
        offers_form = OffersForm(instance=offer, partner_user=request.user)
        seo_meta_form = SeoModelMetaForm(instance=offer.get_seo_meta_object())
        seo_url_form = SeoModelUrlForm(instance=offer.get_seo_url_object())

    context['offers_form'] = offers_form
    context['seo_meta_form'] = seo_meta_form
    context['seo_url_form'] = seo_url_form
    context['page_title'] = offer.title
    context['offer'] = offer
    return render_to_response('partners/menu/offers/form.html', context)