Commit 48cd73d1 authored by Nicolas Chauvat's avatar Nicolas Chauvat
Browse files

[schema views] add billing address (closes #1908592)

parent b283546140ff
......@@ -4,7 +4,7 @@
modname = 'cmt'
distname = 'cubicweb-cmt'
numversion = (0, 4, 0)
numversion = (0, 5, 0)
version = '.'.join(str(num) for num in numversion)
license = 'LCL'
......
add_entity_type('BillingAddress')
......@@ -17,9 +17,10 @@
"""cubicweb-cmt schema"""
from yams.buildobjs import RelationDefinition
from yams.buildobjs import RelationDefinition, EntityType, String
from cubes.shoppingcart.schema import ShoppingItem
from cubes.conference.schema import user_owns_subject, user_owns_object
ShoppingItem.get_relation('quantity').default = 1
......@@ -32,3 +33,22 @@ class has_shoppingitemtype(RelationDefinition):
subject = 'Conference'
object = 'ShoppingItemType'
cardinality = '*1'
class BillingAddress(EntityType):
organisation = String(required=True, maxsize=256)
street = String(required=True, maxsize=256)
street2 = String(required=True, maxsize=256)
postalcode = String(required=True, maxsize=256)
city = String(required=True, maxsize=256)
country = String(required=True, maxsize=256)
your_ref = String(maxsize=256)
class billing(RelationDefinition):
__permissions__ = {
'read': ('managers', 'users'),
'add': ('managers', user_owns_subject()),
'delete': ('managers', user_owns_subject()),
}
subject = 'ShoppingCart'
object = 'BillingAddress'
cardinality = '?1'
......@@ -24,7 +24,7 @@ from cubicweb.selectors import (is_instance, match_view, match_context,
authenticated_user)
from cubicweb.web import uicfg, Redirect, component
from cubicweb.web.component import Layout
from cubicweb.web.views import primary
from cubes.conference.views.startup import ConferenceIndexView
from cubes.conference.views.forms import subject_reg_open_conf_vocabulary
......@@ -34,6 +34,9 @@ from cubes.shoppingcart.views import ShoppingCartEntityFormRenderer
uicfg.autoform_field_kwargs.tag_subject_of(('ShoppingCart', 'book_conf', 'Conference'),
{'choices': subject_reg_open_conf_vocabulary})
uicfg.actionbox_appearsin_addmenu.tag_subject_of(('Conference', 'has_shoppingitemtype', '*'), True)
uicfg.actionbox_appearsin_addmenu.tag_subject_of(('ShoppingCart', 'billing', '*'), True)
uicfg.primaryview_section.tag_subject_of(('ShoppingCart', 'billing', '*'), 'hidden')
uicfg.primaryview_section.tag_object_of(('ShoppingCart', 'billing', 'BillingAddress'), 'hidden')
_ = unicode
......@@ -180,11 +183,37 @@ class CmtShoppingCartPrimaryView(ShoppingCartPrimaryView):
self.w(u'</p>')
self.w(btn_modify)
else:
conf = entity.book_conf[0]
self.w(u'<p><a href="%s">%s</a></p>' % (conf.absolute_url(), self._cw._('Go to the conference schedule')))
if entity.billing:
self.w(u'<p>%s</p>' % self._cw._('Billing address'))
entity.billing[0].view('primary', w=self.w)
else:
add_url = self._cw.build_url('add/BillingAddress',
__linkto='billing:%d:object' % entity.eid,
__redirectpath='shoppingcart/%d' % entity.eid,
__redirectvid='primary')
self.w(u'<p><a href="%s">%s</a></p>' % (xml_escape(add_url), self._cw._('Add a billing address')))
self.w(u'<hr /><p><a href="%s">%s</a></p>' % (entity.book_conf[0].absolute_url(), self._cw._('Go to the conference schedule')))
REPLACE_LIST.append((CmtShoppingCartPrimaryView, ShoppingCartPrimaryView))
# XXX move this upstream into cw
def set_field_order(etype, attrs):
for index, attr in enumerate(attrs):
uicfg.autoform_field_kwargs.tag_subject_of(
(etype, attr, '*'), {'order': index})
uicfg.primaryview_display_ctrl.tag_subject_of(
(etype, attr, '*'), {'order': index})
set_field_order('BillingAddress',
('organisation', 'street', 'street2', 'postalcode', 'city',
'country', 'your_ref',))
class BillingAddressPrimaryView(primary.PrimaryView):
__select__ = primary.PrimaryView.__select__ & is_instance('BillingAddress')
def render_entity_title(self, entity):
pass
# registration view
class ConfRegistrationView(EntityView):
__regid__ = 'conf-registration'
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment