web/views/primary.py
author sylvain.thenault@logilab.fr
Thu, 30 Apr 2009 00:41:52 +0200
branchtls-sprint
changeset 1554 3a3263df6cdd
parent 1516 288d55a7c5e2
child 1558 f63d090eb34a
permissions -rw-r--r--
new primary view using uicfg.rdisplay (major api cleanup)
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)
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
    63
                    displayinfo.setdefault('label', '%s_%s' % (rschema, role))
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
    64
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    65
    def html_headers(self):
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    66
        """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
    67
        <head> and </head> of the returned page
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    68
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    69
        by default primary views are indexed
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    70
        """
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    71
        return []
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    72
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    73
    def cell_call(self, row, col):
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    74
        self.row = row
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    75
        # XXX move render_entity implementation here
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    76
        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
    77
        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
    78
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    79
    def render_entity(self, entity):
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    80
        """return html to display the given entity"""
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    81
        self.render_entity_title(entity)
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    82
        self.render_entity_metadata(entity)
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    83
        # entity's attributes and relations, excluding meta data
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    84
        # 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
    85
        boxes = self._prepare_side_boxes(entity)
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
    86
        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
    87
            self.w(u'<table width="100%"><tr><td width="75%">')
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    88
        self.w(u'<div>')
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    89
        self.w(u'<div class="mainInfo">')
1516
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
    90
        try:
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
    91
            self.render_entity_attributes(entity)
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
    92
        except TypeError: # XXX bw compat
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
    93
            warn('siderelations argument of render_entity_attributes is '
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
    94
                 'deprecated')
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
    95
            self.render_entity_attributes(entity, [])
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    96
        self.w(u'</div>')
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    97
        self.content_navigation_components('navcontenttop')
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
    98
        if self.main_related_section:
1516
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
    99
            try:
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   100
                self.render_entity_relations(entity)
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   101
            except TypeError: # XXX bw compat
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   102
                warn('siderelations argument of render_entity_relations is '
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   103
                     'deprecated')
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   104
                self.render_entity_relations(entity, [])
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   105
        self.w(u'</div>')
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   106
        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
   107
            self.w(u'</td><td>')
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   108
            # side boxes
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   109
            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
   110
            if hasattr(self, 'render_side_related'):
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   111
                warn('render_side_related is deprecated')
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   112
                self.render_side_related(entity, [])
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   113
            self.render_side_boxes(boxes)
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   114
            self.w(u'</div>')
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   115
            self.w(u'</td></tr></table>')
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   116
        self.content_navigation_components('navcontentbottom')
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   117
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   118
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   119
    def content_navigation_components(self, context):
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   120
        self.w(u'<div class="%s">' % context)
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   121
        for comp in self.vreg.possible_vobjects('contentnavigation',
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   122
                                                self.req, self.rset, row=self.row,
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   123
                                                view=self, context=context):
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   124
            try:
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   125
                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
   126
            except NotImplementedError:
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   127
                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
   128
                     % comp.__class__, DeprecationWarning)
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   129
                comp.dispatch(w=self.w, view=self)
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   130
        self.w(u'</div>')
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   131
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   132
    def render_entity_title(self, entity):
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   133
        title = self.content_title(entity) # deprecate content_title?
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   134
        if title:
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   135
            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
   136
                   % (entity.dc_type().capitalize(), title))
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   137
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   138
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   139
    def content_title(self, entity):
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   140
        """default implementation return dc_title"""
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   141
        return html_escape(entity.dc_title())
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   142
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   143
    def render_entity_metadata(self, entity):
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   144
        entity.view('metadata', w=self.w)
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   145
        summary = self.summary(entity) # deprecate summary?
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   146
        if summary:
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   147
            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
   148
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   149
    def summary(self, entity):
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   150
        """default implementation return an empty string"""
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   151
        return u''
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   152
1516
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   153
    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
   154
        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
   155
            vid =  displayinfo.get('vid', 'reledit')
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   156
            if rschema.is_final():
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   157
                value = entity.view('reledit', rtype=rschema.type)
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   158
            else:
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   159
                vid =  displayinfo.get('vid', 'reledit')
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   160
                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
   161
                if rset:
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   162
                    value = self.view(rset, vid)
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   163
                else:
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   164
                    value = None
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   165
            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
   166
                continue
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   167
            self._render_attribute(rschema, value)
1516
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   168
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   169
    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
   170
        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
   171
            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
   172
            if rset:
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   173
                self._render_relation(rset, displayinfo, 'autolimited',
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   174
                                      self.show_rel_label)
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   175
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   176
    def render_side_boxes(self, boxes):
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   177
        """display side related relations:
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   178
        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
   179
        """
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   180
        for box in boxes:
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   181
            if isinstance(box, tuple):
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   182
                label, rset, vid, _  = box
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   183
                self.w(u'<div class="sideRelated">')
1516
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   184
                self.wview(vid, rset, title=label)
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   185
                self.w(u'</div>')
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   186
            else:
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   187
                try:
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   188
                    box.dispatch(w=self.w, row=self.row)
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   189
                except NotImplementedError:
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   190
                    # 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
   191
                    # .call() and not cell_call()
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   192
                    box.dispatch(w=self.w)
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   193
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   194
    def _prepare_side_boxes(self, entity):
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   195
        sideboxes = []
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   196
        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
   197
            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
   198
            if not rset:
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   199
                continue
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   200
            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
   201
            vid = displayinfo.get('vid', 'autolimited')
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   202
            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
   203
        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
   204
        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
   205
                                                      row=self.row, view=self,
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   206
                                                      context='incontext'))
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   207
        return sideboxes
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   208
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   209
    def _iter_display(self, entity, where):
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   210
        eschema = entity.e_schema
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   211
        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
   212
            matchtschemas = []
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   213
            for tschema in tschemas:
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   214
                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
   215
                                                      tschema)
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   216
                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
   217
                                                 str(eschema), str(tschema))
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   218
                if displayinfo.get('where') == where:
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   219
                    matchtschemas.append(tschema)
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   220
            if matchtschemas:
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   221
                # XXX pick the latest displayinfo
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   222
                yield rschema, matchtschemas, role, displayinfo
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   223
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   224
    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
   225
        try:
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   226
            if displayinfo.get('limit'):
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   227
                rset = entity.related(rschema.type, role,
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   228
                                      limit=self.maxrelated+1)
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   229
            else:
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   230
                rset = entity.related(rschema.type, role)
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   231
        except Unauthorized:
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   232
            return
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   233
        if 'filter' in displayinfo:
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   234
            rset = displayinfo['filter'](rset)
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   235
        return rset
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   236
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   237
    def _render_relation(self, rset, displayinfo, defaultvid, showlabel):
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   238
        self.w('<div class="section">')
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   239
        if showlabel:
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   240
            label = self.req._(displayinfo['label'])
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   241
            self.w('<h4>%s</h4>' % label)
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   242
        self.wview(displayinfo.get('vid', defaultvid), rset)
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   243
        self.w('</div>')
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   244
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   245
    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
   246
        if rschema.is_final():
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   247
            show_label = self.show_attr_label
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   248
        else:
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   249
            show_label = self.show_rel_label
1491
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   250
        label = display_name(self.req, rschema.type, role)
742aff97dbf7 move AutomaticEntityForm and PrimaryView into their own module
sylvain.thenault@logilab.fr
parents:
diff changeset
   251
        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
   252
1516
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   253
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   254
class RelatedView(EntityView):
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   255
    id = 'autolimited'
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   256
    def call(self, title=None, **kwargs):
1516
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   257
        # 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
   258
        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
   259
        if title:
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   260
            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
   261
        if self.rset.rowcount <= maxrelated:
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   262
            if self.rset.rowcount == 1:
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   263
                self.wview('incontext', self.rset, row=0)
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   264
            elif 1 < self.rset.rowcount <= 5:
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   265
                self.wview('csv', self.rset)
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   266
            else:
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   267
                self.w(u'<div>')
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   268
                self.wview('simplelist', self.rset)
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   269
                self.w(u'</div>')
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   270
        # else show links to display related entities
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   271
        else:
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   272
            rql = self.rset.printable_rql()
1554
3a3263df6cdd new primary view using uicfg.rdisplay (major api cleanup)
sylvain.thenault@logilab.fr
parents: 1516
diff changeset
   273
            self.rset.limit(maxrelated)
1516
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   274
            self.w(u'<div>')
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   275
            self.wview('simplelist', self.rset)
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   276
            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
   277
                                               self.req._('see them all')))
288d55a7c5e2 refactor side boxes handling of primary view
sylvain.thenault@logilab.fr
parents: 1491
diff changeset
   278
            self.w(u'</div>')