cubicweb/web/request.py
changeset 11913 4516c3956d46
parent 11892 08cf02efc7ce
child 12053 c3c9f2e1424c
equal deleted inserted replaced
11912:c9e6df20e5a4 11913:4516c3956d46
   103     """abstract HTTP request, should be extended according to the HTTP backend
   103     """abstract HTTP request, should be extended according to the HTTP backend
   104     Immutable attributes that describe the received query and generic configuration
   104     Immutable attributes that describe the received query and generic configuration
   105     """
   105     """
   106     ajax_request = False # to be set to True by ajax controllers
   106     ajax_request = False # to be set to True by ajax controllers
   107 
   107 
   108     def __init__(self, vreg, https=False, form=None, headers=None):
   108     def __init__(self, vreg, form=None, headers=None):
   109         """
   109         """
   110         :vreg: Vregistry,
   110         :vreg: Vregistry,
   111         :https: boolean, s this a https request
       
   112         :form: Forms value
   111         :form: Forms value
   113         :headers: dict, request header
   112         :headers: dict, request header
   114         """
   113         """
   115         super(_CubicWebRequestBase, self).__init__(vreg)
   114         super(_CubicWebRequestBase, self).__init__(vreg)
   116         #: (Boolean) Is this an https request.
   115         #: User interface property (see :ref:`uiprops`)
   117         self.https = https
       
   118         #: User interface property (vary with https) (see :ref:`uiprops`)
       
   119         self.uiprops = None
   116         self.uiprops = None
   120         #: url for serving datadir (vary with https) (see :ref:`resources`)
   117         #: url for serving datadir (see :ref:`resources`)
   121         self.datadir_url = None
   118         self.datadir_url = None
   122         if https and vreg.config.https_uiprops is not None:
   119         self.uiprops = vreg.config.uiprops
   123             self.uiprops = vreg.config.https_uiprops
   120         self.datadir_url = vreg.config.datadir_url
   124         else:
       
   125             self.uiprops = vreg.config.uiprops
       
   126         if https and vreg.config.https_datadir_url is not None:
       
   127             self.datadir_url = vreg.config.https_datadir_url
       
   128         else:
       
   129             self.datadir_url = vreg.config.datadir_url
       
   130         #: enable UStringIO's write tracing
   121         #: enable UStringIO's write tracing
   131         self.tracehtml = False
   122         self.tracehtml = False
   132         if vreg.config.debugmode:
   123         if vreg.config.debugmode:
   133             self.tracehtml = bool(form.pop('_cwtracehtml', False))
   124             self.tracehtml = bool(form.pop('_cwtracehtml', False))
   134         #: raw html headers that can be added from any view
   125         #: raw html headers that can be added from any view
   177         warn('[3.15] self._cw.json_request is deprecated, use self._cw.ajax_request instead',
   168         warn('[3.15] self._cw.json_request is deprecated, use self._cw.ajax_request instead',
   178              DeprecationWarning, stacklevel=2)
   169              DeprecationWarning, stacklevel=2)
   179         self.ajax_request = value
   170         self.ajax_request = value
   180     json_request = property(_get_json_request, _set_json_request)
   171     json_request = property(_get_json_request, _set_json_request)
   181 
   172 
   182     def _base_url(self, secure=None):
       
   183         """return the root url of the instance
       
   184 
       
   185         secure = False -> base-url
       
   186         secure = None  -> https-url if req.https
       
   187         secure = True  -> https if it exist
       
   188         """
       
   189         if secure is None:
       
   190             secure = self.https
       
   191         base_url = None
       
   192         if secure:
       
   193             base_url = self.vreg.config.get('https-url')
       
   194         if base_url is None:
       
   195             base_url = super(_CubicWebRequestBase, self)._base_url()
       
   196         return base_url
       
   197 
       
   198     @property
   173     @property
   199     def authmode(self):
   174     def authmode(self):
   200         """Authentification mode of the instance
   175         """Authentification mode of the instance
   201         (see :ref:`WebServerConfig`)"""
   176         (see :ref:`WebServerConfig`)"""
   202         return self.vreg.config['auth-mode']
   177         return self.vreg.config['auth-mode']
   950 
   925 
   951 class ConnectionCubicWebRequestBase(_CubicWebRequestBase):
   926 class ConnectionCubicWebRequestBase(_CubicWebRequestBase):
   952     cnx = None
   927     cnx = None
   953     session = None
   928     session = None
   954 
   929 
   955     def __init__(self, vreg, https=False, form=None, headers={}):
   930     def __init__(self, vreg, form=None, headers={}):
   956         """"""
   931         """"""
   957         self.vreg = vreg
   932         self.vreg = vreg
   958         try:
   933         try:
   959             # no vreg or config which doesn't handle translations
   934             # no vreg or config which doesn't handle translations
   960             self.translations = vreg.config.translations
   935             self.translations = vreg.config.translations
   961         except AttributeError:
   936         except AttributeError:
   962             self.translations = {}
   937             self.translations = {}
   963         super(ConnectionCubicWebRequestBase, self).__init__(vreg, https=https,
   938         super(ConnectionCubicWebRequestBase, self).__init__(vreg, form=form, headers=headers)
   964                                                        form=form, headers=headers)
       
   965         self.session = _MockAnonymousSession()
   939         self.session = _MockAnonymousSession()
   966         self.cnx = self.user = _NeedAuthAccessMock()
   940         self.cnx = self.user = _NeedAuthAccessMock()
   967 
   941 
   968     @property
   942     @property
   969     def transaction_data(self):
   943     def transaction_data(self):