web/views/primary.py
author sylvain.thenault@logilab.fr
Mon, 04 May 2009 10:50:33 +0200
branchtls-sprint
changeset 1632 2253a1005078
parent 1583 1d6d0ea1cda1
child 1720 14c9a0a1aca1
permissions -rw-r--r--
fix generated labels
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
     1
"""The default primary view
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
     2
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
     3
:organization: Logilab
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
     4
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
     5
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
     6
"""
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
     7
__docformat__ = "restructuredtext en"
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
     8
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
     9
from warnings import warn
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    10
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
    11
from logilab.mtconverter import html_escape
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
    12
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    13
from cubicweb import Unauthorized
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    14
from cubicweb.view import EntityView
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
    15
from cubicweb.web.uicfg import rdisplay
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    16
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    17
_ = unicode
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    18
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    19
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    20
class PrimaryView(EntityView):
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    21
    """the full view of an non final entity"""
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    22
    id = 'primary'
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    23
    title = _('primary')
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    24
    show_attr_label = True
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    25
    show_rel_label = True
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    26
    skip_none = True
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
    27
    rdisplay = rdisplay
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    28
    main_related_section = True
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    29
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
    30
    @classmethod
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
    31
    def vreg_initialization_completed(cls):
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
    32
        """set default category tags for relations where it's not yet defined in
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
    33
        the category relation tags
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
    34
        """
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
    35
        for eschema in cls.schema.entities():
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
    36
            for rschema, tschemas, role in eschema.relation_definitions(True):
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
    37
                for tschema in tschemas:
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
    38
                    if role == 'subject':
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
    39
                        X, Y = eschema, tschema
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
    40
                        card = rschema.rproperty(X, Y, 'cardinality')[0]
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
    41
                        composed = rschema.rproperty(X, Y, 'composite') == 'object'
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
    42
                    else:
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
    43
                        X, Y = tschema, eschema
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
    44
                        card = rschema.rproperty(X, Y, 'cardinality')[1]
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
    45
                        composed = rschema.rproperty(X, Y, 'composite') == 'subject'
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
    46
                    displayinfo = cls.rdisplay.get(rschema, role, X, Y)
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
    47
                    if displayinfo is None:
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
    48
                        if rschema.is_final():
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
    49
                            if rschema.meta or tschema.type in ('Password', 'Bytes'):
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
    50
                                where = None
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
    51
                            else:
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
    52
                                where = 'attributes'
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
    53
                        elif card in '1+':
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
    54
                            where = 'attributes'
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
    55
                        elif composed:
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
    56
                            where = 'relations'
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
    57
                        else:
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
    58
                            where = 'sideboxes'
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
    59
                        displayinfo = {'where': where,
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
    60
                                       'order': cls.rdisplay.get_timestamp()}
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
    61
                        cls.rdisplay.tag_relation(displayinfo, (X, rschema, Y),
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
    62
                                                  role)
1632
2253a1005078 fix generated labels
sylvain.thenault@logilab.fr
parents: 1583
diff changeset
    63
                    if role == 'subject':
2253a1005078 fix generated labels
sylvain.thenault@logilab.fr
parents: 1583
diff changeset
    64
                        displayinfo.setdefault('label', rschema.type)
2253a1005078 fix generated labels
sylvain.thenault@logilab.fr
parents: 1583
diff changeset
    65
                    else:
2253a1005078 fix generated labels
sylvain.thenault@logilab.fr
parents: 1583
diff changeset
    66
                        displayinfo.setdefault('label', '%s_%s' % (rschema, role))
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
    67
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    68
    def html_headers(self):
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    69
        """return a list of html headers (eg something to be inserted between
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    70
        <head> and </head> of the returned page
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    71
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    72
        by default primary views are indexed
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    73
        """
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    74
        return []
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    75
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    76
    def cell_call(self, row, col):
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    77
        self.row = row
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    78
        # XXX move render_entity implementation here
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    79
        self.render_entity(self.complete_entity(row, col))
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
    80
        self.maxrelated = self.req.property_value('navigation.related-limit')
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    81
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    82
    def render_entity(self, entity):
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    83
        """return html to display the given entity"""
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    84
        self.render_entity_title(entity)
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    85
        self.render_entity_metadata(entity)
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    86
        # entity's attributes and relations, excluding meta data
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    87
        # if the entity isn't meta itself
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
    88
        boxes = self._prepare_side_boxes(entity)
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
    89
        if boxes or hasattr(self, 'render_side_related'):
1558
f63d090eb34a some primary view fixes, need more (eg reledit doesn't work for non final relation
sylvain.thenault@logilab.fr
parents: 1554
diff changeset
    90
            self.w(u'<table width="100%"><tr><td style="width: 75%">')
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    91
        self.w(u'<div>')
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    92
        self.w(u'<div class="mainInfo">')
1516
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
    93
        try:
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
    94
            self.render_entity_attributes(entity)
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
    95
        except TypeError: # XXX bw compat
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
    96
            warn('siderelations argument of render_entity_attributes is '
1558
f63d090eb34a some primary view fixes, need more (eg reledit doesn't work for non final relation
sylvain.thenault@logilab.fr
parents: 1554
diff changeset
    97
                 'deprecated (%s)' % self.__class__)
1516
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
    98
            self.render_entity_attributes(entity, [])
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    99
        self.w(u'</div>')
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   100
        self.content_navigation_components('navcontenttop')
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   101
        if self.main_related_section:
1516
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   102
            try:
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   103
                self.render_entity_relations(entity)
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   104
            except TypeError: # XXX bw compat
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   105
                warn('siderelations argument of render_entity_relations is '
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   106
                     'deprecated')
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   107
                self.render_entity_relations(entity, [])
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   108
        self.w(u'</div>')
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   109
        if boxes or hasattr(self, 'render_side_related'):
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   110
            self.w(u'</td><td>')
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   111
            # side boxes
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   112
            self.w(u'<div class="primaryRight">')
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   113
            if hasattr(self, 'render_side_related'):
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   114
                warn('render_side_related is deprecated')
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   115
                self.render_side_related(entity, [])
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   116
            self.render_side_boxes(boxes)
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   117
            self.w(u'</div>')
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   118
            self.w(u'</td></tr></table>')
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   119
        self.content_navigation_components('navcontentbottom')
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   120
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   121
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   122
    def content_navigation_components(self, context):
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   123
        self.w(u'<div class="%s">' % context)
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   124
        for comp in self.vreg.possible_vobjects('contentnavigation',
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   125
                                                self.req, self.rset, row=self.row,
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   126
                                                view=self, context=context):
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   127
            try:
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   128
                comp.dispatch(w=self.w, row=self.row, view=self)
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   129
            except NotImplementedError:
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   130
                warn('component %s doesnt implement cell_call, please update'
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   131
                     % comp.__class__, DeprecationWarning)
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   132
                comp.dispatch(w=self.w, view=self)
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   133
        self.w(u'</div>')
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   134
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   135
    def render_entity_title(self, entity):
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   136
        title = self.content_title(entity) # deprecate content_title?
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   137
        if title:
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   138
            self.w(u'<h1><span class="etype">%s</span> %s</h1>'
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   139
                   % (entity.dc_type().capitalize(), title))
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   140
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   141
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   142
    def content_title(self, entity):
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   143
        """default implementation return dc_title"""
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   144
        return html_escape(entity.dc_title())
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   145
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   146
    def render_entity_metadata(self, entity):
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   147
        entity.view('metadata', w=self.w)
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   148
        summary = self.summary(entity) # deprecate summary?
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   149
        if summary:
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   150
            self.w(u'<div class="summary">%s</div>' % summary)
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   151
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   152
    def summary(self, entity):
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   153
        """default implementation return an empty string"""
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   154
        return u''
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   155
1516
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   156
    def render_entity_attributes(self, entity, siderelations=None):
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   157
        for rschema, tschemas, role, displayinfo in self._iter_display(entity, 'attributes'):
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   158
            vid =  displayinfo.get('vid', 'reledit')
1558
f63d090eb34a some primary view fixes, need more (eg reledit doesn't work for non final relation
sylvain.thenault@logilab.fr
parents: 1554
diff changeset
   159
            if rschema.is_final() or vid == 'reledit':
f63d090eb34a some primary view fixes, need more (eg reledit doesn't work for non final relation
sylvain.thenault@logilab.fr
parents: 1554
diff changeset
   160
                value = entity.view(vid, rtype=rschema.type, role=role)
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   161
            else:
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   162
                rset = self._relation_rset(entity, rschema, role, displayinfo)
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   163
                if rset:
1558
f63d090eb34a some primary view fixes, need more (eg reledit doesn't work for non final relation
sylvain.thenault@logilab.fr
parents: 1554
diff changeset
   164
                    value = self.view(vid, rset)
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   165
                else:
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   166
                    value = None
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   167
            if self.skip_none and (value is None or value == ''):
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   168
                continue
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   169
            self._render_attribute(rschema, value)
1516
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   170
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   171
    def render_entity_relations(self, entity, siderelations=None):
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   172
        for rschema, tschemas, role, displayinfo in self._iter_display(entity, 'relations'):
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   173
            rset = self._relation_rset(entity, rschema, role, displayinfo)
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   174
            if rset:
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   175
                self._render_relation(rset, displayinfo, 'autolimited',
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   176
                                      self.show_rel_label)
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   177
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   178
    def render_side_boxes(self, boxes):
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   179
        """display side related relations:
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   180
        non-meta in a first step, meta in a second step
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   181
        """
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   182
        for box in boxes:
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   183
            if isinstance(box, tuple):
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   184
                label, rset, vid, _  = box
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   185
                self.w(u'<div class="sideRelated">')
1516
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   186
                self.wview(vid, rset, title=label)
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   187
                self.w(u'</div>')
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   188
            else:
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   189
                try:
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   190
                    box.dispatch(w=self.w, row=self.row)
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   191
                except NotImplementedError:
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   192
                    # much probably a context insensitive box, which only implements
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   193
                    # .call() and not cell_call()
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   194
                    box.dispatch(w=self.w)
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   195
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   196
    def _prepare_side_boxes(self, entity):
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   197
        sideboxes = []
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   198
        for rschema, tschemas, role, displayinfo in self._iter_display(entity, 'sideboxes'):
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   199
            rset = self._relation_rset(entity, rschema, role, displayinfo)
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   200
            if not rset:
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   201
                continue
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   202
            label = display_name(self.req, rschema.type, role)
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   203
            vid = displayinfo.get('vid', 'autolimited')
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   204
            sideboxes.append((label, rset, vid, displayinfo.get('order')))
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   205
        sideboxes = sorted(sideboxes, key=lambda x: x[-1])
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   206
        sideboxes += list(self.vreg.possible_vobjects('boxes', self.req, self.rset,
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   207
                                                      row=self.row, view=self,
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   208
                                                      context='incontext'))
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   209
        return sideboxes
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   210
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   211
    def _iter_display(self, entity, where):
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   212
        eschema = entity.e_schema
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   213
        for rschema, tschemas, role in eschema.relation_definitions(True):
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   214
            matchtschemas = []
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   215
            for tschema in tschemas:
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   216
                displayinfo = self.rdisplay.etype_get(eschema, rschema, role,
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   217
                                                      tschema)
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   218
                assert displayinfo is not None, (str(rschema), role,
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   219
                                                 str(eschema), str(tschema))
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   220
                if displayinfo.get('where') == where:
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   221
                    matchtschemas.append(tschema)
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   222
            if matchtschemas:
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   223
                # XXX pick the latest displayinfo
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   224
                yield rschema, matchtschemas, role, displayinfo
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   225
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   226
    def _relation_rset(self, entity, rschema, role, displayinfo):
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   227
        try:
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   228
            if displayinfo.get('limit'):
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   229
                rset = entity.related(rschema.type, role,
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   230
                                      limit=self.maxrelated+1)
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   231
            else:
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   232
                rset = entity.related(rschema.type, role)
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   233
        except Unauthorized:
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   234
            return
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   235
        if 'filter' in displayinfo:
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   236
            rset = displayinfo['filter'](rset)
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   237
        return rset
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   238
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   239
    def _render_relation(self, rset, displayinfo, defaultvid, showlabel):
1583
1d6d0ea1cda1 needs unicode string
sylvain.thenault@logilab.fr
parents: 1558
diff changeset
   240
        self.w(u'<div class="section">')
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   241
        if showlabel:
1583
1d6d0ea1cda1 needs unicode string
sylvain.thenault@logilab.fr
parents: 1558
diff changeset
   242
            self.w(u'<h4>%s</h4>' % self.req._(displayinfo['label']))
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   243
        self.wview(displayinfo.get('vid', defaultvid), rset)
1583
1d6d0ea1cda1 needs unicode string
sylvain.thenault@logilab.fr
parents: 1558
diff changeset
   244
        self.w(u'</div>')
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   245
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   246
    def _render_attribute(self, rschema, value, role='subject'):
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   247
        if rschema.is_final():
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   248
            show_label = self.show_attr_label
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   249
        else:
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   250
            show_label = self.show_rel_label
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   251
        label = display_name(self.req, rschema.type, role)
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   252
        self.field(label, value, show_label=show_label, tr=False)
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   253
1516
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   254
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   255
class RelatedView(EntityView):
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   256
    id = 'autolimited'
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   257
    def call(self, title=None, **kwargs):
1516
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   258
        # if not too many entities, show them all in a list
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   259
        maxrelated = self.req.property_value('navigation.related-limit')
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   260
        if title:
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   261
            self.w(u'<div class="title"><span>%s</span></div>' % title)
1516
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   262
        if self.rset.rowcount <= maxrelated:
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   263
            if self.rset.rowcount == 1:
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   264
                self.wview('incontext', self.rset, row=0)
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   265
            elif 1 < self.rset.rowcount <= 5:
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   266
                self.wview('csv', self.rset)
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   267
            else:
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   268
                self.w(u'<div>')
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   269
                self.wview('simplelist', self.rset)
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   270
                self.w(u'</div>')
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   271
        # else show links to display related entities
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   272
        else:
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   273
            rql = self.rset.printable_rql()
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   274
            self.rset.limit(maxrelated)
1516
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   275
            self.w(u'<div>')
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   276
            self.wview('simplelist', self.rset)
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   277
            self.w(u'[<a href="%s">%s</a>]' % (self.build_url(rql=rql),
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   278
                                               self.req._('see them all')))
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   279
            self.w(u'</div>')