示例#1
0
def update(request, pk, slug=None, template='contacts/person/update.html'):
    """Update a person.

    :param template: A custom template.
    """


    user = request.user
    if not user.has_perm('change_person'):
        return HttpResponseForbidden()

    try:
        person = Person.objects.get(pk__iexact=pk)
    except person.DoesNotExist:
        raise Http404

    if request.method == 'POST':
        form = PersonUpdateForm(request.POST, instance=person)
        phone_formset = PhoneNumberFormSet(request.POST, instance=person)
        email_formset = EmailAddressFormSet(request.POST, instance=person)
        im_formset = InstantMessengerFormSet(request.POST, instance=person)
        website_formset = WebSiteFormSet(request.POST, instance=person)
        address_formset = StreetAddressFormSet(request.POST, instance=person)
        special_date_formset = SpecialDateFormSet(request.POST, instance=person)

        if form.is_valid() and phone_formset.is_valid() and \
            email_formset.is_valid() and im_formset.is_valid() and \
            website_formset.is_valid() and address_formset.is_valid():
            form.save()
            phone_formset.save()
            email_formset.save()
            im_formset.save()
            website_formset.save()
            address_formset.save()
            special_date_formset.save()
            return HttpResponseRedirect(person.get_absolute_url())
        else:
            return HttpResponseServerError

    form = PersonUpdateForm(instance=person)
    phone_formset = PhoneNumberFormSet(instance=person)
    email_formset = EmailAddressFormSet(instance=person)
    im_formset = InstantMessengerFormSet(instance=person)
    website_formset = WebSiteFormSet(instance=person)
    address_formset = StreetAddressFormSet(instance=person)
    special_date_formset = SpecialDateFormSet(instance=person)

    kwvars = {
        'form': form,
        'phone_formset': phone_formset,
        'email_formset': email_formset,
        'im_formset': im_formset,
        'website_formset': website_formset,
        'address_formset': address_formset,
        'special_date_formset': special_date_formset,
        'object': person,
    }

    return render_to_response(template, kwvars, RequestContext(request))
示例#2
0
def update(request, slug, template="contacts/company/update.html"):
    """Update a company.

    :param template: A custom template.
    :param form: A custom form.
    """

    user = request.user
    if not user.has_perm("change_company"):
        return HttpResponseForbidden()

    try:
        company = Company.objects.get(slug__iexact=slug)
    except Company.DoesNotExist:
        raise Http404

    form = CompanyUpdateForm(instance=company)
    phone_formset = PhoneNumberFormSet(instance=company)
    email_formset = EmailAddressFormSet(instance=company)
    im_formset = InstantMessengerFormSet(instance=company)
    website_formset = WebSiteFormSet(instance=company)
    address_formset = StreetAddressFormSet(instance=company)

    if request.method == "POST":
        form = CompanyUpdateForm(request.POST, instance=company)
        phone_formset = PhoneNumberFormSet(request.POST, instance=company)
        email_formset = EmailAddressFormSet(request.POST, instance=company)
        im_formset = InstantMessengerFormSet(request.POST, instance=company)
        website_formset = WebSiteFormSet(request.POST, instance=company)
        address_formset = StreetAddressFormSet(request.POST, instance=company)

        if (
            form.is_valid()
            and phone_formset.is_valid()
            and email_formset.is_valid()
            and im_formset.is_valid()
            and website_formset.is_valid()
            and address_formset.is_valid()
        ):
            form.save()
            phone_formset.save()
            email_formset.save()
            im_formset.save()
            website_formset.save()
            address_formset.save()
            return HttpResponseRedirect(company.get_absolute_url())

    kwvars = {
        "form": form,
        "phone_formset": phone_formset,
        "email_formset": email_formset,
        "im_formset": im_formset,
        "website_formset": website_formset,
        "address_formset": address_formset,
        "object": company,
    }

    return render_to_response(template, kwvars, RequestContext(request))
示例#3
0
def update(request, pk, slug=None, template='contacts/company/update.html'):
    """Update a company.

    :param template: A custom template.
    :param form: A custom form.
    """

    user = request.user
    if not user.has_perm('{}.change_company'.format(Company._meta.app_label)):
        return HttpResponseForbidden()

    try:
        company = Company.objects.get(pk__iexact=pk)
    except Company.DoesNotExist:
        raise Http404

    form = CompanyUpdateForm(instance=company)
    phone_formset = PhoneNumberFormSet(instance=company)
    email_formset = EmailAddressFormSet(instance=company)
    im_formset = InstantMessengerFormSet(instance=company)
    website_formset = WebSiteFormSet(instance=company)
    address_formset = StreetAddressFormSet(instance=company)
    special_date_formset = SpecialDateFormSet(instance=company)

    if request.method == 'POST':
        form = CompanyUpdateForm(request.POST, instance=company)
        phone_formset = PhoneNumberFormSet(request.POST, instance=company)
        email_formset = EmailAddressFormSet(request.POST, instance=company)
        im_formset = InstantMessengerFormSet(request.POST, instance=company)
        website_formset = WebSiteFormSet(request.POST, instance=company)
        address_formset = StreetAddressFormSet(request.POST, instance=company)
        special_date_formset = SpecialDateFormSet(request.POST, instance=company)

        if form.is_valid() and phone_formset.is_valid() and \
                email_formset.is_valid() and im_formset.is_valid() and \
                website_formset.is_valid() and address_formset.is_valid():
            form.save()
            phone_formset.save()
            email_formset.save()
            im_formset.save()
            website_formset.save()
            address_formset.save()
            special_date_formset.save()
            return HttpResponseRedirect(company.get_absolute_url())

    kwvars = {
        'form': form,
        'phone_formset': phone_formset,
        'email_formset': email_formset,
        'im_formset': im_formset,
        'website_formset': website_formset,
        'address_formset': address_formset,
        'special_date_formset': special_date_formset,
        'object': company,
    }

    return render_to_response(template, kwvars, RequestContext(request))
示例#4
0
def update(request, pk, slug=None, template='contacts/company/update.html'):
    """Update a company.

    :param template: A custom template.
    :param form: A custom form.
    """

    user = request.user
    if not user.has_perm('contacts.change_company'):
        return HttpResponseForbidden()

    try:
        company = Company.objects.get(pk__iexact=pk)
    except Company.DoesNotExist:
        raise Http404

    
    if request.method == 'POST':
        form = CompanyUpdateForm(request.POST, instance=company)
        phone_formset = PhoneNumberFormSet(request.POST, instance=company)
        email_formset = EmailAddressFormSet(request.POST, instance=company)
        website_formset = WebSiteFormSet(request.POST, instance=company)
        address_formset = StreetAddressFormSet(request.POST, instance=company)

        if form.is_valid() and phone_formset.is_valid() and \
            email_formset.is_valid() and \
            website_formset.is_valid() and address_formset.is_valid():
            form.save()
            phone_formset.save()
            email_formset.save()
            website_formset.save()
            address_formset.save()
            msg = 'Company updated'
            messages.success(request, msg)

            return HttpResponseRedirect(company.get_absolute_url())
        
    else:
        
        form = CompanyUpdateForm(instance=company)
        phone_formset = PhoneNumberFormSet(instance=company)
        email_formset = EmailAddressFormSet(instance=company)
        website_formset = WebSiteFormSet(instance=company)
        address_formset = StreetAddressFormSet(instance=company)
        
    kwvars = {
        'form': form,
        'phone_formset': phone_formset,
        'email_formset': email_formset,
        'website_formset': website_formset,
        'address_formset': address_formset,
        'object': company,
    }

    return render_to_response(template, RequestContext(request, kwvars))
示例#5
0
def update(request, pk, slug=None, template='contacts/person/update.html'):
    """Update a person.

    :param template: A custom template.
    """

    user = request.user
    if not user.has_perm('change_person'):
        return HttpResponseForbidden()

    try:
        person = Person.objects.get(pk__iexact=pk)
    except person.DoesNotExist:
        raise Http404

    if request.method == 'POST':
        form = PersonUpdateForm(request.POST, instance=person)
        phone_formset = PhoneNumberFormSet(request.POST, instance=person)
        email_formset = EmailAddressFormSet(request.POST, instance=person)
        im_formset = InstantMessengerFormSet(request.POST, instance=person)
        website_formset = WebSiteFormSet(request.POST, instance=person)
        address_formset = StreetAddressFormSet(request.POST, instance=person)
        special_date_formset = SpecialDateFormSet(request.POST,
                                                  instance=person)

        if form.is_valid() and phone_formset.is_valid() and \
            email_formset.is_valid() and im_formset.is_valid() and \
            website_formset.is_valid() and address_formset.is_valid():
            form.save()
            phone_formset.save()
            email_formset.save()
            im_formset.save()
            website_formset.save()
            address_formset.save()
            special_date_formset.save()
            return HttpResponseRedirect(person.get_absolute_url())
        else:
            return HttpResponseServerError

    form = PersonUpdateForm(instance=person)
    phone_formset = PhoneNumberFormSet(instance=person)
    email_formset = EmailAddressFormSet(instance=person)
    im_formset = InstantMessengerFormSet(instance=person)
    website_formset = WebSiteFormSet(instance=person)
    address_formset = StreetAddressFormSet(instance=person)
    special_date_formset = SpecialDateFormSet(instance=person)

    kwvars = {
        'form': form,
        'phone_formset': phone_formset,
        'email_formset': email_formset,
        'im_formset': im_formset,
        'website_formset': website_formset,
        'address_formset': address_formset,
        'special_date_formset': special_date_formset,
        'object': person,
    }

    return render_to_response(template, kwvars, RequestContext(request))
示例#6
0
def update(request, pk, slug=None, template='contacts/company/update.html'):
    """Update a company.

    :param template: A custom template.
    :param form: A custom form.
    """

    user = request.user
    if not user.has_perm('{}.change_company'.format(Company._meta.app_label)):
        return HttpResponseForbidden()

    try:
        company = Company.objects.get(pk__iexact=pk)
    except Company.DoesNotExist:
        raise Http404

    form = CompanyUpdateForm(instance=company)
    phone_formset = PhoneNumberFormSet(instance=company)
    email_formset = EmailAddressFormSet(instance=company)
    im_formset = InstantMessengerFormSet(instance=company)
    website_formset = WebSiteFormSet(instance=company)
    address_formset = StreetAddressFormSet(instance=company)
    special_date_formset = SpecialDateFormSet(instance=company)

    if request.method == 'POST':
        form = CompanyUpdateForm(request.POST, instance=company)
        phone_formset = PhoneNumberFormSet(request.POST, instance=company)
        email_formset = EmailAddressFormSet(request.POST, instance=company)
        im_formset = InstantMessengerFormSet(request.POST, instance=company)
        website_formset = WebSiteFormSet(request.POST, instance=company)
        address_formset = StreetAddressFormSet(request.POST, instance=company)
        special_date_formset = SpecialDateFormSet(request.POST,
                                                  instance=company)

        if form.is_valid() and phone_formset.is_valid() and \
                email_formset.is_valid() and im_formset.is_valid() and \
                website_formset.is_valid() and address_formset.is_valid():
            form.save()
            phone_formset.save()
            email_formset.save()
            im_formset.save()
            website_formset.save()
            address_formset.save()
            special_date_formset.save()
            return HttpResponseRedirect(company.get_absolute_url())

    kwvars = {
        'form': form,
        'phone_formset': phone_formset,
        'email_formset': email_formset,
        'im_formset': im_formset,
        'website_formset': website_formset,
        'address_formset': address_formset,
        'special_date_formset': special_date_formset,
        'object': company,
    }

    return render_to_response(template, kwvars, RequestContext(request))