当前位置: 首页>>代码示例>>Python>>正文


Python ContactForm.save方法代码示例

本文整理汇总了Python中contact.forms.ContactForm.save方法的典型用法代码示例。如果您正苦于以下问题:Python ContactForm.save方法的具体用法?Python ContactForm.save怎么用?Python ContactForm.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在contact.forms.ContactForm的用法示例。


在下文中一共展示了ContactForm.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: edit

# 需要导入模块: from contact.forms import ContactForm [as 别名]
# 或者: from contact.forms.ContactForm import save [as 别名]
def edit(request):
    try:
        contact = Contact.objects.all()[0]
    except IndexError:
        raise Http404
    if request.method == "POST":
        form = ContactForm(request.POST, request.FILES, instance=contact)
        if form.is_valid():
            form.save()
            if request.is_ajax():
                response = {'status': 'OK'}
                data = {'name': 'photo', 'value': contact.photo}
                response['image'] = form.fields['photo'].widget.render(**data)
                return HttpResponse(simplejson.dumps(response))
            return redirect(reverse('index'))
        else:
            if request.is_ajax():
                response = {'status': 'BAD'}
                errors = dict()
                for label_id, error in form.errors.items():
                    errors[label_id] = error
                response['errors'] = errors
                return HttpResponse(simplejson.dumps(response))
    else:
        form = ContactForm(instance=contact)
    return render_to_response('edit.html', {'form': form,
        'number': FORM_SPLIT_BY}, context_instance=RequestContext(request))
开发者ID:volodymyrko,项目名称:hello-world-django,代码行数:29,代码来源:views.py

示例2: test_contact_form_escaped_tags

# 需要导入模块: from contact.forms import ContactForm [as 别名]
# 或者: from contact.forms.ContactForm import save [as 别名]
def test_contact_form_escaped_tags(admin, rf, mailoutbox):
    request = rf.request()
    request.user = admin
    request.META['REMOTE_ADDR'] = '127.0.0.1'
    recipient_email = settings.POOTLE_CONTACT_EMAIL
    specified_subject = "My <tag> subject"
    subject = "[%s] %s" % (settings.POOTLE_TITLE, specified_subject)
    data = {
        'name': admin.full_name,
        'email': admin.email,
        'email_subject': specified_subject,
        'body': "First <tag> of message.",
    }
    form = ContactForm(request=request, data=data)
    assert form.is_valid()
    form.save()
    assert len(mailoutbox) == 1
    message = mailoutbox[0]
    assert message.from_email == settings.DEFAULT_FROM_EMAIL
    reply_to = u'%s <%s>' % (data['name'], data['email'])
    assert reply_to == message.extra_headers['Reply-To']
    assert [recipient_email] == message.recipients()
    assert escape(subject) == message.subject
    assert escape(data['body']) in message.body
    assert "Your question or comment:" not in message.body
开发者ID:arky,项目名称:pootle,代码行数:27,代码来源:contact.py

示例3: contactpage

# 需要导入模块: from contact.forms import ContactForm [as 别名]
# 或者: from contact.forms.ContactForm import save [as 别名]
def contactpage(request):
    if request.method == 'POST':
        form = ContactForm(request.POST)
        if form.is_valid():
            form.save()

            # Sending email.
            subject = form.cleaned_data['subject']
            email = [form.cleaned_data['email'], settings.EMAIL_HOST_USER, ]
            message = form.cleaned_data['message']

            send_mail(subject, message, settings.EMAIL_HOST_USER, email, fail_silently=False)

            url = reverse('contact:message-sent')
            return HttpResponseRedirect(url)
    else:
        form = ContactForm(
            initial={
                'name': u'Kolo\u017ei Robert',
                'email': u'[email protected]',
                'subject': u'[Django] Test from gmail to eunet.rs subject',
                'message': u'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas et nunc id felis condimentum ullamcorper nec a orci. Morbi placerat convallis pharetra. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin volutpat id massa et pulvinar. Etiam est ligula, imperdiet sed sollicitudin vitae, vehicula id nunc. Maecenas at sollicitudin nunc, at fringilla nisi. Duis egestas lorem tristique, suscipit nisi nec, commodo sem. Nulla ac eros nec leo tincidunt bibendum a eget felis. Nunc consectetur enim ligula, vel egestas quam rutrum in.',
                'web_site': u'http://www.robertkolozsi.org'
            }
        )

    context = {
        'form': form,
    }
    return render_to_response('contact/index.html',
                              context,
                              context_instance=RequestContext(request))
开发者ID:old-willow,项目名称:golgota,代码行数:34,代码来源:views.py

示例4: index

# 需要导入模块: from contact.forms import ContactForm [as 别名]
# 或者: from contact.forms.ContactForm import save [as 别名]
def index(request, template_name='content/index.html'):
    page_title = 'Contact DanuGroup.org'
    form=ContactForm(request.POST)
    if form.is_valid():
       form.save()
       return HttpResponseRedirect('/contact/thankyou.html')
    else:
       return render_to_response(template_name, {'form': ContactForm()}, context_instance=RequestContext(request))
开发者ID:jmpmcmanus,项目名称:danugroup,代码行数:10,代码来源:views.py

示例5: contact

# 需要导入模块: from contact.forms import ContactForm [as 别名]
# 或者: from contact.forms.ContactForm import save [as 别名]
def contact(request):
    ctxt = dict()
    template = "contact.html"
    form = ContactForm(request.POST or None)
    if request.method == "POST":
        if form.is_valid():
            form.save()
            messages.success(request, "Thanks! We will contact you shortly.")
            return redirect("home")
        messages.error(request, "You must complete all required fields")
    ctxt["form"] = form
    return render(request, template, ctxt)
开发者ID:Nomadblue,项目名称:nomadweb,代码行数:14,代码来源:views.py

示例6: contact

# 需要导入模块: from contact.forms import ContactForm [as 别名]
# 或者: from contact.forms.ContactForm import save [as 别名]
def contact(request):
	from contact.forms import ContactForm
	
	if request.method == 'POST':
		form = ContactForm(request.POST)
		if form.is_valid():
			form.save()
			return HttpResponseRedirect(reverse('contact_thanks'))
	else:
		form = ContactForm()
		
	return render_to_response('contact.phtml',{'form':form},context_instance=RequestContext(request))
开发者ID:MatchStrike,项目名称:matchstrike,代码行数:14,代码来源:views.py

示例7: post

# 需要导入模块: from contact.forms import ContactForm [as 别名]
# 或者: from contact.forms.ContactForm import save [as 别名]
    def post(self, request, *args, **kwargs):
        form = ContactForm(request.POST)
        if form.is_valid():
            form.save(commit=False)

        send_mail(request.POST.get('name') +" Omaha ", request.POST.get('comment'),request.POST.get('email'), ['[email protected]'])

        data = {
            'form': form,
            'app_name': settings.APP_NAME
        }
        return render(request, self.template_name, data)
开发者ID:RobertUJ,项目名称:Omaha,代码行数:14,代码来源:views.py

示例8: contact_edit

# 需要导入模块: from contact.forms import ContactForm [as 别名]
# 或者: from contact.forms.ContactForm import save [as 别名]
def contact_edit(request):
    contact = get_object_or_404(Contact)
    if request.method == 'POST':
        form = ContactForm(request.POST, instance=contact)
        if form.is_valid():
            form.save()
            if request.is_ajax():
                return HttpResponse("redirect")
            else:
                return redirect(reverse('contact.views.index'))
    else:
        form = ContactForm(instance=contact)
    return render(request, 'contact_edit.html', {'form': form})
开发者ID:alekzvik,项目名称:test_42cc,代码行数:15,代码来源:views.py

示例9: addContactMessage

# 需要导入模块: from contact.forms import ContactForm [as 别名]
# 或者: from contact.forms.ContactForm import save [as 别名]
def addContactMessage(request):
    if request.POST:
        form=ContactForm(request.POST)
        if form.is_valid():
            form.save(commit=True)
            messages.success(request,'Thanks for contacting us!')
            return HttpResponseRedirect('/')

    form=ContactForm()
    args={}
    args.update(csrf(request))
    args['form']=form
    return render(request,'contact/contact.html',args)
开发者ID:narcis2007,项目名称:Multi-user-website-blog,代码行数:15,代码来源:views.py

示例10: contact

# 需要导入模块: from contact.forms import ContactForm [as 别名]
# 或者: from contact.forms.ContactForm import save [as 别名]
def contact(request, template_name='contact/contact.html'):
    # sticks in a POST or renders an empty form
    form = ContactForm(request.POST or None)
    if form.is_valid():
        subject = form.cleaned_data['subject']
        cc = form.cleaned_data['cc']
        print subject
        print cc
        # custom business logic
        form.save()
        return HttpResponseRedirect('/contact/thanks/')
    
    return render(request, template_name, {'form' : form})
开发者ID:MinHyoung,项目名称:play,代码行数:15,代码来源:views.py

示例11: index

# 需要导入模块: from contact.forms import ContactForm [as 别名]
# 或者: from contact.forms.ContactForm import save [as 别名]
def index(request):
    if request.method == "POST":
        form = ContactForm(request.POST)
        if form.is_valid():
            akis = Akismet(key=settings.AKISMET_KEY)
            data = {"user_ip": request.META["REMOTE_ADDR"], "user_agent": request.META["HTTP_USER_AGENT"]}
            if akis.comment_check(comment=form.cleaned_data.get("message"), data=data) == False:
                form.save()
                return redirect("contact_thanks")
    else:
        form = ContactForm()

    return render_to_response("contact/index.html", {"form": form}, context_instance=RequestContext(request))
开发者ID:drewtempelmeyer,项目名称:parisyp,代码行数:15,代码来源:views.py

示例12: save_contact

# 需要导入模块: from contact.forms import ContactForm [as 别名]
# 或者: from contact.forms.ContactForm import save [as 别名]
def save_contact(request):
    if request.method == 'POST':
        contact = Contact()
        form = ContactForm(request.POST, instance=contact)
        if form.is_valid():
            try:
                form.save()
            except Exception:
                return mail_response('false')
            sendmail(form)
            return mail_response('true')
        else:
            return mail_response('false')
    else:
        raise Http404
开发者ID:erickbelfy,项目名称:blink,代码行数:17,代码来源:views.py

示例13: contact_create_or_edit

# 需要导入模块: from contact.forms import ContactForm [as 别名]
# 或者: from contact.forms.ContactForm import save [as 别名]
def contact_create_or_edit(request, id=None):
    if id:
        title = _('Edit a contact')
        contact = get_object_or_404(Contact, pk=id, owner=request.user)
        address = contact.address
    else:
        title = _('Add a contact')
        contact = None
        address = None

    PhoneNumberFormSet = inlineformset_factory(Contact,
                                               PhoneNumber,
                                               form=PhoneNumberForm,
                                               fk_name="contact",
                                               extra=1)

    contacts = Contact.objects.filter(owner=request.user)
    if contact:
        contacts = contacts.exclude(pk=contact.id)

    if request.method == 'POST':
        contactForm = ContactForm(request.POST, instance=contact, prefix="contact")
        contactForm.fields['contacts'].queryset = contacts
        addressForm = AddressForm(request.POST, instance=address, prefix="address")
        phonenumberformset = PhoneNumberFormSet(request.POST, instance=contact)

        if contactForm.is_valid() and addressForm.is_valid() and phonenumberformset.is_valid():
            user = request.user
            address = addressForm.save(commit=False)
            address.save(user=user)
            contact = contactForm.save(commit=False)
            contact.address = address
            contact.save(user=user)
            contactForm.save_m2m()
            for phonenumberform in phonenumberformset.forms:
                phonenumber = phonenumberform.save(commit=False)
                if phonenumber.type:
                    phonenumber.contact = contact
                    phonenumber.save(user=user)

            for deleted_phonenumberrowform in phonenumberformset.deleted_forms:
                deleted_phonenumberrowform.cleaned_data['ownedobject_ptr'].delete()

            messages.success(request, _('The contact has been saved successfully'))
            return redirect(reverse('contact_detail', kwargs={'id': contact.id}))
        else:
            messages.error(request, _('Data provided are invalid'))
    else:
        contactForm = ContactForm(instance=contact, prefix="contact")
        contactForm.fields['contacts'].queryset = contacts
        addressForm = AddressForm(instance=address, prefix="address")
        phonenumberformset = PhoneNumberFormSet(instance=contact)

    return render_to_response('contact/edit.html',
                              {'active': 'contact',
                               'title': title,
                               'contactForm': contactForm,
                               'addressForm': addressForm,
                               'phonenumberformset': phonenumberformset},
                               context_instance=RequestContext(request))
开发者ID:fouda2009,项目名称:aemanager,代码行数:62,代码来源:views.py

示例14: ContactFormTest

# 需要导入模块: from contact.forms import ContactForm [as 别名]
# 或者: from contact.forms.ContactForm import save [as 别名]
class ContactFormTest(TestCase):
    """ Tests the contact form.

    Instance variables:

    val_from_name -- valid from name
    val_from_email -- valid email address
    val_to_name -- valid choice for who it's going to
    val_message -- valid message
    valid_form -- a valid form

    """

    def setUp(self):
        """Set up contact test."""

        # Set environment variable so that we can get around recaptcha
        os.environ["RECAPTCHA_TESTING"] = "True"

        # Make a bunch of valid fields for the valid form
        self.val_from_name = "AT test val_from_name"
        self.val_from_email = "[email protected]"
        self.val_to_name = "HO"
        self.val_message = "This is an automated test from test_valid_data"
        # Make a dictionary of all the valid fields which can be used later
        self.valid_dict = {
            "from_name": self.val_from_name,
            "from_email": self.val_from_email,
            "to_name": self.val_to_name,
            "message": self.val_message,
            "g-recaptcha-response": "PASSED",
        }

        # Create the valid form
        self.valid_form = ContactForm(self.valid_dict)

    def test_valid_data_equals_valid_form(self):
        """ Tests that form is valid. """

        self.assertTrue(self.valid_form.is_valid())

    def test_data_goes_into_object(self):
        """ Tests all fields go into object model correctly. """

        saved_comment = self.valid_form.save()
        self.assertEqual(saved_comment.from_name, self.val_from_name)
        self.assertEqual(saved_comment.from_email, self.val_from_email)
        self.assertEqual(saved_comment.to_name, self.val_to_name)
        self.assertEqual(saved_comment.message, self.val_message)

        # TODO: This probable belongs ina model test.
        contact_queryset = Contact.objects.filter(message__exact=self.val_message)
        first_object = contact_queryset[0]
        self.assertEqual(first_object.from_name, self.val_from_name)

    def tearDown(self):
        """ Unset everything that needs to be unset before next test. """

        os.environ["RECAPTCHA_TESTING"] = "False"
开发者ID:howinator,项目名称:GimmeThat,代码行数:61,代码来源:test_forms.py

示例15: add_contact

# 需要导入模块: from contact.forms import ContactForm [as 别名]
# 或者: from contact.forms.ContactForm import save [as 别名]
def add_contact(request):
    # Get the context from the request.
    context = RequestContext(request)


    context_dict = {}


    # A HTTP POST?
    if request.method == 'POST':
        form = ContactForm(request.POST)

        # Have we been provided with a valid form?
        if form.is_valid():
            # Save the new category to the database.
            print form.cleaned_data
            mes=form.data['name']+form.data['phone']+ form.data['message']
            umes=unicode(mes)


            form.save(commit=True)


            import smsru
            cli = smsru.Client()
            cli.send("+79526646699", umes )



            # Now call the index() view.
            # The user will be shown the homepage.
            return index(request)
        else:
	        # The supplied form contained errors - just print them to the terminal.
            print form.errors
    else:
        # If the request was not a POST, display the form to enter details.
        form = ContactForm()

    # Bad form (or form details), no form supplied...
    # Render the form with error messages (if any).
    context_dict['form'] = form
    return render_to_response('contact/add_contact.html', context_dict, context)
开发者ID:AlfiyaZi,项目名称:flower-SHOP,代码行数:45,代码来源:views.py


注:本文中的contact.forms.ContactForm.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。