Exemplo n.º 1
0
def add_domain_signature(request, domain_id,
                        template='config/add_domain_sig.html'):
    'add domain text or html signature'
    domain = get_object_or_404(UserAddresses, id=domain_id, address_type=1)

    if request.method == 'POST':
        form = AddDomainSignatureForm(request.POST)
        if form.is_valid():
            try:
                form.save()
                msg = _('The signature has been saved')
                GenerateDomainSigs.delay(domain.id)
            except IntegrityError:
                msg = _('A signature of this type already '
                'exists for domain: %(domain)s') % dict(domain=domain.name)
            except DatabaseError:
                msg = _('An error occured during processing try again later')
            djmessages.info(request, msg)
            return HttpResponseRedirect(reverse('view-domain',
                    args=[domain.id]))
    else:
        form = AddDomainSignatureForm(initial={'useraddress': domain.id})
        form.fields['useraddress'].widget.attrs['readonly'] = True
    return render_to_response(template, locals(),
        context_instance=RequestContext(request))
Exemplo n.º 2
0
def edit_domain_signature(request, domain_id, sig_id, template="config/edit_domain_sig.html"):
    "edit domain text or html signature"
    domain = get_object_or_404(UserAddresses, id=domain_id, address_type=1)
    signature = get_object_or_404(DomainSignature, id=sig_id)

    if request.method == "POST":
        form = EditDomainSignatureForm(request.POST, instance=signature)
        if form.is_valid():
            try:
                form.save()
                msg = _("The signature has been updated")
                GenerateDomainSigs.delay(domain.id)
            except DatabaseError:
                msg = _("An error occured during processing, try again later")
            djmessages.info(request, msg)
            return HttpResponseRedirect(reverse("view-domain", args=[domain.id]))
    else:
        form = EditDomainSignatureForm(instance=signature)
    return render_to_response(template, locals(), context_instance=RequestContext(request))