entities/lib.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 24 Sep 2015 12:18:00 +0200
changeset 10916 8e504786df3c
parent 10907 9ae707db5265
permissions -rw-r--r--
[hooks/syncschema] Turn DropColumnOp into a data operation While writing a test for a migration issue where "NOT NULL" was added to an inlined relation column, I ran into a case where the same column was deleted twice, which of course results in an error. This is because the "ecrit_par" relation used by the test is ambiguous. I've hence turned the DropColumnOp into a data operation to ensure we'll delete the column only once in such case. Related to #6211101
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9211
d45d66d94baa [entities] properly escape in EmailAddress.printable_value when format is html. Closes #3064025
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8930
diff changeset
     1
# copyright 2003-2013 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: 4252
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: 4252
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: 4252
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: 4252
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: 4252
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: 4252
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: 4252
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: 4252
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: 4252
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: 4252
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: 4252
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: 4252
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: 4252
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: 4252
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: 4252
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
9211
d45d66d94baa [entities] properly escape in EmailAddress.printable_value when format is html. Closes #3064025
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8930
diff changeset
    18
"""entity classes for optional library entities"""
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    19
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    20
__docformat__ = "restructuredtext en"
9442
fbf2287fb2ce [req] deprecate get_cache (closes #3181499)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9211
diff changeset
    21
from warnings import warn
10603
65ad6980976e [py3k] import URL mangling functions using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9442
diff changeset
    22
from datetime import datetime
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    23
10609
e2d8e81bfe68 [py3k] import range using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10603
diff changeset
    24
from six.moves import range
10603
65ad6980976e [py3k] import URL mangling functions using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9442
diff changeset
    25
from six.moves.urllib.parse import urlsplit, urlunsplit
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    26
9211
d45d66d94baa [entities] properly escape in EmailAddress.printable_value when format is html. Closes #3064025
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8930
diff changeset
    27
from logilab.mtconverter import xml_escape
d45d66d94baa [entities] properly escape in EmailAddress.printable_value when format is html. Closes #3064025
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8930
diff changeset
    28
1302
dd984d682ab0 don't fail on unregistered properties
sylvain.thenault@logilab.fr
parents: 1154
diff changeset
    29
from cubicweb import UnknownProperty
713
5adb6d8e5fa7 update imports of "cubicweb.common.entity" and use the new module path "cubicweb.entity"
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 583
diff changeset
    30
from cubicweb.entity import _marker
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    31
from cubicweb.entities import AnyEntity, fetch_config
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    32
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    33
def mangle_email(address):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    34
    try:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    35
        name, host = address.split('@', 1)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    36
    except ValueError:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    37
        return address
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    38
    return '%s at %s' % (name, host.replace('.', ' dot '))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    39
5174
78438ad513ca #759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    40
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    41
class EmailAddress(AnyEntity):
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3230
diff changeset
    42
    __regid__ = 'EmailAddress'
7827
9bbf83f68bcc [entity] upgrade fetch_[unrelated_]order to benefit from changes introduced in 3.14 (closes #1942758)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7737
diff changeset
    43
    fetch_attrs, cw_fetch_order = fetch_config(['address', 'alias'])
7737
db6d296cc66f [web] closes #1892494: emailaddress and anonymity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5556
diff changeset
    44
    rest_attr = 'eid'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    45
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    46
    def dc_title(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    47
        if self.alias:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    48
            return '%s <%s>' % (self.alias, self.display_address())
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    49
        return self.display_address()
1477
b056a49c16dc backport default branch
sylvain.thenault@logilab.fr
parents: 1398 1410
diff changeset
    50
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    51
    @property
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    52
    def email_of(self):
5556
9ab2b4c74baf [entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    53
        return self.reverse_use_email and self.reverse_use_email[0] or None
1477
b056a49c16dc backport default branch
sylvain.thenault@logilab.fr
parents: 1398 1410
diff changeset
    54
3204
0b766b8a13e1 #370578: change EmailAddress identical_to/canonical to prefered_form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2098
diff changeset
    55
    @property
0b766b8a13e1 #370578: change EmailAddress identical_to/canonical to prefered_form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2098
diff changeset
    56
    def prefered(self):
3207
2516324401dd return self, not None, when no prefered form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3204
diff changeset
    57
        return self.prefered_form and self.prefered_form[0] or self
3204
0b766b8a13e1 #370578: change EmailAddress identical_to/canonical to prefered_form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2098
diff changeset
    58
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    59
    def related_emails(self, skipeids=None):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    60
        # XXX move to eemail
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    61
        # check email relations are in the schema first
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    62
        subjrels = self.e_schema.object_relations()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    63
        if not ('sender' in subjrels and 'recipients' in subjrels):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    64
            return
5174
78438ad513ca #759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    65
        rset = self._cw.execute('DISTINCT Any X, S, D ORDERBY D DESC '
78438ad513ca #759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    66
                                'WHERE X sender Y or X recipients Y, '
78438ad513ca #759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    67
                                'X subject S, X date D, Y eid %(y)s',
78438ad513ca #759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    68
                                {'y': self.eid})
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    69
        if skipeids is None:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    70
            skipeids = set()
10609
e2d8e81bfe68 [py3k] import range using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10603
diff changeset
    71
        for i in range(len(rset)):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    72
            eid = rset[i][0]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    73
            if eid in skipeids:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    74
                continue
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    75
            skipeids.add(eid)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    76
            yield rset.get_entity(i, 0)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    77
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    78
    def display_address(self):
3418
7b49fa7e942d [api] use _cw, cw_row, cw_col, cw_rset etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3377
diff changeset
    79
        if self._cw.vreg.config['mangle-emails']:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    80
            return mangle_email(self.address)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    81
        return self.address
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    82
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    83
    def printable_value(self, attr, value=_marker, attrtype=None,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    84
                        format='text/html'):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    85
        """overriden to return displayable address when necessary"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    86
        if attr == 'address':
9211
d45d66d94baa [entities] properly escape in EmailAddress.printable_value when format is html. Closes #3064025
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8930
diff changeset
    87
            address = self.display_address()
d45d66d94baa [entities] properly escape in EmailAddress.printable_value when format is html. Closes #3064025
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8930
diff changeset
    88
            if format == 'text/html':
d45d66d94baa [entities] properly escape in EmailAddress.printable_value when format is html. Closes #3064025
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8930
diff changeset
    89
                address = xml_escape(address)
d45d66d94baa [entities] properly escape in EmailAddress.printable_value when format is html. Closes #3064025
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8930
diff changeset
    90
            return address
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    91
        return super(EmailAddress, self).printable_value(attr, value, attrtype, format)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    92
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    93
2828
306fe72bfd07 remove old bw compat code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2098
diff changeset
    94
class Bookmark(AnyEntity):
306fe72bfd07 remove old bw compat code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2098
diff changeset
    95
    """customized class for Bookmark entities"""
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3230
diff changeset
    96
    __regid__ = 'Bookmark'
7827
9bbf83f68bcc [entity] upgrade fetch_[unrelated_]order to benefit from changes introduced in 3.14 (closes #1942758)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7737
diff changeset
    97
    fetch_attrs, cw_fetch_order = fetch_config(['title', 'path'])
2828
306fe72bfd07 remove old bw compat code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2098
diff changeset
    98
306fe72bfd07 remove old bw compat code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2098
diff changeset
    99
    def actual_url(self):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3418
diff changeset
   100
        url = self._cw.build_url(self.path)
2828
306fe72bfd07 remove old bw compat code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2098
diff changeset
   101
        if self.title:
306fe72bfd07 remove old bw compat code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2098
diff changeset
   102
            urlparts = list(urlsplit(url))
306fe72bfd07 remove old bw compat code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2098
diff changeset
   103
            if urlparts[3]:
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3418
diff changeset
   104
                urlparts[3] += '&vtitle=%s' % self._cw.url_quote(self.title)
2828
306fe72bfd07 remove old bw compat code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2098
diff changeset
   105
            else:
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3418
diff changeset
   106
                urlparts[3] = 'vtitle=%s' % self._cw.url_quote(self.title)
2828
306fe72bfd07 remove old bw compat code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2098
diff changeset
   107
            url = urlunsplit(urlparts)
306fe72bfd07 remove old bw compat code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2098
diff changeset
   108
        return url
306fe72bfd07 remove old bw compat code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2098
diff changeset
   109
306fe72bfd07 remove old bw compat code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2098
diff changeset
   110
    def action_url(self):
306fe72bfd07 remove old bw compat code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2098
diff changeset
   111
        return self.absolute_url() + '/follow'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   112
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   113
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1302
diff changeset
   114
class CWProperty(AnyEntity):
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3230
diff changeset
   115
    __regid__ = 'CWProperty'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   116
7827
9bbf83f68bcc [entity] upgrade fetch_[unrelated_]order to benefit from changes introduced in 3.14 (closes #1942758)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7737
diff changeset
   117
    fetch_attrs, cw_fetch_order = fetch_config(['pkey', 'value'])
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   118
    rest_attr = 'pkey'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   119
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   120
    def typed_value(self):
3460
e4843535db25 [api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3451
diff changeset
   121
        return self._cw.vreg.typed_value(self.pkey, self.value)
1477
b056a49c16dc backport default branch
sylvain.thenault@logilab.fr
parents: 1398 1410
diff changeset
   122
1780
7549509ce0e6 dc_description should take a format argument
sylvain.thenault@logilab.fr
parents: 1477
diff changeset
   123
    def dc_description(self, format='text/plain'):
1302
dd984d682ab0 don't fail on unregistered properties
sylvain.thenault@logilab.fr
parents: 1154
diff changeset
   124
        try:
3460
e4843535db25 [api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3451
diff changeset
   125
            return self._cw._(self._cw.vreg.property_info(self.pkey)['help'])
1302
dd984d682ab0 don't fail on unregistered properties
sylvain.thenault@logilab.fr
parents: 1154
diff changeset
   126
        except UnknownProperty:
dd984d682ab0 don't fail on unregistered properties
sylvain.thenault@logilab.fr
parents: 1154
diff changeset
   127
            return u''
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   128
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   129
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1302
diff changeset
   130
class CWCache(AnyEntity):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   131
    """Cache"""
3377
dd9d292b6a6d use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3230
diff changeset
   132
    __regid__ = 'CWCache'
7827
9bbf83f68bcc [entity] upgrade fetch_[unrelated_]order to benefit from changes introduced in 3.14 (closes #1942758)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7737
diff changeset
   133
    fetch_attrs, cw_fetch_order = fetch_config(['name'])
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   134
9442
fbf2287fb2ce [req] deprecate get_cache (closes #3181499)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9211
diff changeset
   135
    def __init__(self, *args, **kwargs):
fbf2287fb2ce [req] deprecate get_cache (closes #3181499)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9211
diff changeset
   136
        warn('[3.19] CWCache entity type is going away soon. '
fbf2287fb2ce [req] deprecate get_cache (closes #3181499)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9211
diff changeset
   137
             'Other caching mechanisms can be used more reliably '
fbf2287fb2ce [req] deprecate get_cache (closes #3181499)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9211
diff changeset
   138
             'to the same effect.',
fbf2287fb2ce [req] deprecate get_cache (closes #3181499)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9211
diff changeset
   139
             DeprecationWarning)
fbf2287fb2ce [req] deprecate get_cache (closes #3181499)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9211
diff changeset
   140
        super(CWCache, self).__init__(*args, **kwargs)
fbf2287fb2ce [req] deprecate get_cache (closes #3181499)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9211
diff changeset
   141
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   142
    def touch(self):
3451
6b46d73823f5 [api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3418
diff changeset
   143
        self._cw.execute('SET X timestamp %(t)s WHERE X eid %(x)s',
5174
78438ad513ca #759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   144
                         {'t': datetime.now(), 'x': self.eid})
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   145
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   146
    def valid(self, date):
2060
10d9fbdbed35 [entities][CWCache] handle classic datetime vs None comparison bug
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1977
diff changeset
   147
        if date:
2098
13aab3775af7 [CWCache] fix CWCache validity test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2060
diff changeset
   148
            return date > self.timestamp
2060
10d9fbdbed35 [entities][CWCache] handle classic datetime vs None comparison bug
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1977
diff changeset
   149
        return False