def __call__(self): form = self.request.form if form.get('form.buttons.CheckOut') is not None: use_verkkolasku = True if form.get('use_verkkolasku', False) == 'True' else False shopping_site = self.shopping_site() shopping_site.update_cart('use_verkkolasku', use_verkkolasku) if use_verkkolasku: verkkolasku_operator = form.get('verkkolasku_operator') if not verkkolasku_operator: message = _(u'Input verkkolasku operator or remove check from "I want verkkolasku".') IStatusMessage(self.request).addStatusMessage(message, type='info') url = self.context.restrictedTraverse('@@plone_context_state').current_base_url() return self.request.response.redirect(url) else: shopping_site.update_cart('verkkolasku_operator', verkkolasku_operator) verkkolasku_account = form.get('verkkolasku_account') if not verkkolasku_account: message = _(u'Input verkkolasku intermediator account.') IStatusMessage(self.request).addStatusMessage(message, type='info') url = self.context.restrictedTraverse('@@plone_context_state').current_base_url() return self.request.response.redirect(url) else: shopping_site.update_cart('verkkolasku_account', verkkolasku_account) return super(BillingAndShippingView, self).__call__()
def table_headers(self): """Returns headers for table :rtype: tuple """ return ( _(u'ID (e-mail)'), _(u'Name'))
class RegistrationForm(users.browser.register.RegistrationForm): """Registration form for SLT site""" description = _( u'help_registration_form', default= u'You need to be registered and logged in to buy products from our shopping site.' )
def __call__(self): url = self.context.absolute_url() message = PloneMessageFactory(u'Welcome! You are now logged in.') portal_state = self.context.restrictedTraverse('@@plone_portal_state') member = portal_state.member() if not member.getProperty('fullname'): url = '{}/@@personal-information'.format(portal_state.portal_url()) message = _(u'first-time-login', default=u'Please fill your personal information.') IStatusMessage(self.request).addStatusMessage(message, type='info') return self.request.response.redirect(url)
def description(self): return _( u'members-description', default= u'There are ${direct_marketing_allowers} members out of ${all_members} who allows direct marketing.', mapping={ 'direct_marketing_allowers': len(self.direct_marketing_allowers()), 'all_members': len(self.all_members()) })
def __call__(self): form = self.request.form if form.get('form.buttons.CheckOut') is not None: use_verkkolasku = True if form.get('use_verkkolasku', False) == 'True' else False shopping_site = self.shopping_site() shopping_site.update_cart('use_verkkolasku', use_verkkolasku) if use_verkkolasku: verkkolasku_operator = form.get('verkkolasku_operator') if not verkkolasku_operator: message = _( u'Input verkkolasku operator or remove check from "I want verkkolasku".' ) IStatusMessage(self.request).addStatusMessage(message, type='info') url = self.context.restrictedTraverse( '@@plone_context_state').current_base_url() return self.request.response.redirect(url) else: shopping_site.update_cart('verkkolasku_operator', verkkolasku_operator) verkkolasku_account = form.get('verkkolasku_account') if not verkkolasku_account: message = _(u'Input verkkolasku intermediator account.') IStatusMessage(self.request).addStatusMessage(message, type='info') url = self.context.restrictedTraverse( '@@plone_context_state').current_base_url() return self.request.response.redirect(url) else: shopping_site.update_cart('verkkolasku_account', verkkolasku_account) return super(BillingAndShippingView, self).__call__()
class IUserDataSchema(Interface): """ """ fullname = userdataschema.IUserDataSchema.get('fullname') email = userdataschema.IUserDataSchema.get('email') birth_date = schema.TextLine(title=_('Birth Date'), description=_( u'birth_date_format', default=u'Use format: YYYY-MM-DD'), required=False, constraint=validate_birth_date) registration_number = schema.TextLine(title=_('Registration Number'), required=False) allow_direct_marketing = schema.Bool( title=_(u'allow_direct_marketing_title', default=u'Allow Direct Marketing'), description=_( u'allow_direct_marketing_description', u'Check this box to allow direct marketing from this site.'), required=False)
class BirthDateValidationError(schema.ValidationError): """Validation error for birth date""" __doc__ = _(u'birth_date_format', default=u'Use format: YYYY-MM-DD')
def description(self): return _( u'members-description', default=u'There are ${direct_marketing_allowers} members out of ${all_members} who allows direct marketing.', mapping={'direct_marketing_allowers': len(self.direct_marketing_allowers()), 'all_members': len(self.all_members())})
class MembersView(BaseView): """View for @@members""" implements(IMembersView) title = _(u'Members') def description(self): return _( u'members-description', default= u'There are ${direct_marketing_allowers} members out of ${all_members} who allows direct marketing.', mapping={ 'direct_marketing_allowers': len(self.direct_marketing_allowers()), 'all_members': len(self.all_members()) }) @memoize def all_members(self): membership = getToolByName(self.context, 'portal_membership') return membership.searchForMembers() @memoize def direct_marketing_allowers(self): res = [] for member in self.all_members(): if member.getProperty('allow_direct_marketing'): res.append(member) return res @memoize_contextless def table_headers(self): """Returns headers for table :rtype: tuple """ return (_(u'ID (e-mail)'), _(u'Name')) def __call__(self): if self.request.form.get( 'form.buttons.ExportDirectMarketingAllowers') is not None: out = StringIO() writer = csv.writer(out, delimiter='|', quoting=csv.QUOTE_MINIMAL) plone = self.context.restrictedTraverse('@@plone') encoding = plone.site_encoding() headers = [ self.context.translate(header).encode(encoding) for header in self.table_headers() ] writer.writerow(headers) for member in self.direct_marketing_allowers(): writer.writerow((member.getProperty('email'), member.getProperty('fullname'))) filename = 'direct-marketing-allowers-{}.csv'.format( datetime.now().isoformat()) cd = 'attachment; filename="{}"'.format(filename) self.request.response.setHeader('Content-Type', 'text/csv') self.request.response.setHeader("Content-Disposition", cd) return out.getvalue() return self.template()
class OrderListingView(BaseView): """View for listing orders for MemberArea.""" implements(IOrderListingView) title = _(u'Order Linsting')
class AddressListingView(BaseView): """View for listing addresses for MemberArea.""" implements(IAddressListingView) title = _(u'Address Linsting') description = _(u'Add commonly used addresses to make your order easier.')
def table_headers(self): """Returns headers for table :rtype: tuple """ return (_(u'ID (e-mail)'), _(u'Name'))