web/views/basetemplates.py
changeset 5590 a56eb02f9ce7
parent 5479 6ba3587c5cda
parent 5588 377c9adfe81e
child 5849 9db65b381028
equal deleted inserted replaced
5578:6b9fee0c5c42 5590:a56eb02f9ce7
     1 # -*- coding: utf-8 -*-
       
     2 # copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     1 # copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     3 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     4 #
     3 #
     5 # This file is part of CubicWeb.
     4 # This file is part of CubicWeb.
     6 #
     5 #
    14 # FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
    13 # FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
    15 # details.
    14 # details.
    16 #
    15 #
    17 # You should have received a copy of the GNU Lesser General Public License along
    16 # You should have received a copy of the GNU Lesser General Public License along
    18 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    19 """default templates for CubicWeb web client
    18 """default templates for CubicWeb web client"""
    20 
    19 
    21 """
       
    22 __docformat__ = "restructuredtext en"
    20 __docformat__ = "restructuredtext en"
    23 
    21 
    24 from logilab.mtconverter import xml_escape
    22 from logilab.mtconverter import xml_escape
    25 from logilab.common.deprecation import class_renamed
    23 from logilab.common.deprecation import class_renamed
    26 
    24 
    27 from cubicweb.appobject import objectify_selector
    25 from cubicweb.appobject import objectify_selector
    28 from cubicweb.selectors import match_kwargs, no_cnx
    26 from cubicweb.selectors import match_kwargs, no_cnx, anonymous_user
    29 from cubicweb.view import View, MainTemplate, NOINDEX, NOFOLLOW
    27 from cubicweb.view import View, MainTemplate, NOINDEX, NOFOLLOW
    30 from cubicweb.utils import UStringIO
    28 from cubicweb.utils import UStringIO
    31 from cubicweb.schema import display_name
    29 from cubicweb.schema import display_name
    32 from cubicweb.web import component, formfields as ff, formwidgets as fw
    30 from cubicweb.web import component, formfields as ff, formwidgets as fw
    33 from cubicweb.web.views import forms
    31 from cubicweb.web.views import forms
    58         w(u'<title>%s</title>\n' % xml_escape(page_title))
    56         w(u'<title>%s</title>\n' % xml_escape(page_title))
    59 
    57 
    60 
    58 
    61 class LogInTemplate(LogInOutTemplate):
    59 class LogInTemplate(LogInOutTemplate):
    62     __regid__ = 'login'
    60     __regid__ = 'login'
       
    61     __select__ = anonymous_user()
    63     title = 'log in'
    62     title = 'log in'
    64 
    63 
    65     def content(self, w):
    64     def content(self, w):
    66         self.wview('logform', rset=self.cw_rset, id='loginBox', klass='')
    65         self.wview('logform', rset=self.cw_rset, id='loginBox', klass='')
    67 
    66 
    77         if self._cw.vreg.config['anonymous-user']:
    76         if self._cw.vreg.config['anonymous-user']:
    78             indexurl = self._cw.build_url('view', vid='index', __message=msg)
    77             indexurl = self._cw.build_url('view', vid='index', __message=msg)
    79             w(u'<p><a href="%s">%s</a><p>' % (
    78             w(u'<p><a href="%s">%s</a><p>' % (
    80                 xml_escape(indexurl),
    79                 xml_escape(indexurl),
    81                 self._cw._('go back to the index page')))
    80                 self._cw._('go back to the index page')))
       
    81 
    82 
    82 
    83 @objectify_selector
    83 @objectify_selector
    84 def templatable_view(cls, req, rset, *args, **kwargs):
    84 def templatable_view(cls, req, rset, *args, **kwargs):
    85     view = kwargs.pop('view', None)
    85     view = kwargs.pop('view', None)
    86     if view is None:
    86     if view is None:
   446     __password = ff.StringField('__password', label=_('password'),
   446     __password = ff.StringField('__password', label=_('password'),
   447                                 widget=fw.PasswordSingleInput({'class': 'data'}))
   447                                 widget=fw.PasswordSingleInput({'class': 'data'}))
   448     form_buttons = [fw.SubmitButton(label=_('log in'),
   448     form_buttons = [fw.SubmitButton(label=_('log in'),
   449                                     attrs={'class': 'loginButton'})]
   449                                     attrs={'class': 'loginButton'})]
   450 
   450 
   451     @property
   451     def form_action(self):
   452     def action(self):
   452         if self.action is None:
   453         return xml_escape(login_form_url(self._cw))
   453             return login_form_url(self._cw)
       
   454         return super(LogForm, self).form_action()
   454 
   455 
   455 
   456 
   456 class LogFormView(View):
   457 class LogFormView(View):
   457     __regid__ = 'logform'
   458     __regid__ = 'logform'
   458     __select__ = match_kwargs('id', 'klass')
   459     __select__ = match_kwargs('id', 'klass')