110 Here is the code, samples from my cube's `views.py` file: |
110 Here is the code, samples from my cube's `views.py` file: |
111 |
111 |
112 .. sourcecode:: python |
112 .. sourcecode:: python |
113 |
113 |
114 from cubicweb.selectors import is_instance |
114 from cubicweb.selectors import is_instance |
115 from cubicweb.web import box |
115 from cubicweb.web import component |
116 from cubicweb.web.views import basetemplates, error |
116 from cubicweb.web.views import error |
117 |
117 |
118 class FourOhFour(error.FourOhFour): |
118 class FourOhFour(error.FourOhFour): |
119 __select__ = error.FourOhFour.__select__ & anonymous_user() |
119 __select__ = error.FourOhFour.__select__ & anonymous_user() |
120 |
120 |
121 def call(self): |
121 def call(self): |
122 self.w(u"<h1>%s</h1>" % self._cw._('this resource does not exist')) |
122 self.w(u"<h1>%s</h1>" % self._cw._('this resource does not exist')) |
123 self.w(u"<p>%s</p>" % self._cw._('have you tried to login?')) |
123 self.w(u"<p>%s</p>" % self._cw._('have you tried to login?')) |
124 |
124 |
125 class LoginBox(box.BoxTemplate, basetemplates.LogFormView): |
125 |
|
126 class LoginBox(component.CtxComponent): |
126 """display a box containing links to all startup views""" |
127 """display a box containing links to all startup views""" |
127 __regid__ = 'sytweb.loginbox' |
128 __regid__ = 'sytweb.loginbox' |
128 __select__ = box.BoxTemplate.__select__ & anonymous_user() |
129 __select__ = component.CtxComponent.__select__ & anonymous_user() |
129 |
130 |
130 title = _('Authenticate yourself') |
131 title = _('Authenticate yourself') |
131 order = 70 |
132 order = 70 |
132 |
133 |
133 def call(self, **kwargs): |
134 def render_body(self, w): |
134 self.w(u'<div class="sideBoxTitle"><span>%s</span></div>' % self.title) |
135 cw = self._cw |
135 self.w(u'<div class="sideBox"><div class="sideBoxBody">') |
136 form = cw.vreg['forms'].select('logform', cw) |
136 self.login_form('loginBox') |
137 form.render(w=w, table_class='', display_progress_div=False) |
137 self.w(u'</div></div>') |
|
138 |
138 |
139 The first class provides a new specific implementation of the default page you |
139 The first class provides a new specific implementation of the default page you |
140 get on 404 error, to display an adapted message to anonymous user. |
140 get on 404 error, to display an adapted message to anonymous user. |
141 |
141 |
142 .. Note:: |
142 .. Note:: |
145 since the additional `anonymous_user()` selector gives it a higher score than |
145 since the additional `anonymous_user()` selector gives it a higher score than |
146 the default, and not for authenticated since this selector will return 0 in |
146 the default, and not for authenticated since this selector will return 0 in |
147 such case (hence the object won't be selectable) |
147 such case (hence the object won't be selectable) |
148 |
148 |
149 The second class defines a simple box, that will be displayed by default with |
149 The second class defines a simple box, that will be displayed by default with |
150 boxes in the left column, thanks to default `box.BoxTemplate`'selector. The HTML |
150 boxes in the left column, thanks to default :class:`component.CtxComponent` |
151 is written to match default CubicWeb boxes style. To get the actual login form, |
151 selector. The HTML is written to match default CubicWeb boxes style. The code |
152 we inherit from the `LogFormView` view which provides a `login_form` method |
152 fetch the actual login form and render it. |
153 (handling some stuff under the cover for us, hence the multiple inheritance), that |
|
154 we simply have to call to get the form's HTML. |
|
155 |
153 |
156 |
154 |
157 .. figure:: ../../images/tutos-photowebsite_login-box.png |
155 .. figure:: ../../images/tutos-photowebsite_login-box.png |
158 :alt: login box / 404 screenshot |
156 :alt: login box / 404 screenshot |
159 |
157 |