Beispiel #1
0
def newAgency(request):
    my_agency = AdvertisingAgency(username=request.user)
    ContactFormSet = inlineformset_factory(AdvertisingAgency, Contact, form=ContactForm, can_delete=False, extra=1)
    DetailsFormSet = inlineformset_factory(AdvertisingAgency, Details, form=DetailsForm, can_delete=False, max_num=1)
    NegotiationResultFormSet = inlineformset_factory(AdvertisingAgency, NegotiationResult, form=NegotiationResultForm, can_delete=False, extra=1)
    BrandFormSet = inlineformset_factory(AdvertisingAgency, Brand, form=BrandForm, can_delete=True, extra=1)
    PayerFormSet = inlineformset_factory(AdvertisingAgency, Payer, form=PayerForm, can_delete=True, extra=1)
    formAgency = AgencyForm(request.POST or None, request.FILES or None, instance=my_agency)
    formContactSet = ContactFormSet(request.POST or None, instance=my_agency)
    formDetailsSet = DetailsFormSet(request.POST or None, instance=my_agency)
    formNegotiationResultSet = NegotiationResultFormSet(request.POST or None, instance=my_agency)
    formBrandSet = BrandFormSet(request.POST or None, instance=my_agency)
    formPayerSet = PayerFormSet(request.POST or None, instance=my_agency)
    if formAgency.is_valid() and formContactSet.is_valid() and formDetailsSet.is_valid() and formNegotiationResultSet.is_valid() and formBrandSet.is_valid() and formPayerSet.is_valid():
        formAgency.save()
        formContactSet.save()
        formDetailsSet.save()
        formNegotiationResultSet.save()
        formBrandSet.save()
        formPayerSet.save()
        error(request, 'Информация о рекламном агенстве успешно добавлена.')
        return redirect('agency-index')
    var = {'formAgency': formAgency, 'formContactSet': formContactSet, 'formDetailsSet': formDetailsSet, 'formNegotiationResultSet': formNegotiationResultSet, 'formBrandSet': formBrandSet, 'formPayerSet': formPayerSet}

    return render_to_response('client/agency/edit.html', var, context_instance=RequestContext(request))
Beispiel #2
0
    else:
        BrandFormSet = inlineformset_factory(AdvertisingAgency, Brand, form=BrandForm, can_delete=True, extra=0)
    try:
        Payer.objects.get(agency=my_agency)
    except Exception, e:
        PayerFormSet = inlineformset_factory(AdvertisingAgency, Payer, form=PayerForm, can_delete=True, extra=1)
    else:
        PayerFormSet = inlineformset_factory(AdvertisingAgency, Payer, form=PayerForm, can_delete=True, extra=0)
    formAgency = AgencyForm(request.POST or None, request.FILES or None, instance=my_agency)
    formContactSet = ContactFormSet(request.POST or None, instance=my_agency)
    formDetailsSet = DetailsFormSet(request.POST or None, instance=my_agency)
    formNegotiationResultSet = NegotiationResultFormSet(request.POST or None, instance=my_agency)
    formBrandSet = BrandFormSet(request.POST or None, instance=my_agency)
    formPayerSet = PayerFormSet(request.POST or None, instance=my_agency)
    if formAgency.is_valid() and formContactSet.is_valid() and formDetailsSet.is_valid() and formNegotiationResultSet.is_valid() and formBrandSet.is_valid() and formPayerSet.is_valid():
        formAgency.save()
        formContactSet.save()
        formDetailsSet.save()
        formNegotiationResultSet.save()
        formBrandSet.save()
        formPayerSet.save()
        error(request, 'Информация о рекламном агенстве успешно изменена.')
        return redirect('agency-index')
    var = {'agency': my_agency, 'neg_results': neg_results, 'formAgency': formAgency, 'formContactSet': formContactSet, 'formDetailsSet': formDetailsSet, 'formNegotiationResultSet': formNegotiationResultSet, 'formBrandSet': formBrandSet, 'formPayerSet': formPayerSet}

    return render_to_response('client/agency/edit.html', var, context_instance=RequestContext(request))


@login_required
def deleteAgency(request, id):
    agency = AdvertisingAgency.objects.filter(id=id).update(is_active=False)