Commit 291dce97 authored by Julien Jehannet's avatar Julien Jehannet
Browse files

[views] update registration box to cw3.10

parent c3635ccc915b
......@@ -41,7 +41,7 @@ from cubicweb.devtools import testlib
class DefaultTC(testlib.CubicWebTC):
def test_something(self):
self.skip('this cube has no test')
self.skipTest('this cube has no test')
if __name__ == '__main__':
......
# copyright 2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
# CubicWeb is free software: you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free
# Software Foundation, either version 2.1 of the License, or (at your option)
# any later version.
#
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License along
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>.
from __future__ import with_statement
from cubicweb.utils import UStringIO
from cubicweb.devtools.testlib import CubicWebTC
from cubicweb.web.component import EmptyComponent
class ConfRegistrationComponentTC(CubicWebTC):
regid = 'confregistrationbox'
def create_conf(self, reg_open=True):
pa = self.req.create_entity('PostalAddress', street=u"ma rue",
postalcode=u"42",
city=u'ma ville')
conf = self.req.create_entity('Conference', title=u"my conf",
reg_open=reg_open, take_place_at=pa)
self.commit()
return conf
def setUp(self):
CubicWebTC.setUp(self)
self.req = self.request()
self.component = self.vreg['ctxcomponents'].select(self.regid, self.req)
self.w = UStringIO
def test_boolean_field(self):
self.assertEqual(len(self.execute('Any C WHERE C is Conference')), 0)
pa = self.req.create_entity('PostalAddress', street=u"ma rue",
postalcode=u"42",
city=u'ma ville')
conf = self.req.create_entity('Conference', title=u"my conf",
reg_open=True, take_place_at=pa)
self.commit()
self.assertEqual(len(self.execute('Any C WHERE C is Conference, C reg_open True')), 1)
def test_create_conf(self):
self.assertEqual(len(self.execute('Any C WHERE C is Conference')), 0)
conf = self.create_conf()
self.assertTrue(conf.reg_open)
self.assertEqual(len(self.execute('Any C WHERE C is Conference, C reg_open True')), 1)
self.assertEqual(conf.take_place_at[0].street, u"ma rue")
conf = self.create_conf(reg_open=False)
self.assertEqual(len(self.execute('Any C WHERE C is Conference, C reg_open False')), 1)
self.assertFalse(conf.reg_open)
self.assertEqual(len(self.execute('Any C WHERE C is Conference')), 2)
def test_no_open_registration(self):
self.assertEqual(self.component.context, "left")
self.assertRaises(EmptyComponent, self.component.init_rendering)
self.create_conf(reg_open=False)
self.assertRaises(EmptyComponent, self.component.init_rendering)
def test_anonymous_session(self):
conf = self.create_conf()
with self.login('anon') as anon:
req = self.request()
self.assertTrue(req.session.anonymous_session)
self.component.init_rendering()
label = self.component.render_body(self.w)
self.assertEqual(label, _('Register now for the conference !'))
def test_items_not_found(self):
self.create_conf()
self.component.init_rendering()
label = self.component.render_body(self.w)
self.assertEqual(label, _('Register now for the conference !'))
def test_items_found_and_cart_is_checked_out(self):
self.create_conf()
you_are_registered = _('You are registered for the conference')
self.skipTest(you_are_registered)
def test_items_found_and_cart_not_checked_out(self):
self.create_conf()
pay_to_confirm = _('Pay now to confirm your registration !')
self.skipTest(pay_to_confirm)
if __name__ == '__main__':
from logilab.common.testlib import unittest_main
unittest_main()
......@@ -19,10 +19,12 @@
import datetime
from logilab.mtconverter import xml_escape
from cubicweb.web import uicfg, box, Redirect
from cubicweb.view import EntityView
from cubicweb.selectors import is_instance, match_user_groups, authenticated_user
from cubicweb.web.views import primary, workflow
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 cubes.conference.views.startup import ConferenceIndexView
from cubes.conference.views.forms import subject_reg_open_conf_vocabulary
......@@ -52,45 +54,66 @@ class CmtIndexView(ConferenceIndexView):
REPLACE_LIST.append((CmtIndexView, ConferenceIndexView))
class ConferenceRegistrationBox(box.BoxTemplate):
__regid__ = 'confregistrationbox'
class ConferenceRegistrationComponent(component.CtxComponent):
__regid__ = 'confregistrationbox'
context = 'left'
title = _(u'Conference Registration')
order = 0
label = None
def call(self, **kwargs):
reg_open = self._cw.execute('Any C WHERE C is Conference, C reg_open "True"')
def init_rendering(self):
reg_open = self._cw.execute('Any C WHERE C is Conference, C reg_open True')
if not reg_open:
return
conf = reg_open.get_entity(0,0) # XXX bug: what if there is more than one conf ?
w = self.w
register_now = self._cw._('Register now for the conference !')
pay_to_confirm = self._cw._('Pay now to confirm your registration !')
you_are_registered = self._cw._('You are registered for the conference')
label = None
raise component.EmptyComponent()
# BUGGY: what if there is more than one conf ?
self.conf = self._cw.entity_from_eid(reg_open[0][0])
register_now = _('Register now for the conference !')
pay_to_confirm = _('Pay now to confirm your registration !')
you_are_registered = _('You are registered for the conference')
if self._cw.session.anonymous_session:
if reg_open:
label = register_now
self.label = register_now
else:
has_cart = self._cw.execute('Any C WHERE U eid %(x)s, C buyer U', {'x': self._cw.user.eid})
items = self._cw.execute('Any I WHERE U eid %(x)s, C buyer U, C items_in_cart I',
{'x': self._cw.user.eid})
if has_cart:
if items:
if has_cart.get_entity(0,0).in_state[0].name == 'checked out':
label = you_are_registered
state = has_cart.get_entity(0, 0).cw_adapt_to('IWorkflowable').state
if state == 'checked out':
self.label = you_are_registered
else:
label = pay_to_confirm
self.label = pay_to_confirm
else:
label = register_now
self.label = register_now
elif reg_open:
label = register_now
if label:
w(u'<div class="conferenceBox">')
w(u'<div id="confRegister">')
w(u'<a href="%s">%s</a>' % (xml_escape(conf.absolute_url()+'/registration'), xml_escape(label)))
w(u'</div></div>')
self.label = register_now
if self.label is None:
raise component.EmptyComponent()
def render_body(self, w):
label = self._cw._(self.label)
w(u'<div class="conferenceBox">')
w(u'<div id="confRegister">')
w(u'<a href="%s">%s</a>' % (xml_escape(self.conf.absolute_url()+'/registration'), xml_escape(label)))
w(u'</div></div>')
# debugging purpose
return self.label
class ConferenceRegistrationLayout(Layout):
__select__ = Layout.__select__ & match_context('left') & match_view('confregistrationbox')
# raw rendering instead of default box layout (no extra div)
def render(self, w):
if self.init_rendering():
view = self.cw_extra_kwargs['view']
view.render_body(w)
class CmtShoppingCartEntityFormRenderer(ShoppingCartEntityFormRenderer):
......
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