author | pierre-yves |
Mon, 27 May 2013 16:43:02 +0200 | |
changeset 9024 | 701b19785f1d |
parent 9022 | a1cee6915ea3 |
child 9051 | 944d66870c6a |
permissions | -rw-r--r-- |
8544
3d049071957e
massive copyright update to avoid clutering later patches
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8538
diff
changeset
|
1 |
# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5290
diff
changeset
|
2 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5290
diff
changeset
|
3 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5290
diff
changeset
|
4 |
# This file is part of CubicWeb. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5290
diff
changeset
|
5 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5290
diff
changeset
|
6 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5290
diff
changeset
|
7 |
# terms of the GNU Lesser General Public License as published by the Free |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5290
diff
changeset
|
8 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5290
diff
changeset
|
9 |
# any later version. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5290
diff
changeset
|
10 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5290
diff
changeset
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5290
diff
changeset
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5290
diff
changeset
|
14 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5290
diff
changeset
|
15 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5290
diff
changeset
|
16 |
# You should have received a copy of the GNU Lesser General Public License along |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5290
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
6141
b8287e54b528
[web api] unify 'contentnav' (VComponent) and 'boxes' registries as 'ctxcomponents' (CtxComponent)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5924
diff
changeset
|
18 |
"""Base class for request/session""" |
2792
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
19 |
|
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
20 |
__docformat__ = "restructuredtext en" |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
21 |
|
4933
433174d9394f
add missing warn imports
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4899
diff
changeset
|
22 |
from warnings import warn |
4891
90203ec7b3e3
[url] new rebuild_url method on base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4466
diff
changeset
|
23 |
from urlparse import urlsplit, urlunsplit |
2808
497424219fb0
fix urlquote imports
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2798
diff
changeset
|
24 |
from urllib import quote as urlquote, unquote as urlunquote |
2796
14d2c69e12c4
move get_cache to base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2792
diff
changeset
|
25 |
from datetime import time, datetime, timedelta |
4891
90203ec7b3e3
[url] new rebuild_url method on base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4466
diff
changeset
|
26 |
from cgi import parse_qs, parse_qsl |
2792
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
27 |
|
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
28 |
from logilab.common.decorators import cached |
3659 | 29 |
from logilab.common.deprecation import deprecated |
4466
8b0ca7904820
moved generic datetime manipulation function to lgc
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4459
diff
changeset
|
30 |
from logilab.common.date import ustrftime, strptime, todate, todatetime |
2792
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
31 |
|
8748
f5027f8d2478
drop typed_eid() in favour of int() (closes #2742462)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8596
diff
changeset
|
32 |
from cubicweb import Unauthorized, NoSelectableObject, uilib |
2792
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
33 |
from cubicweb.rset import ResultSet |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
34 |
|
2796
14d2c69e12c4
move get_cache to base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2792
diff
changeset
|
35 |
ONESECOND = timedelta(0, 1, 0) |
14d2c69e12c4
move get_cache to base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2792
diff
changeset
|
36 |
CACHE_REGISTRY = {} |
14d2c69e12c4
move get_cache to base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2792
diff
changeset
|
37 |
|
7116
dfd4680a23f0
[session] add find_entities and find_one_entity to session/request API (closes #1550045)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6750
diff
changeset
|
38 |
class FindEntityError(Exception): |
dfd4680a23f0
[session] add find_entities and find_one_entity to session/request API (closes #1550045)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6750
diff
changeset
|
39 |
"""raised when find_one_entity() can not return one and only one entity""" |
2796
14d2c69e12c4
move get_cache to base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2792
diff
changeset
|
40 |
|
14d2c69e12c4
move get_cache to base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2792
diff
changeset
|
41 |
class Cache(dict): |
14d2c69e12c4
move get_cache to base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2792
diff
changeset
|
42 |
def __init__(self): |
14d2c69e12c4
move get_cache to base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2792
diff
changeset
|
43 |
super(Cache, self).__init__() |
14d2c69e12c4
move get_cache to base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2792
diff
changeset
|
44 |
_now = datetime.now() |
14d2c69e12c4
move get_cache to base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2792
diff
changeset
|
45 |
self.cache_creation_date = _now |
14d2c69e12c4
move get_cache to base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2792
diff
changeset
|
46 |
self.latest_cache_lookup = _now |
14d2c69e12c4
move get_cache to base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2792
diff
changeset
|
47 |
|
14d2c69e12c4
move get_cache to base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2792
diff
changeset
|
48 |
|
2792
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
49 |
class RequestSessionBase(object): |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
50 |
"""base class containing stuff shared by server session and web request |
2825 | 51 |
|
52 |
request/session is the main resources accessor, mainly through it's vreg |
|
53 |
attribute: |
|
5290
15846058378b
[doc/book] fix a bit the request chapter, add autodoc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5199
diff
changeset
|
54 |
|
15846058378b
[doc/book] fix a bit the request chapter, add autodoc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5199
diff
changeset
|
55 |
:attribute vreg: the instance's registry |
15846058378b
[doc/book] fix a bit the request chapter, add autodoc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5199
diff
changeset
|
56 |
:attribute vreg.schema: the instance's schema |
15846058378b
[doc/book] fix a bit the request chapter, add autodoc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5199
diff
changeset
|
57 |
:attribute vreg.config: the instance's configuration |
2792
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
58 |
""" |
8525
c09feae04094
[entity edition] don't remove values from attribute cache on the repository side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8309
diff
changeset
|
59 |
is_request = True # False for repository session |
c09feae04094
[entity edition] don't remove values from attribute cache on the repository side
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8309
diff
changeset
|
60 |
|
2792
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
61 |
def __init__(self, vreg): |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
62 |
self.vreg = vreg |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
63 |
try: |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
64 |
encoding = vreg.property_value('ui.encoding') |
7815
2a164a9cf81c
[exceptions] stop catching any exception in various places (closes #1942716)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7543
diff
changeset
|
65 |
except Exception: # no vreg or property not registered |
2792
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
66 |
encoding = 'utf-8' |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
67 |
self.encoding = encoding |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
68 |
# cache result of execution for (rql expr / eids), |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
69 |
# should be emptied on commit/rollback of the server session / web |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
70 |
# connection |
8847
074f9f385f6b
[req] explicit `user` attribute
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8791
diff
changeset
|
71 |
self.user = None |
2792
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
72 |
self.local_perm_cache = {} |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
73 |
self._ = unicode |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
74 |
|
8538
00597256de18
[request/session] refactor language handling: don't attempt to sync web/repo languages
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8525
diff
changeset
|
75 |
def set_language(self, lang): |
00597256de18
[request/session] refactor language handling: don't attempt to sync web/repo languages
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8525
diff
changeset
|
76 |
"""install i18n configuration for `lang` translation. |
00597256de18
[request/session] refactor language handling: don't attempt to sync web/repo languages
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8525
diff
changeset
|
77 |
|
00597256de18
[request/session] refactor language handling: don't attempt to sync web/repo languages
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8525
diff
changeset
|
78 |
Raises :exc:`KeyError` if translation doesn't exist. |
00597256de18
[request/session] refactor language handling: don't attempt to sync web/repo languages
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8525
diff
changeset
|
79 |
""" |
00597256de18
[request/session] refactor language handling: don't attempt to sync web/repo languages
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8525
diff
changeset
|
80 |
self.lang = lang |
00597256de18
[request/session] refactor language handling: don't attempt to sync web/repo languages
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8525
diff
changeset
|
81 |
gettext, pgettext = self.vreg.config.translations[lang] |
00597256de18
[request/session] refactor language handling: don't attempt to sync web/repo languages
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8525
diff
changeset
|
82 |
# use _cw.__ to translate a message without registering it to the catalog |
00597256de18
[request/session] refactor language handling: don't attempt to sync web/repo languages
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8525
diff
changeset
|
83 |
self._ = self.__ = gettext |
00597256de18
[request/session] refactor language handling: don't attempt to sync web/repo languages
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8525
diff
changeset
|
84 |
self.pgettext = pgettext |
00597256de18
[request/session] refactor language handling: don't attempt to sync web/repo languages
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8525
diff
changeset
|
85 |
|
8585
3f60f416dddb
[dbapi] provide get_option_value over DBAPIRequest (closes #2515522)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8309
diff
changeset
|
86 |
def get_option_value(self, option, foreid=None): |
3f60f416dddb
[dbapi] provide get_option_value over DBAPIRequest (closes #2515522)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8309
diff
changeset
|
87 |
raise NotImplementedError |
3f60f416dddb
[dbapi] provide get_option_value over DBAPIRequest (closes #2515522)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8309
diff
changeset
|
88 |
|
2792
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
89 |
def property_value(self, key): |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
90 |
"""return value of the property with the given key, giving priority to |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
91 |
user specific value if any, else using site value |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
92 |
""" |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
93 |
if self.user: |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
94 |
return self.user.property_value(key) |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
95 |
return self.vreg.property_value(key) |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
96 |
|
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
97 |
def etype_rset(self, etype, size=1): |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
98 |
"""return a fake result set for a particular entity type""" |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
99 |
rset = ResultSet([('A',)]*size, '%s X' % etype, |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
100 |
description=[(etype,)]*size) |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
101 |
def get_entity(row, col=0, etype=etype, req=self, rset=rset): |
7407
a78cc15227ef
[deprecation] drop remaining warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7121
diff
changeset
|
102 |
return req.vreg['etypes'].etype_class(etype)(req, rset, row, col) |
2792
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
103 |
rset.get_entity = get_entity |
4850
bd640b137f50
[refactor] drop rset.vreg attribute, vreg should be accessed through rset.req. Also kill decorate_rset, simply set rset.req where we were calling this method.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
104 |
rset.req = self |
bd640b137f50
[refactor] drop rset.vreg attribute, vreg should be accessed through rset.req. Also kill decorate_rset, simply set rset.req where we were calling this method.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
105 |
return rset |
2792
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
106 |
|
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
107 |
def eid_rset(self, eid, etype=None): |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
108 |
"""return a result set for the given eid without doing actual query |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
109 |
(we have the eid, we can suppose it exists and user has access to the |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
110 |
entity) |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
111 |
""" |
8748
f5027f8d2478
drop typed_eid() in favour of int() (closes #2742462)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8596
diff
changeset
|
112 |
eid = int(eid) |
2792
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
113 |
if etype is None: |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
114 |
etype = self.describe(eid)[0] |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
115 |
rset = ResultSet([(eid,)], 'Any X WHERE X eid %(x)s', {'x': eid}, |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
116 |
[(etype,)]) |
4850
bd640b137f50
[refactor] drop rset.vreg attribute, vreg should be accessed through rset.req. Also kill decorate_rset, simply set rset.req where we were calling this method.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
117 |
rset.req = self |
bd640b137f50
[refactor] drop rset.vreg attribute, vreg should be accessed through rset.req. Also kill decorate_rset, simply set rset.req where we were calling this method.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
118 |
return rset |
2792
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
119 |
|
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
120 |
def empty_rset(self): |
5459
6e561796804c
[doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5426
diff
changeset
|
121 |
""" return a guaranteed empty result """ |
4850
bd640b137f50
[refactor] drop rset.vreg attribute, vreg should be accessed through rset.req. Also kill decorate_rset, simply set rset.req where we were calling this method.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
122 |
rset = ResultSet([], 'Any X WHERE X eid -1') |
bd640b137f50
[refactor] drop rset.vreg attribute, vreg should be accessed through rset.req. Also kill decorate_rset, simply set rset.req where we were calling this method.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
123 |
rset.req = self |
bd640b137f50
[refactor] drop rset.vreg attribute, vreg should be accessed through rset.req. Also kill decorate_rset, simply set rset.req where we were calling this method.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
124 |
return rset |
2792
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
125 |
|
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
126 |
def entity_from_eid(self, eid, etype=None): |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
127 |
"""return an entity instance for the given eid. No query is done""" |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
128 |
try: |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
129 |
return self.entity_cache(eid) |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
130 |
except KeyError: |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
131 |
rset = self.eid_rset(eid, etype) |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
132 |
entity = rset.get_entity(0, 0) |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
133 |
self.set_entity_cache(entity) |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
134 |
return entity |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
135 |
|
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
136 |
def entity_cache(self, eid): |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
137 |
raise KeyError |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
138 |
|
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
139 |
def set_entity_cache(self, entity): |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
140 |
pass |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
141 |
|
4835
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4466
diff
changeset
|
142 |
def create_entity(self, etype, **kwargs): |
3629
559cad62c786
backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3163
diff
changeset
|
143 |
"""add a new entity of the given type |
559cad62c786
backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3163
diff
changeset
|
144 |
|
559cad62c786
backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3163
diff
changeset
|
145 |
Example (in a shell session): |
559cad62c786
backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3163
diff
changeset
|
146 |
|
4835
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4466
diff
changeset
|
147 |
>>> c = create_entity('Company', name=u'Logilab') |
5924
b218df942dd4
[book] update rql documentation and some erroneous/deprecated examples
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5736
diff
changeset
|
148 |
>>> create_entity('Person', firstname=u'John', surname=u'Doe', |
4835
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4466
diff
changeset
|
149 |
... works_for=c) |
3674
387d51af966d
backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3659
diff
changeset
|
150 |
|
3629
559cad62c786
backport stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3163
diff
changeset
|
151 |
""" |
5199
ebb50479d2ab
[entity] move req.create_entity content to a cw_instantiate factory method on entity classes, so cube developpers will be able to easily customize instance creation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4933
diff
changeset
|
152 |
cls = self.vreg['etypes'].etype_class(etype) |
ebb50479d2ab
[entity] move req.create_entity content to a cw_instantiate factory method on entity classes, so cube developpers will be able to easily customize instance creation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4933
diff
changeset
|
153 |
return cls.cw_instantiate(self.execute, **kwargs) |
2968
0e3460341023
somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2825
diff
changeset
|
154 |
|
7116
dfd4680a23f0
[session] add find_entities and find_one_entity to session/request API (closes #1550045)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6750
diff
changeset
|
155 |
def find_entities(self, etype, **kwargs): |
dfd4680a23f0
[session] add find_entities and find_one_entity to session/request API (closes #1550045)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6750
diff
changeset
|
156 |
"""find entities of the given type and attribute values. |
dfd4680a23f0
[session] add find_entities and find_one_entity to session/request API (closes #1550045)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6750
diff
changeset
|
157 |
|
dfd4680a23f0
[session] add find_entities and find_one_entity to session/request API (closes #1550045)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6750
diff
changeset
|
158 |
>>> users = find_entities('CWGroup', name=u'users') |
dfd4680a23f0
[session] add find_entities and find_one_entity to session/request API (closes #1550045)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6750
diff
changeset
|
159 |
>>> groups = find_entities('CWGroup') |
dfd4680a23f0
[session] add find_entities and find_one_entity to session/request API (closes #1550045)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6750
diff
changeset
|
160 |
""" |
dfd4680a23f0
[session] add find_entities and find_one_entity to session/request API (closes #1550045)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6750
diff
changeset
|
161 |
parts = ['Any X WHERE X is %s' % etype] |
dfd4680a23f0
[session] add find_entities and find_one_entity to session/request API (closes #1550045)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6750
diff
changeset
|
162 |
parts.extend('X %(attr)s %%(%(attr)s)s' % {'attr': attr} for attr in kwargs) |
dfd4680a23f0
[session] add find_entities and find_one_entity to session/request API (closes #1550045)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6750
diff
changeset
|
163 |
return self.execute(', '.join(parts), kwargs).entities() |
dfd4680a23f0
[session] add find_entities and find_one_entity to session/request API (closes #1550045)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6750
diff
changeset
|
164 |
|
dfd4680a23f0
[session] add find_entities and find_one_entity to session/request API (closes #1550045)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6750
diff
changeset
|
165 |
def find_one_entity(self, etype, **kwargs): |
dfd4680a23f0
[session] add find_entities and find_one_entity to session/request API (closes #1550045)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6750
diff
changeset
|
166 |
"""find one entity of the given type and attribute values. |
7121 | 167 |
raise :exc:`FindEntityError` if can not return one and only one entity. |
7116
dfd4680a23f0
[session] add find_entities and find_one_entity to session/request API (closes #1550045)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6750
diff
changeset
|
168 |
|
dfd4680a23f0
[session] add find_entities and find_one_entity to session/request API (closes #1550045)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6750
diff
changeset
|
169 |
>>> users = find_one_entity('CWGroup', name=u'users') |
dfd4680a23f0
[session] add find_entities and find_one_entity to session/request API (closes #1550045)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6750
diff
changeset
|
170 |
>>> groups = find_one_entity('CWGroup') |
dfd4680a23f0
[session] add find_entities and find_one_entity to session/request API (closes #1550045)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6750
diff
changeset
|
171 |
Exception() |
dfd4680a23f0
[session] add find_entities and find_one_entity to session/request API (closes #1550045)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6750
diff
changeset
|
172 |
""" |
dfd4680a23f0
[session] add find_entities and find_one_entity to session/request API (closes #1550045)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6750
diff
changeset
|
173 |
parts = ['Any X WHERE X is %s' % etype] |
dfd4680a23f0
[session] add find_entities and find_one_entity to session/request API (closes #1550045)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6750
diff
changeset
|
174 |
parts.extend('X %(attr)s %%(%(attr)s)s' % {'attr': attr} for attr in kwargs) |
dfd4680a23f0
[session] add find_entities and find_one_entity to session/request API (closes #1550045)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6750
diff
changeset
|
175 |
rql = ', '.join(parts) |
dfd4680a23f0
[session] add find_entities and find_one_entity to session/request API (closes #1550045)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6750
diff
changeset
|
176 |
rset = self.execute(rql, kwargs) |
dfd4680a23f0
[session] add find_entities and find_one_entity to session/request API (closes #1550045)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6750
diff
changeset
|
177 |
if len(rset) != 1: |
dfd4680a23f0
[session] add find_entities and find_one_entity to session/request API (closes #1550045)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6750
diff
changeset
|
178 |
raise FindEntityError('Found %i entitie(s) when 1 was expected (rql=%s ; %s)' |
dfd4680a23f0
[session] add find_entities and find_one_entity to session/request API (closes #1550045)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6750
diff
changeset
|
179 |
% (len(rset), rql, repr(kwargs))) |
dfd4680a23f0
[session] add find_entities and find_one_entity to session/request API (closes #1550045)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6750
diff
changeset
|
180 |
return rset.get_entity(0,0) |
dfd4680a23f0
[session] add find_entities and find_one_entity to session/request API (closes #1550045)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6750
diff
changeset
|
181 |
|
2792
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
182 |
def ensure_ro_rql(self, rql): |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
183 |
"""raise an exception if the given rql is not a select query""" |
6747
63bf61e4e130
[security] fix access control problem
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6321
diff
changeset
|
184 |
first = rql.split(None, 1)[0].lower() |
2792
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
185 |
if first in ('insert', 'set', 'delete'): |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
186 |
raise Unauthorized(self._('only select queries are authorized')) |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
187 |
|
2796
14d2c69e12c4
move get_cache to base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2792
diff
changeset
|
188 |
def get_cache(self, cachename): |
5290
15846058378b
[doc/book] fix a bit the request chapter, add autodoc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5199
diff
changeset
|
189 |
"""cachename should be dotted names as in : |
15846058378b
[doc/book] fix a bit the request chapter, add autodoc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
5199
diff
changeset
|
190 |
|
2796
14d2c69e12c4
move get_cache to base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2792
diff
changeset
|
191 |
- cubicweb.mycache |
14d2c69e12c4
move get_cache to base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2792
diff
changeset
|
192 |
- cubes.blog.mycache |
14d2c69e12c4
move get_cache to base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2792
diff
changeset
|
193 |
- etc. |
14d2c69e12c4
move get_cache to base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2792
diff
changeset
|
194 |
""" |
14d2c69e12c4
move get_cache to base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2792
diff
changeset
|
195 |
if cachename in CACHE_REGISTRY: |
14d2c69e12c4
move get_cache to base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2792
diff
changeset
|
196 |
cache = CACHE_REGISTRY[cachename] |
14d2c69e12c4
move get_cache to base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2792
diff
changeset
|
197 |
else: |
14d2c69e12c4
move get_cache to base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2792
diff
changeset
|
198 |
cache = CACHE_REGISTRY[cachename] = Cache() |
14d2c69e12c4
move get_cache to base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2792
diff
changeset
|
199 |
_now = datetime.now() |
14d2c69e12c4
move get_cache to base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2792
diff
changeset
|
200 |
if _now > cache.latest_cache_lookup + ONESECOND: |
14d2c69e12c4
move get_cache to base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2792
diff
changeset
|
201 |
ecache = self.execute( |
14d2c69e12c4
move get_cache to base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2792
diff
changeset
|
202 |
'Any C,T WHERE C is CWCache, C name %(name)s, C timestamp T', |
14d2c69e12c4
move get_cache to base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2792
diff
changeset
|
203 |
{'name':cachename}).get_entity(0,0) |
14d2c69e12c4
move get_cache to base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2792
diff
changeset
|
204 |
cache.latest_cache_lookup = _now |
14d2c69e12c4
move get_cache to base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2792
diff
changeset
|
205 |
if not ecache.valid(cache.cache_creation_date): |
14d2c69e12c4
move get_cache to base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2792
diff
changeset
|
206 |
cache.clear() |
14d2c69e12c4
move get_cache to base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2792
diff
changeset
|
207 |
cache.cache_creation_date = _now |
14d2c69e12c4
move get_cache to base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2792
diff
changeset
|
208 |
return cache |
14d2c69e12c4
move get_cache to base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2792
diff
changeset
|
209 |
|
2792
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
210 |
# url generation methods ################################################## |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
211 |
|
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
212 |
def build_url(self, *args, **kwargs): |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
213 |
"""return an absolute URL using params dictionary key/values as URL |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
214 |
parameters. Values are automatically URL quoted, and the |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
215 |
publishing method to use may be specified or will be guessed. |
6321
a8a33679f4dd
[req] build_url: detect None values in arguments and raise ValueError
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6141
diff
changeset
|
216 |
|
8309
48ef505aa9f9
[request] gather all base_url logic in a single place (closes #2200756)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8238
diff
changeset
|
217 |
if ``__secure__`` argument is True, the request will try to build a |
48ef505aa9f9
[request] gather all base_url logic in a single place (closes #2200756)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8238
diff
changeset
|
218 |
https url. |
48ef505aa9f9
[request] gather all base_url logic in a single place (closes #2200756)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8238
diff
changeset
|
219 |
|
6321
a8a33679f4dd
[req] build_url: detect None values in arguments and raise ValueError
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6141
diff
changeset
|
220 |
raises :exc:`ValueError` if None is found in arguments |
2792
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
221 |
""" |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
222 |
# use *args since we don't want first argument to be "anonymous" to |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
223 |
# avoid potential clash with kwargs |
9022
a1cee6915ea3
[req] drop from_controller on non WebRequest object (Closes #2901079)
pierre-yves
parents:
8847
diff
changeset
|
224 |
method = None |
2798
9c650701cb17
stop using controller class attribute, allowing to deprecate appobject.build_url in favor of req.build_url
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2796
diff
changeset
|
225 |
if args: |
9c650701cb17
stop using controller class attribute, allowing to deprecate appobject.build_url in favor of req.build_url
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2796
diff
changeset
|
226 |
assert len(args) == 1, 'only 0 or 1 non-named-argument expected' |
9c650701cb17
stop using controller class attribute, allowing to deprecate appobject.build_url in favor of req.build_url
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2796
diff
changeset
|
227 |
method = args[0] |
9022
a1cee6915ea3
[req] drop from_controller on non WebRequest object (Closes #2901079)
pierre-yves
parents:
8847
diff
changeset
|
228 |
if method is None: |
a1cee6915ea3
[req] drop from_controller on non WebRequest object (Closes #2901079)
pierre-yves
parents:
8847
diff
changeset
|
229 |
method = 'view' |
2798
9c650701cb17
stop using controller class attribute, allowing to deprecate appobject.build_url in favor of req.build_url
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2796
diff
changeset
|
230 |
# XXX I (adim) think that if method is passed explicitly, we should |
9c650701cb17
stop using controller class attribute, allowing to deprecate appobject.build_url in favor of req.build_url
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2796
diff
changeset
|
231 |
# not try to process it and directly call req.build_url() |
2792
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
232 |
base_url = kwargs.pop('base_url', None) |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
233 |
if base_url is None: |
8309
48ef505aa9f9
[request] gather all base_url logic in a single place (closes #2200756)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8238
diff
changeset
|
234 |
secure = kwargs.pop('__secure__', None) |
48ef505aa9f9
[request] gather all base_url logic in a single place (closes #2200756)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8238
diff
changeset
|
235 |
base_url = self.base_url(secure=secure) |
2792
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
236 |
if '_restpath' in kwargs: |
9022
a1cee6915ea3
[req] drop from_controller on non WebRequest object (Closes #2901079)
pierre-yves
parents:
8847
diff
changeset
|
237 |
assert method == 'view', repr(method) |
2792
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
238 |
path = kwargs.pop('_restpath') |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
239 |
else: |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
240 |
path = method |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
241 |
if not kwargs: |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
242 |
return u'%s%s' % (base_url, path) |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
243 |
return u'%s%s?%s' % (base_url, path, self.build_url_params(**kwargs)) |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
244 |
|
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
245 |
def build_url_params(self, **kwargs): |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
246 |
"""return encoded params to incorporate them in an URL""" |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
247 |
args = [] |
4892
7ee8f128be9e
[cleanup] use iteritems
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4891
diff
changeset
|
248 |
for param, values in kwargs.iteritems(): |
2792
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
249 |
if not isinstance(values, (list, tuple)): |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
250 |
values = (values,) |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
251 |
for value in values: |
6582
8eb7883b4223
[pylint] fix a bug of pylint detected errors and i18n pb (calling builtins._ instead of req._)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6321
diff
changeset
|
252 |
assert value is not None |
2792
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
253 |
args.append(u'%s=%s' % (param, self.url_quote(value))) |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
254 |
return '&'.join(args) |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
255 |
|
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
256 |
def url_quote(self, value, safe=''): |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
257 |
"""urllib.quote is not unicode safe, use this method to do the |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
258 |
necessary encoding / decoding. Also it's designed to quote each |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
259 |
part of a url path and so the '/' character will be encoded as well. |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
260 |
""" |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
261 |
if isinstance(value, unicode): |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
262 |
quoted = urlquote(value.encode(self.encoding), safe=safe) |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
263 |
return unicode(quoted, self.encoding) |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
264 |
return urlquote(str(value), safe=safe) |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
265 |
|
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
266 |
def url_unquote(self, quoted): |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
267 |
"""returns a unicode unquoted string |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
268 |
|
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
269 |
decoding is based on `self.encoding` which is the encoding |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
270 |
used in `url_quote` |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
271 |
""" |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
272 |
if isinstance(quoted, unicode): |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
273 |
quoted = quoted.encode(self.encoding) |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
274 |
try: |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
275 |
return unicode(urlunquote(quoted), self.encoding) |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
276 |
except UnicodeDecodeError: # might occurs on manually typed URLs |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
277 |
return unicode(urlunquote(quoted), 'iso-8859-1') |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
278 |
|
4300
03430023ce82
new url_parse_qs method on base request to parse unicode url formatted query strings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4222
diff
changeset
|
279 |
def url_parse_qsl(self, querystring): |
03430023ce82
new url_parse_qs method on base request to parse unicode url formatted query strings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4222
diff
changeset
|
280 |
"""return a list of (key, val) found in the url quoted query string""" |
03430023ce82
new url_parse_qs method on base request to parse unicode url formatted query strings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4222
diff
changeset
|
281 |
if isinstance(querystring, unicode): |
03430023ce82
new url_parse_qs method on base request to parse unicode url formatted query strings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4222
diff
changeset
|
282 |
querystring = querystring.encode(self.encoding) |
03430023ce82
new url_parse_qs method on base request to parse unicode url formatted query strings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4222
diff
changeset
|
283 |
for key, val in parse_qsl(querystring): |
03430023ce82
new url_parse_qs method on base request to parse unicode url formatted query strings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4222
diff
changeset
|
284 |
try: |
03430023ce82
new url_parse_qs method on base request to parse unicode url formatted query strings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4222
diff
changeset
|
285 |
yield unicode(key, self.encoding), unicode(val, self.encoding) |
03430023ce82
new url_parse_qs method on base request to parse unicode url formatted query strings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4222
diff
changeset
|
286 |
except UnicodeDecodeError: # might occurs on manually typed URLs |
03430023ce82
new url_parse_qs method on base request to parse unicode url formatted query strings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4222
diff
changeset
|
287 |
yield unicode(key, 'iso-8859-1'), unicode(val, 'iso-8859-1') |
03430023ce82
new url_parse_qs method on base request to parse unicode url formatted query strings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4222
diff
changeset
|
288 |
|
4891
90203ec7b3e3
[url] new rebuild_url method on base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4466
diff
changeset
|
289 |
|
90203ec7b3e3
[url] new rebuild_url method on base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4466
diff
changeset
|
290 |
def rebuild_url(self, url, **newparams): |
90203ec7b3e3
[url] new rebuild_url method on base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4466
diff
changeset
|
291 |
"""return the given url with newparams inserted. If any new params |
90203ec7b3e3
[url] new rebuild_url method on base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4466
diff
changeset
|
292 |
is already specified in the url, it's overriden by the new value |
90203ec7b3e3
[url] new rebuild_url method on base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4466
diff
changeset
|
293 |
|
90203ec7b3e3
[url] new rebuild_url method on base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4466
diff
changeset
|
294 |
newparams may only be mono-valued. |
90203ec7b3e3
[url] new rebuild_url method on base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4466
diff
changeset
|
295 |
""" |
90203ec7b3e3
[url] new rebuild_url method on base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4466
diff
changeset
|
296 |
if isinstance(url, unicode): |
90203ec7b3e3
[url] new rebuild_url method on base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4466
diff
changeset
|
297 |
url = url.encode(self.encoding) |
90203ec7b3e3
[url] new rebuild_url method on base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4466
diff
changeset
|
298 |
schema, netloc, path, query, fragment = urlsplit(url) |
90203ec7b3e3
[url] new rebuild_url method on base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4466
diff
changeset
|
299 |
query = parse_qs(query) |
90203ec7b3e3
[url] new rebuild_url method on base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4466
diff
changeset
|
300 |
# sort for testing predictability |
90203ec7b3e3
[url] new rebuild_url method on base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4466
diff
changeset
|
301 |
for key, val in sorted(newparams.iteritems()): |
90203ec7b3e3
[url] new rebuild_url method on base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4466
diff
changeset
|
302 |
query[key] = (self.url_quote(val),) |
90203ec7b3e3
[url] new rebuild_url method on base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4466
diff
changeset
|
303 |
query = '&'.join(u'%s=%s' % (param, value) |
90203ec7b3e3
[url] new rebuild_url method on base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4466
diff
changeset
|
304 |
for param, values in query.items() |
90203ec7b3e3
[url] new rebuild_url method on base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4466
diff
changeset
|
305 |
for value in values) |
90203ec7b3e3
[url] new rebuild_url method on base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4466
diff
changeset
|
306 |
return urlunsplit((schema, netloc, path, query, fragment)) |
90203ec7b3e3
[url] new rebuild_url method on base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4466
diff
changeset
|
307 |
|
2792
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
308 |
# bound user related methods ############################################### |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
309 |
|
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
310 |
@cached |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
311 |
def user_data(self): |
8238
087bb529035c
[spelling] fix dictionnary -> dictionary typo
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
312 |
"""returns a dictionary with this user's information""" |
2792
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
313 |
userinfo = {} |
4835
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4466
diff
changeset
|
314 |
user = self.user |
2792
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
315 |
userinfo['login'] = user.login |
3163
edfe43ceaa35
backport 3.5
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
316 |
userinfo['name'] = user.name() |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5527
diff
changeset
|
317 |
userinfo['email'] = user.cw_adapt_to('IEmailable').get_email() |
2792
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
318 |
return userinfo |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
319 |
|
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
320 |
# formating methods ####################################################### |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
321 |
|
2823
a4e3e9b1a9cd
backported from appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2808
diff
changeset
|
322 |
def view(self, __vid, rset=None, __fallback_oid=None, __registry='views', |
5516
232d13fc3e86
[req] avoid getting w in cw_extra_kwargs when calling .view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5459
diff
changeset
|
323 |
initargs=None, w=None, **kwargs): |
4070
6e9f7abee4ef
fix initargs handling
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
3720
diff
changeset
|
324 |
"""Select object with the given id (`__oid`) then render it. If the |
6e9f7abee4ef
fix initargs handling
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
3720
diff
changeset
|
325 |
object isn't selectable, try to select fallback object if |
6e9f7abee4ef
fix initargs handling
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
3720
diff
changeset
|
326 |
`__fallback_oid` is specified. |
6e9f7abee4ef
fix initargs handling
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
3720
diff
changeset
|
327 |
|
8238
087bb529035c
[spelling] fix dictionnary -> dictionary typo
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
328 |
If specified `initargs` is expected to be a dictionary containing |
4070
6e9f7abee4ef
fix initargs handling
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
3720
diff
changeset
|
329 |
arguments that should be given to selection (hence to object's __init__ |
6e9f7abee4ef
fix initargs handling
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
3720
diff
changeset
|
330 |
as well), but not to render(). Other arbitrary keyword arguments will be |
6e9f7abee4ef
fix initargs handling
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
3720
diff
changeset
|
331 |
given to selection *and* to render(), and so should be handled by |
6e9f7abee4ef
fix initargs handling
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
3720
diff
changeset
|
332 |
object's call or cell_call method.. |
6e9f7abee4ef
fix initargs handling
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
3720
diff
changeset
|
333 |
""" |
6e9f7abee4ef
fix initargs handling
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
3720
diff
changeset
|
334 |
if initargs is None: |
6e9f7abee4ef
fix initargs handling
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
3720
diff
changeset
|
335 |
initargs = kwargs |
6e9f7abee4ef
fix initargs handling
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
3720
diff
changeset
|
336 |
else: |
6e9f7abee4ef
fix initargs handling
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
3720
diff
changeset
|
337 |
initargs.update(kwargs) |
3655
af86ab65a282
3.6 updates
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3629
diff
changeset
|
338 |
try: |
4070
6e9f7abee4ef
fix initargs handling
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
3720
diff
changeset
|
339 |
view = self.vreg[__registry].select(__vid, self, rset=rset, **initargs) |
7888
e257b4476454
[req] .view should not catch [Object|Registry]NotFound (which is a bug), only NoSelectableObject (closes #1973681)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7815
diff
changeset
|
340 |
except NoSelectableObject: |
5709
5606c01d68b2
[view] ensure fallback_oid is specified before trying to select fallback view, else simply raise the exception
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5516
diff
changeset
|
341 |
if __fallback_oid is None: |
5606c01d68b2
[view] ensure fallback_oid is specified before trying to select fallback view, else simply raise the exception
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5516
diff
changeset
|
342 |
raise |
3655
af86ab65a282
3.6 updates
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3629
diff
changeset
|
343 |
view = self.vreg[__registry].select(__fallback_oid, self, |
4070
6e9f7abee4ef
fix initargs handling
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
3720
diff
changeset
|
344 |
rset=rset, **initargs) |
5516
232d13fc3e86
[req] avoid getting w in cw_extra_kwargs when calling .view
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5459
diff
changeset
|
345 |
return view.render(w=w, **kwargs) |
2823
a4e3e9b1a9cd
backported from appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2808
diff
changeset
|
346 |
|
7914
fb757a7d887e
[request, ui] printable_value is now a method of request, and may be given dict of formatters to use (closes #1984743)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7888
diff
changeset
|
347 |
def printable_value(self, attrtype, value, props=None, displaytime=True, |
fb757a7d887e
[request, ui] printable_value is now a method of request, and may be given dict of formatters to use (closes #1984743)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7888
diff
changeset
|
348 |
formatters=uilib.PRINTERS): |
fb757a7d887e
[request, ui] printable_value is now a method of request, and may be given dict of formatters to use (closes #1984743)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7888
diff
changeset
|
349 |
"""return a displayablye value (i.e. unicode string)""" |
fb757a7d887e
[request, ui] printable_value is now a method of request, and may be given dict of formatters to use (closes #1984743)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7888
diff
changeset
|
350 |
if value is None: |
fb757a7d887e
[request, ui] printable_value is now a method of request, and may be given dict of formatters to use (closes #1984743)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7888
diff
changeset
|
351 |
return u'' |
fb757a7d887e
[request, ui] printable_value is now a method of request, and may be given dict of formatters to use (closes #1984743)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7888
diff
changeset
|
352 |
try: |
fb757a7d887e
[request, ui] printable_value is now a method of request, and may be given dict of formatters to use (closes #1984743)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7888
diff
changeset
|
353 |
as_string = formatters[attrtype] |
fb757a7d887e
[request, ui] printable_value is now a method of request, and may be given dict of formatters to use (closes #1984743)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7888
diff
changeset
|
354 |
except KeyError: |
fb757a7d887e
[request, ui] printable_value is now a method of request, and may be given dict of formatters to use (closes #1984743)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7888
diff
changeset
|
355 |
self.error('given bad attrtype %s', attrtype) |
fb757a7d887e
[request, ui] printable_value is now a method of request, and may be given dict of formatters to use (closes #1984743)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7888
diff
changeset
|
356 |
return unicode(value) |
fb757a7d887e
[request, ui] printable_value is now a method of request, and may be given dict of formatters to use (closes #1984743)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7888
diff
changeset
|
357 |
return as_string(value, self, props, displaytime) |
fb757a7d887e
[request, ui] printable_value is now a method of request, and may be given dict of formatters to use (closes #1984743)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7888
diff
changeset
|
358 |
|
2792
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
359 |
def format_date(self, date, date_format=None, time=False): |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
360 |
"""return a string for a date time according to instance's |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
361 |
configuration |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
362 |
""" |
5710
1c17e47df974
[req] fix format_time w/ 0:0 which is evaluated to False
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5709
diff
changeset
|
363 |
if date is not None: |
2792
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
364 |
if date_format is None: |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
365 |
if time: |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
366 |
date_format = self.property_value('ui.datetime-format') |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
367 |
else: |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
368 |
date_format = self.property_value('ui.date-format') |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
369 |
return ustrftime(date, date_format) |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
370 |
return u'' |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
371 |
|
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
372 |
def format_time(self, time): |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
373 |
"""return a string for a time according to instance's |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
374 |
configuration |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
375 |
""" |
5710
1c17e47df974
[req] fix format_time w/ 0:0 which is evaluated to False
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5709
diff
changeset
|
376 |
if time is not None: |
2792
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
377 |
return ustrftime(time, self.property_value('ui.time-format')) |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
378 |
return u'' |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
379 |
|
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
380 |
def format_float(self, num): |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
381 |
"""return a string for floating point number according to instance's |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
382 |
configuration |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
383 |
""" |
4459
f628abfb3a6c
backport stable
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4307
diff
changeset
|
384 |
if num is not None: |
2792
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
385 |
return self.property_value('ui.float-format') % num |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
386 |
return u'' |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
387 |
|
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
388 |
def parse_datetime(self, value, etype='Datetime'): |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
389 |
"""get a datetime or time from a string (according to etype) |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
390 |
Datetime formatted as Date are accepted |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
391 |
""" |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
392 |
assert etype in ('Datetime', 'Date', 'Time'), etype |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
393 |
# XXX raise proper validation error |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
394 |
if etype == 'Datetime': |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
395 |
format = self.property_value('ui.datetime-format') |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
396 |
try: |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
397 |
return todatetime(strptime(value, format)) |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
398 |
except ValueError: |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
399 |
pass |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
400 |
elif etype == 'Time': |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
401 |
format = self.property_value('ui.time-format') |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
402 |
try: |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
403 |
# (adim) I can't find a way to parse a Time with a custom format |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
404 |
date = strptime(value, format) # this returns a DateTime |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
405 |
return time(date.hour, date.minute, date.second) |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
406 |
except ValueError: |
4222
5667f493c505
return localized message on parse_datetime errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4070
diff
changeset
|
407 |
raise ValueError(self._('can\'t parse %(value)r (expected %(format)s)') |
5667f493c505
return localized message on parse_datetime errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4070
diff
changeset
|
408 |
% {'value': value, 'format': format}) |
2792
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
409 |
try: |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
410 |
format = self.property_value('ui.date-format') |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
411 |
dt = strptime(value, format) |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
412 |
if etype == 'Datetime': |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
413 |
return todatetime(dt) |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
414 |
return todate(dt) |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
415 |
except ValueError: |
4222
5667f493c505
return localized message on parse_datetime errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4070
diff
changeset
|
416 |
raise ValueError(self._('can\'t parse %(value)r (expected %(format)s)') |
5667f493c505
return localized message on parse_datetime errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4070
diff
changeset
|
417 |
% {'value': value, 'format': format}) |
2792
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
418 |
|
8309
48ef505aa9f9
[request] gather all base_url logic in a single place (closes #2200756)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8238
diff
changeset
|
419 |
def base_url(self, secure=None): |
48ef505aa9f9
[request] gather all base_url logic in a single place (closes #2200756)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8238
diff
changeset
|
420 |
"""return the root url of the instance |
48ef505aa9f9
[request] gather all base_url logic in a single place (closes #2200756)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8238
diff
changeset
|
421 |
""" |
48ef505aa9f9
[request] gather all base_url logic in a single place (closes #2200756)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8238
diff
changeset
|
422 |
if secure: |
8595
01e1e44f1eb3
[server] implement base_url with secure=True (closes #2508638)
Arthur Lutz <arthur.lutz@logilab.fr>
parents:
8579
diff
changeset
|
423 |
return self.vreg.config.get('https-url', self.vreg.config['base-url']) |
5443
f299ee54d7e0
[webconfig] cleanup base_url management
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
424 |
return self.vreg.config['base-url'] |
f299ee54d7e0
[webconfig] cleanup base_url management
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
425 |
|
f299ee54d7e0
[webconfig] cleanup base_url management
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
426 |
# abstract methods to override according to the web front-end ############# |
2792
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
427 |
|
7543
570522300e22
[ms, entity metas] add 'actual source' to entities table / base entity metadata cache. Closes #1767090
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7407
diff
changeset
|
428 |
def describe(self, eid, asdict=False): |
2792
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
429 |
"""return a tuple (type, sourceuri, extid) for the entity with id <eid>""" |
135580d15d42
rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
430 |
raise NotImplementedError |