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


Python WebToLeadForm.is_valid方法代码示例

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


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

示例1: contact_bizdev

# 需要导入模块: from bedrock.mozorg.forms import WebToLeadForm [as 别名]
# 或者: from bedrock.mozorg.forms.WebToLeadForm import is_valid [as 别名]
def contact_bizdev(request):
    form = WebToLeadForm(request.POST)

    msg = 'Form invalid'
    stat = 400
    success = 0

    if form.is_valid():
        data = form.cleaned_data.copy()

        honeypot = data.pop('superpriority')

        if honeypot:
            msg = 'Visitor invalid'
            stat = 400
        else:
            interest = data.pop('interest')
            data['00NU0000002pDJr'] = interest
            data['oid'] = '00DU0000000IrgO'
            data['retURL'] = ('http://www.mozilla.org/en-US/about/'
                              'partnerships?success=1')
            r = requests.post('https://www.salesforce.com/servlet/'
                              'servlet.WebToLead?encoding=UTF-8', data)
            msg = requests.status_codes._codes.get(r.status_code, ['error'])[0]
            stat = r.status_code

            success = 1

    if request.is_ajax():
        return HttpResponse(msg, status=stat)
    else:
        return HttpResponseRedirect("%s?success=%s" % (reverse('mozorg.partnerships'), success))
开发者ID:MichealAbaho,项目名称:bedrock,代码行数:34,代码来源:views.py

示例2: process_partnership_form

# 需要导入模块: from bedrock.mozorg.forms import WebToLeadForm [as 别名]
# 或者: from bedrock.mozorg.forms.WebToLeadForm import is_valid [as 别名]
def process_partnership_form(request, template, success_url_name, template_vars=None, form_kwargs=None):
    template_vars = template_vars or {}
    form_kwargs = form_kwargs or {}

    if request.method == "POST":
        form = WebToLeadForm(data=request.POST, **form_kwargs)

        msg = "Form invalid"
        stat = 400
        success = False

        if form.is_valid():
            data = form.cleaned_data.copy()

            honeypot = data.pop("office_fax")

            if honeypot:
                msg = "Visitor invalid"
                stat = 400
            else:
                interest = data.pop("interest")
                data["00NU0000002pDJr"] = interest
                data["oid"] = "00DU0000000IrgO"
                data["lead_source"] = form_kwargs.get("lead_source", "www.mozilla.org/about/partnerships/")
                # As we're doing the Salesforce POST in the background here,
                # `retURL` is never visited/seen by the user. I believe it
                # is required by Salesforce though, so it should hang around
                # as a placeholder (with a valid URL, just in case).
                data["retURL"] = "http://www.mozilla.org/en-US/about/" "partnerships?success=1"

                r = requests.post("https://www.salesforce.com/servlet/" "servlet.WebToLead?encoding=UTF-8", data)
                msg = requests.status_codes._codes.get(r.status_code, ["error"])[0]
                stat = r.status_code

                success = True

        if request.is_ajax():
            return HttpResponseJSON({"msg": msg, "errors": form.errors}, status=stat)
        # non-AJAX POST
        else:
            # if form is not valid, render template to retain form data/error messages
            if not success:
                template_vars.update(csrf(request))
                template_vars["form"] = form
                template_vars["form_success"] = success

                return l10n_utils.render(request, template, template_vars)
            # if form is valid, redirect to avoid refresh double post possibility
            else:
                return HttpResponseRedirect("%s?success" % (reverse(success_url_name)))
    # no form POST - build form, add CSRF, & render template
    else:
        # without auto_id set, all id's get prefixed with 'id_'
        form = WebToLeadForm(auto_id="%s", **form_kwargs)

        template_vars.update(csrf(request))
        template_vars["form"] = form
        template_vars["form_success"] = True if ("success" in request.GET) else False

        return l10n_utils.render(request, template, template_vars)
开发者ID:josiah2595,项目名称:bedrock,代码行数:62,代码来源:views.py

示例3: process_partnership_form

# 需要导入模块: from bedrock.mozorg.forms import WebToLeadForm [as 别名]
# 或者: from bedrock.mozorg.forms.WebToLeadForm import is_valid [as 别名]
def process_partnership_form(request, template, success_url_name, template_vars=None, form_kwargs=None):
    template_vars = template_vars or {}
    form_kwargs = form_kwargs or {}

    if request.method == 'POST':
        form = WebToLeadForm(data=request.POST, **form_kwargs)

        msg = 'Form invalid'
        stat = 400
        success = False

        if form.is_valid():
            data = form.cleaned_data.copy()

            honeypot = data.pop('office_fax')

            if honeypot:
                msg = 'ok'
                stat = 200
            else:
                # rename custom Salesforce fields to their real GUID name
                data['00NU0000002pDJr'] = data.pop('interest')
                data['00NU00000053D4G'] = data.pop('interested_countries')
                data['00NU00000053D4L'] = data.pop('interested_languages')
                data['00NU00000053D4a'] = data.pop('campaign_type')
                data['oid'] = '00DU0000000IrgO'
                data['lead_source'] = form_kwargs.get('lead_source',
                                                      'www.mozilla.org/about/partnerships/')
                # As we're doing the Salesforce POST in the background here,
                # `retURL` is never visited/seen by the user. I believe it
                # is required by Salesforce though, so it should hang around
                # as a placeholder (with a valid URL, just in case).
                data['retURL'] = ('http://www.mozilla.org/en-US/about/'
                                  'partnerships?success=1')

                r = requests.post('https://www.salesforce.com/servlet/'
                                  'servlet.WebToLead?encoding=UTF-8', data)
                msg = requests.status_codes._codes.get(r.status_code, ['error'])[0]
                stat = r.status_code

                success = True

        if request.is_ajax():
            form_errors = {fn: [escape(msg) for msg in msgs] for fn, msgs
                           in form.errors.iteritems()}

            return HttpResponseJSON({'msg': msg, 'errors': form_errors}, status=stat)
        # non-AJAX POST
        else:
            # if form is not valid, render template to retain form data/error messages
            if not success:
                template_vars.update(csrf(request))
                template_vars['form'] = form
                template_vars['form_success'] = success

                return l10n_utils.render(request, template, template_vars)
            # if form is valid, redirect to avoid refresh double post possibility
            else:
                return HttpResponseRedirect("%s?success" % (reverse(success_url_name)))
    # no form POST - build form, add CSRF, & render template
    else:
        # without auto_id set, all id's get prefixed with 'id_'
        form = WebToLeadForm(auto_id='%s', **form_kwargs)

        template_vars.update(csrf(request))
        template_vars['form'] = form
        template_vars['form_success'] = True if ('success' in request.GET) else False

        return l10n_utils.render(request, template, template_vars)
开发者ID:OBSERVER-DLL,项目名称:bedrock,代码行数:71,代码来源:views.py

示例4: process_partnership_form

# 需要导入模块: from bedrock.mozorg.forms import WebToLeadForm [as 别名]
# 或者: from bedrock.mozorg.forms.WebToLeadForm import is_valid [as 别名]
def process_partnership_form(request, template, success_url_name,
                             template_vars=None, form_kwargs=None):
    template_vars = template_vars or {}
    form_kwargs = form_kwargs or {}

    if request.method == 'POST':
        form = WebToLeadForm(data=request.POST, **form_kwargs)

        msg = 'Form invalid'
        stat = 400
        success = False

        if form.is_valid():
            data = form.cleaned_data.copy()

            honeypot = data.pop('office_fax')

            if honeypot:
                msg = 'ok'
                stat = 200
            else:
                # form testing address
                if not data['email'] == '[email protected]':
                    data['lead_source'] = form_kwargs.get('lead_source',
                                                          'www.mozilla.org/about/partnerships/')

                    subject = PARTNERSHIPS_EMAIL_SUBJECT
                    sender = PARTNERSHIPS_EMAIL_FROM
                    to = PARTNERSHIPS_EMAIL_TO
                    body = render_to_string('mozorg/emails/partnerships.txt', data,
                                            request=request)

                    email = EmailMessage(subject, body, sender, to)
                    email.send()

                msg = 'ok'
                stat = 200
                success = True

        if request.is_ajax():
            form_errors = {fn: [escape(msg) for msg in msgs] for fn, msgs
                           in form.errors.iteritems()}

            return HttpResponseJSON({'msg': msg, 'errors': form_errors}, status=stat)
        # non-AJAX POST
        else:
            # if form is not valid, render template to retain form data/error messages
            if not success:
                template_vars.update(csrf(request))
                template_vars['form'] = form
                template_vars['form_success'] = success

                return l10n_utils.render(request, template, template_vars)
            # if form is valid, redirect to avoid refresh double post possibility
            else:
                return HttpResponseRedirect("%s?success" % (reverse(success_url_name)))
    # no form POST - build form, add CSRF, & render template
    else:
        # without auto_id set, all id's get prefixed with 'id_'
        form = WebToLeadForm(auto_id='%s', **form_kwargs)

        template_vars.update(csrf(request))
        template_vars['form'] = form
        template_vars['form_success'] = True if ('success' in request.GET) else False

        return l10n_utils.render(request, template, template_vars)
开发者ID:jgmize,项目名称:bedrock,代码行数:68,代码来源:views.py

示例5: process_partnership_form

# 需要导入模块: from bedrock.mozorg.forms import WebToLeadForm [as 别名]
# 或者: from bedrock.mozorg.forms.WebToLeadForm import is_valid [as 别名]
def process_partnership_form(request, template, success_url_name, template_vars=None, form_kwargs=None):
    template_vars = template_vars or {}
    form_kwargs = form_kwargs or {}

    if request.method == 'POST':
        form = WebToLeadForm(data=request.POST, **form_kwargs)

        msg = 'Form invalid'
        stat = 400
        success = False

        if form.is_valid():
            data = form.cleaned_data.copy()

            honeypot = data.pop('superpriority')

            if honeypot:
                msg = 'Visitor invalid'
                stat = 400
            else:
                interest = data.pop('interest')
                data['00NU0000002pDJr'] = interest
                data['oid'] = '00DU0000000IrgO'
                # As we're doing the Salesforce POST in the background here,
                # `retURL` is never visited/seen by the user. I believe it
                # is required by Salesforce though, so it should hang around
                # as a placeholder (with a valid URL, just in case).
                data['retURL'] = ('http://www.mozilla.org/en-US/about/'
                                  'partnerships?success=1')

        if form.is_valid():

            data = form.cleaned_data.copy()

            subject = 'New partner submission from %s' % data['company']
            to = ['[email protected]']
            cc = ['[email protected]illa.com']
            from_ = '[email protected]'
            reply_to = [data['email']]
            msg = jingo.render_to_string(request, 'mocotw/emails/notify_bizdev.txt', data)

            # FIXME Why ?
            msg = msg.replace('\n', '\r\n')
            headers = {'Reply-To': ','.join(reply_to)}

            email = EmailMessage(subject, msg, from_, to, cc=cc, headers=headers)
            email.send()

            stat = 200
            success = 1

    if request.is_ajax():
        return HttpResponse(msg, status=stat)

    else:
        # without auto_id set, all id's get prefixed with 'id_'
        form = WebToLeadForm(auto_id='%s', **form_kwargs)

        template_vars.update(csrf(request))
        template_vars['form'] = form
        template_vars['form_success'] = True if ('success' in request.GET) else False

        return l10n_utils.render(request, template, template_vars)
开发者ID:elin-moco,项目名称:bedrock,代码行数:65,代码来源:views.py


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