验证Plone 3.2.1 BrowserView

时间:2014-05-20 08:49:27

标签: paypal plone

我为Plone 3.2.1网站编写了一个简单的附加浏览器视图,它是一个使用HTML variables specified by PayPal然后发布到PayPal地址的简单表单。

由于PayPal表单上这些字段的性质,当我直接发布到PayPal时,绝对没有验证,这是可以理解的,因为大多数字段都是可选的。我希望按顺序使用urllib和urllib2,以便我可以将表单发布到Python脚本,验证输入,然后发布到PayPal。

BrowserView的布局(修剪)

paypal.test
|-paypal
  |-test
    |-browser
      |-paypal_validation.py
      |-paypal_validation_script.py
      |-paypal_view.pt
      |-configure.zcml

configure.zcml中

<configure
    xmlns="http://namespaces.zope.org/zope"
    xmlns:browser="http://namespaces.zope.org/browser"
    i18n_domain="paypal.test">

    ...

    <browser:page
        name="paypal_validation_script"
        for="*"
        permission="zope2.View"
        class=".paypal_validation.PayPalValidation"
        />
    <browser:page 
        name="paypal_validation"
        for="*"
        permission="zope2.View"
        class=".paypal_validation.PayPalView"
        />
</configure>

paypal_validation.py

from Products.Five import BrowserView
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile

class PayPalView(BrowserView):

  template = ViewPageTemplateFile('paypal_view.pt')

  def __call__(self):
    self.paypal_name = getattr(self.context, 'paypal_name', 'World')
    return self.template()

paypal_view.pt

<form action="paypal_validation_script" method="post" 
  tal:define="did python:request.form['did'];
              ourl string:http://www.mysite.co.uk/uploadedfiles/;
              dil python:ourl + did">
  <input type="hidden" name="cmd" value="_xclick" />
  <input type="hidden" name="business" value="paypal-facilitator@someothersite.co.uk" />
  <label for="item_name">Design Name:</label>
  <input name="item_name" id="item_name" />
  <label for="dimensionx">Width (mm):</label>
  <input type="hidden" name="on0" value="Width (mm)" />
  <input id="dimensionx" name="os0" />
  <label for="dimensiony">Height (mm):</label>
  <input type="hidden" name="on1" value="Height (mm)" />
  <input id="dimensiony" name="os1" />
  <label for="dimensionz">Depth (mm):</label>
  <input type="hidden" name="on2" value="Depth (mm)" />
  <input id="dimensionz" name="os2" />
  <label for="design_no">Design Number:</label>
  <input type="hidden" name="on3" value="Design Number" />
  <input id="design_no" name="os3" />
  <label for="tool_no">Tool/Cutter Number:</label>
  <input type="hidden" name="on4" value="Tool/Cutter Number" />
  <input id="tool_no" name="os4" />
  <input type="hidden" name="item_number" id="item_number" tal:attributes="value dil"/>
  <label for="street_addr">Street Address:</label>
  <input type="hidden" name="on5" value="Street Address" />
  <input id="street_addr" name="os5" />
  <label for="city">City:</label>
  <input type="hidden" name="on6" value="City" />
  <input id="city" name="os6" />
  <label for="postcode">Post Code:</label>
  <input type="hidden" name="on7" value="Post Code" />
  <input id="postcode" name="os7" />
  <label for="tel">Telephone Number:</label>
  <input type="hidden" name="on8" value="Telephone" />
  <input id="tel" name="os8" />
  <label for="email">Email Address:</label>
  <input type="hidden" name="on9" value="Email Address" />
  <input id="email" name="os9" />
  <input type="hidden" name="amount" value="19.99" />
  <input type="hidden" name="no_shipping" value="0" />
  <input type="hidden" name="no_note" value="0" />
  <input type="hidden" name="currency_code" value="GBP" />
  <input type="hidden" name="return" value="http://www.mysite.co.uk" />
  <div class="formControls">
    <input type="submit" data-env="sandbox" value="Pay with PayPal" />
  </div>
</form>

paypal_validation_script.py

目前这是空的,因为我到目前为止还无法实现这一点......我认为我可以在这里使用context.REQUEST获取提交的信息?

发生了什么

每当我提交表单时,我都会被带到404,说明paypal_validation_script不可用,我不知道如何在我的表单中引用此脚本(见上文),以便我可以使用以下方式验证和发布必要的信息它。

0 个答案:

没有答案