entities/__init__.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 19 May 2009 09:05:47 +0200
branchstable
changeset 1854 9302d0e66076
parent 1498 2c6eec0b46b9
child 1977 606923dff11b
permissions -rw-r--r--
stop automatically setting default method for _format field, too hard to override this with the new form system while keeping bw compat. Simply upgrade to new form system where it's a problem
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     1
"""base application's entities class implementation: `AnyEntity`
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     2
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     3
:organization: Logilab
479
ac5c9442b1fd update some copyrights
sylvain.thenault@logilab.fr
parents: 253
diff changeset
     4
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     5
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     6
"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     7
__docformat__ = "restructuredtext en"
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     8
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     9
from warnings import warn
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    10
1179
70825477c6ce fix *relations_by_categories + rtags api/key mess
sylvain.thenault@logilab.fr
parents: 1154
diff changeset
    11
from logilab.common.deprecation import deprecated_function, obsolete
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    12
from logilab.common.decorators import cached
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    13
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    14
from cubicweb import Unauthorized, typed_eid
713
5adb6d8e5fa7 update imports of "cubicweb.common.entity" and use the new module path "cubicweb.entity"
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 479
diff changeset
    15
from cubicweb.entity import Entity
940
15dcdc863965 fix imports : common.utils -> utils
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 912
diff changeset
    16
from cubicweb.utils import dump_class
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    17
from cubicweb.schema import FormatConstraint
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    18
125
979dbe0cade3 views with rss feed
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 0
diff changeset
    19
from cubicweb.interfaces import IBreadCrumbs, IFeed
979dbe0cade3 views with rss feed
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 0
diff changeset
    20
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    21
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    22
class AnyEntity(Entity):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    23
    """an entity instance has e_schema automagically set on the class and
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    24
    instances have access to their issuing cursor
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    25
    """
1493
8270580b65a0 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1417
diff changeset
    26
    id = 'Any'
125
979dbe0cade3 views with rss feed
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 0
diff changeset
    27
    __implements__ = (IBreadCrumbs, IFeed)
1417
06af20e663f2 remove spaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    28
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    29
    @classmethod
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    30
    def selected(cls, etype):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    31
        """the special Any entity is used as the default factory, so
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    32
        the actual class has to be constructed at selection time once we
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    33
        have an actual entity'type
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    34
        """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    35
        if cls.id == etype:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    36
            return cls
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    37
        usercls = dump_class(cls, etype)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    38
        usercls.id = etype
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    39
        usercls.__initialize__()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    40
        return usercls
1493
8270580b65a0 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1417
diff changeset
    41
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    42
    fetch_attrs = ('modification_date',)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    43
    @classmethod
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    44
    def fetch_order(cls, attr, var):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    45
        """class method used to control sort order when multiple entities of
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    46
        this type are fetched
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    47
        """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    48
        return cls.fetch_unrelated_order(attr, var)
1493
8270580b65a0 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1417
diff changeset
    49
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    50
    @classmethod
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    51
    def fetch_unrelated_order(cls, attr, var):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    52
        """class method used to control sort order when multiple entities of
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    53
        this type are fetched to use in edition (eg propose them to create a
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    54
        new relation on an edited entity).
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    55
        """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    56
        if attr == 'modification_date':
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    57
            return '%s DESC' % var
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    58
        return None
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    59
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    60
    # meta data api ###########################################################
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    61
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    62
    def dc_title(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    63
        """return a suitable *unicode* title for this entity"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    64
        for rschema, attrschema in self.e_schema.attribute_definitions():
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    65
            if rschema.meta:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    66
                continue
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    67
            value = self.get_value(rschema.type)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    68
            if value:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    69
                # make the value printable (dates, floats, bytes, etc.)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    70
                return self.printable_value(rschema.type, value, attrschema.type,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    71
                                            format='text/plain')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    72
        return u'%s #%s' % (self.dc_type(), self.eid)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    73
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    74
    def dc_long_title(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    75
        """return a more detailled title for this entity"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    76
        return self.dc_title()
1493
8270580b65a0 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1417
diff changeset
    77
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    78
    def dc_description(self, format='text/plain'):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    79
        """return a suitable description for this entity"""
253
57e88c0ba286 check we have a description *yams attribute*
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 142
diff changeset
    80
        if self.e_schema.has_subject_relation('description'):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    81
            return self.printable_value('description', format=format)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    82
        return u''
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    83
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    84
    def dc_authors(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    85
        """return a suitable description for the author(s) of the entity"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    86
        try:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    87
            return ', '.join(u.name() for u in self.owned_by)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    88
        except Unauthorized:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    89
            return u''
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    90
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    91
    def dc_creator(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    92
        """return a suitable description for the creator of the entity"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    93
        if self.creator:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    94
            return self.creator.name()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    95
        return u''
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    96
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    97
    def dc_date(self, date_format=None):# XXX default to ISO 8601 ?
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    98
        """return latest modification date of this entity"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    99
        return self.format_date(self.modification_date, date_format=date_format)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   100
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   101
    def dc_type(self, form=''):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   102
        """return the display name for the type of this entity (translated)"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   103
        return self.e_schema.display_name(self.req, form)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   104
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   105
    def dc_language(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   106
        """return language used by this entity (translated)"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   107
        # check if entities has internationalizable attributes
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   108
        # XXX one is enough or check if all String attributes are internationalizable?
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   109
        for rschema, attrschema in self.e_schema.attribute_definitions():
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   110
            if rschema.rproperty(self.e_schema, attrschema,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   111
                                 'internationalizable'):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   112
                return self.req._(self.req.user.property_value('ui.language'))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   113
        return self.req._(self.vreg.property_value('ui.language'))
1493
8270580b65a0 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1417
diff changeset
   114
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   115
    @property
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   116
    def creator(self):
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1360
diff changeset
   117
        """return the CWUser entity which has created this entity, or None if
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   118
        unknown or if the curent user doesn't has access to this euser
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
        try:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   121
            return self.created_by[0]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   122
        except (Unauthorized, IndexError):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   123
            return None
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   124
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   125
    def breadcrumbs(self, view=None, recurs=False):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   126
        path = [self]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   127
        if hasattr(self, 'parent'):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   128
            parent = self.parent()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   129
            if parent is not None:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   130
                try:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   131
                    path = parent.breadcrumbs(view, True) + [self]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   132
                except TypeError:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   133
                    warn("breadcrumbs method's now takes two arguments "
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   134
                         "(view=None, recurs=False), please update",
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   135
                         DeprecationWarning)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   136
                    path = parent.breadcrumbs(view) + [self]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   137
        if not recurs:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   138
            if view is None:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   139
                if 'vtitle' in self.req.form:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   140
                    # embeding for instance
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   141
                    path.append( self.req.form['vtitle'] )
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   142
            elif view.id != 'primary' and hasattr(view, 'title'):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   143
                path.append( self.req._(view.title) )
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   144
        return path
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   145
125
979dbe0cade3 views with rss feed
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 0
diff changeset
   146
    ## IFeed interface ########################################################
979dbe0cade3 views with rss feed
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 0
diff changeset
   147
979dbe0cade3 views with rss feed
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 0
diff changeset
   148
    def rss_feed_url(self):
979dbe0cade3 views with rss feed
Laure Bourgois <Laure.Bourgois@logilab.fr>
parents: 0
diff changeset
   149
        return self.absolute_url(vid='rss')
1493
8270580b65a0 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1417
diff changeset
   150
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   151
    # abstractions making the whole things (well, some at least) working ######
1493
8270580b65a0 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1417
diff changeset
   152
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   153
    def sortvalue(self, rtype=None):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   154
        """return a value which can be used to sort this entity or given
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   155
        entity's attribute
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   156
        """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   157
        if rtype is None:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   158
            return self.dc_title().lower()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   159
        value = self.get_value(rtype)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   160
        # do not restrict to `unicode` because Bytes will return a `str` value
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   161
        if isinstance(value, basestring):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   162
            return self.printable_value(rtype, format='text/plain').lower()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   163
        return value
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   164
1493
8270580b65a0 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1417
diff changeset
   165
    # edition helper functions ################################################
1086
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   166
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   167
    def linked_to(self, rtype, target, remove=True):
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   168
        """if entity should be linked to another using __linkto form param for
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   169
        the given relation/target, return eids of related entities
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   170
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   171
        This method is consuming matching link-to information from form params
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   172
        if `remove` is True (by default).
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   173
        """
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   174
        try:
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   175
            return self.__linkto[(rtype, target)]
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   176
        except AttributeError:
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   177
            self.__linkto = {}
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   178
        except KeyError:
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   179
            pass
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   180
        linktos = list(self.req.list_form_param('__linkto'))
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   181
        linkedto = []
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   182
        for linkto in linktos[:]:
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   183
            ltrtype, eid, lttarget = linkto.split(':')
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   184
            if rtype == ltrtype and target == lttarget:
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   185
                # delete __linkto from form param to avoid it being added as
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   186
                # hidden input
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   187
                if remove:
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   188
                    linktos.remove(linkto)
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   189
                    self.req.form['__linkto'] = linktos
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   190
                linkedto.append(typed_eid(eid))
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   191
        self.__linkto[(rtype, target)] = linkedto
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   192
        return linkedto
1493
8270580b65a0 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1417
diff changeset
   193
1086
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   194
    # edit controller callbacks ###############################################
1493
8270580b65a0 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1417
diff changeset
   195
1086
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   196
    def after_deletion_path(self):
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   197
        """return (path, parameters) which should be used as redirect
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   198
        information when this entity is being deleted
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   199
        """
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   200
        return str(self.e_schema).lower(), {}
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   201
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   202
    def pre_web_edit(self):
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   203
        """callback called by the web editcontroller when an entity will be
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   204
        created/modified, to let a chance to do some entity specific stuff.
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   205
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   206
        Do nothing by default.
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   207
        """
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   208
        pass
1493
8270580b65a0 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1417
diff changeset
   209
1086
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   210
    # server side helpers #####################################################
1493
8270580b65a0 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1417
diff changeset
   211
1086
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   212
    def notification_references(self, view):
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   213
        """used to control References field of email send on notification
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   214
        for this entity. `view` is the notification view.
1493
8270580b65a0 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1417
diff changeset
   215
1086
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   216
        Should return a list of eids which can be used to generate message ids
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   217
        of previously sent email
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   218
        """
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   219
        return ()
1493
8270580b65a0 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1417
diff changeset
   220
1086
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   221
    # XXX deprecates, may be killed once old widgets system is gone ###########
1493
8270580b65a0 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1417
diff changeset
   222
1086
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   223
    @classmethod
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   224
    def get_widget(cls, rschema, x='subject'):
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   225
        """return a widget to view or edit a relation
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   226
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   227
        notice that when the relation support multiple target types, the widget
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   228
        is necessarily the same for all those types
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   229
        """
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   230
        # let ImportError propage if web par isn't available
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   231
        from cubicweb.web.widgets import widget
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   232
        if isinstance(rschema, basestring):
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   233
            rschema = cls.schema.rschema(rschema)
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   234
        if x == 'subject':
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   235
            tschema = rschema.objects(cls.e_schema)[0]
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   236
            wdg = widget(cls.vreg, cls, rschema, tschema, 'subject')
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   237
        else:
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   238
            tschema = rschema.subjects(cls.e_schema)[0]
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   239
            wdg = widget(cls.vreg, tschema, rschema, cls, 'object')
c8ff5c7fd0ae move get_widget in the to-deprecate section
sylvain.thenault@logilab.fr
parents: 1013
diff changeset
   240
        return wdg
1154
9b23a6836c32 support for old __rtags__
sylvain.thenault@logilab.fr
parents: 1150
diff changeset
   241
1179
70825477c6ce fix *relations_by_categories + rtags api/key mess
sylvain.thenault@logilab.fr
parents: 1154
diff changeset
   242
    @obsolete('use EntityFieldsForm.subject_relation_vocabulary')
70825477c6ce fix *relations_by_categories + rtags api/key mess
sylvain.thenault@logilab.fr
parents: 1154
diff changeset
   243
    def subject_relation_vocabulary(self, rtype, limit):
70825477c6ce fix *relations_by_categories + rtags api/key mess
sylvain.thenault@logilab.fr
parents: 1154
diff changeset
   244
        from cubicweb.web.form import EntityFieldsForm
1182
78e4080252be fix form instantiation
sylvain.thenault@logilab.fr
parents: 1179
diff changeset
   245
        return EntityFieldsForm(self.req, None, entity=self).subject_relation_vocabulary(rtype, limit)
1179
70825477c6ce fix *relations_by_categories + rtags api/key mess
sylvain.thenault@logilab.fr
parents: 1154
diff changeset
   246
70825477c6ce fix *relations_by_categories + rtags api/key mess
sylvain.thenault@logilab.fr
parents: 1154
diff changeset
   247
    @obsolete('use EntityFieldsForm.object_relation_vocabulary')
70825477c6ce fix *relations_by_categories + rtags api/key mess
sylvain.thenault@logilab.fr
parents: 1154
diff changeset
   248
    def object_relation_vocabulary(self, rtype, limit):
70825477c6ce fix *relations_by_categories + rtags api/key mess
sylvain.thenault@logilab.fr
parents: 1154
diff changeset
   249
        from cubicweb.web.form import EntityFieldsForm
1182
78e4080252be fix form instantiation
sylvain.thenault@logilab.fr
parents: 1179
diff changeset
   250
        return EntityFieldsForm(self.req, None, entity=self).object_relation_vocabulary(rtype, limit)
1493
8270580b65a0 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1417
diff changeset
   251
1179
70825477c6ce fix *relations_by_categories + rtags api/key mess
sylvain.thenault@logilab.fr
parents: 1154
diff changeset
   252
    @obsolete('use AutomaticEntityForm.[e]relations_by_category')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   253
    def relations_by_category(self, categories=None, permission=None):
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1493
diff changeset
   254
        from cubicweb.web.views.autoform import AutomaticEntityForm
1179
70825477c6ce fix *relations_by_categories + rtags api/key mess
sylvain.thenault@logilab.fr
parents: 1154
diff changeset
   255
        return AutomaticEntityForm.erelations_by_category(self, categories, permission)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   256
1179
70825477c6ce fix *relations_by_categories + rtags api/key mess
sylvain.thenault@logilab.fr
parents: 1154
diff changeset
   257
    @obsolete('use AutomaticEntityForm.[e]srelations_by_category')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   258
    def srelations_by_category(self, categories=None, permission=None):
1498
2c6eec0b46b9 fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents: 1493
diff changeset
   259
        from cubicweb.web.views.autoform import AutomaticEntityForm
1179
70825477c6ce fix *relations_by_categories + rtags api/key mess
sylvain.thenault@logilab.fr
parents: 1154
diff changeset
   260
        return AutomaticEntityForm.esrelations_by_category(self, categories, permission)
1493
8270580b65a0 delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1417
diff changeset
   261
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   262
    def attribute_values(self, attrname):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   263
        if self.has_eid() or attrname in self:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   264
            try:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   265
                values = self[attrname]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   266
            except KeyError:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   267
                values = getattr(self, attrname)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   268
            # actual relation return a list of entities
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   269
            if isinstance(values, list):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   270
                return [v.eid for v in values]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   271
            return (values,)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   272
        # the entity is being created, try to find default value for
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   273
        # this attribute
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   274
        try:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   275
            values = self.req.form[attrname]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   276
        except KeyError:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   277
            try:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   278
                values = self[attrname] # copying
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   279
            except KeyError:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   280
                values = getattr(self, 'default_%s' % attrname,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   281
                                 self.e_schema.default(attrname))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   282
                if callable(values):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   283
                    values = values()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   284
        if values is None:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   285
            values = ()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   286
        elif not isinstance(values, (list, tuple)):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   287
            values = (values,)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   288
        return values
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   289
912
9ad0867692e1 prepare for deprecation
sylvain.thenault@logilab.fr
parents: 713
diff changeset
   290
    def use_fckeditor(self, attr):
9ad0867692e1 prepare for deprecation
sylvain.thenault@logilab.fr
parents: 713
diff changeset
   291
        """return True if fckeditor should be used to edit entity's attribute named
9ad0867692e1 prepare for deprecation
sylvain.thenault@logilab.fr
parents: 713
diff changeset
   292
        `attr`, according to user preferences
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   293
        """
1107
961a478593a5 has_metadata is a schema method
sylvain.thenault@logilab.fr
parents: 1101
diff changeset
   294
        if self.req.use_fckeditor() and self.e_schema.has_metadata(attr, 'format'):
912
9ad0867692e1 prepare for deprecation
sylvain.thenault@logilab.fr
parents: 713
diff changeset
   295
            if self.has_eid() or '%s_format' % attr in self:
1360
13ae1121835e rename attribute_metadata method to attr_metadata to save a few chars
sylvain.thenault@logilab.fr
parents: 1182
diff changeset
   296
                return self.attr_metadata(attr, 'format') == 'text/html'
1013
948a3882c94a add a use_fckeditor method on http request
sylvain.thenault@logilab.fr
parents: 1010
diff changeset
   297
            return self.req.property_value('ui.default-text-format') == 'text/html'
912
9ad0867692e1 prepare for deprecation
sylvain.thenault@logilab.fr
parents: 713
diff changeset
   298
        return False
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   299
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   300
# XXX:  store a reference to the AnyEntity class since it is hijacked in goa
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   301
#       configuration and we need the actual reference to avoid infinite loops
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   302
#       in mro
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   303
ANYENTITY = AnyEntity
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   304
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   305
def fetch_config(fetchattrs, mainattr=None, pclass=AnyEntity, order='ASC'):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   306
    if pclass is ANYENTITY:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   307
        pclass = AnyEntity # AnyEntity and ANYENTITY may be different classes
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   308
    if pclass is not None:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   309
        fetchattrs += pclass.fetch_attrs
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   310
    if mainattr is None:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   311
        mainattr = fetchattrs[0]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   312
    @classmethod
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   313
    def fetch_order(cls, attr, var):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   314
        if attr == mainattr:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   315
            return '%s %s' % (var, order)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   316
        return None
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   317
    return fetchattrs, fetch_order