web/views/cwsources.py
author Rémi Cardona <remi.cardona@logilab.fr>
Wed, 12 Feb 2014 17:32:49 +0100
changeset 9534 34d9de030564
parent 8665 e65af61bde7d
child 9445 65d93a4fd11c
permissions -rw-r--r--
[web/data] Ignore disabled widgets in cw.utils.formContents() (closes #3544492) 17.12.1 Disabled controls : http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.12.1 When set, the disabled attribute has the following effects on an element: * Disabled controls do not receive focus. * Disabled controls are skipped in tabbing navigation. * Disabled controls cannot be successful. The third one is the important one. 17.13.2 Successful controls : http://www.w3.org/TR/REC-html40/interact/forms.html#successful-controls A successful control is "valid" for submission. Every successful control has its control name paired with its current value as part of the submitted form data set. Bottom line, disable widgets should not be part of the names and values lists returned by formContents().
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8665
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8408
diff changeset
     1
# copyright 2010-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
6724
24bf6f181d0e [pyro source] store pyro source mapping file into the database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     2
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
24bf6f181d0e [pyro source] store pyro source mapping file into the database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     3
#
24bf6f181d0e [pyro source] store pyro source mapping file into the database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     4
# This file is part of CubicWeb.
24bf6f181d0e [pyro source] store pyro source mapping file into the database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     5
#
24bf6f181d0e [pyro source] store pyro source mapping file into the database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     6
# CubicWeb is free software: you can redistribute it and/or modify it under the
24bf6f181d0e [pyro source] store pyro source mapping file into the database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     7
# terms of the GNU Lesser General Public License as published by the Free
24bf6f181d0e [pyro source] store pyro source mapping file into the database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     8
# Software Foundation, either version 2.1 of the License, or (at your option)
24bf6f181d0e [pyro source] store pyro source mapping file into the database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     9
# any later version.
24bf6f181d0e [pyro source] store pyro source mapping file into the database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    10
#
24bf6f181d0e [pyro source] store pyro source mapping file into the database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    11
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
24bf6f181d0e [pyro source] store pyro source mapping file into the database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
24bf6f181d0e [pyro source] store pyro source mapping file into the database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    13
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
24bf6f181d0e [pyro source] store pyro source mapping file into the database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    14
# details.
24bf6f181d0e [pyro source] store pyro source mapping file into the database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    15
#
24bf6f181d0e [pyro source] store pyro source mapping file into the database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    16
# You should have received a copy of the GNU Lesser General Public License along
24bf6f181d0e [pyro source] store pyro source mapping file into the database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
6944
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
    18
"""Specific views for data sources and related entities (eg CWSource,
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
    19
CWSourceHostConfig, CWSourceSchemaConfig).
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
    20
"""
6724
24bf6f181d0e [pyro source] store pyro source mapping file into the database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    21
24bf6f181d0e [pyro source] store pyro source mapping file into the database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    22
__docformat__ = "restructuredtext en"
24bf6f181d0e [pyro source] store pyro source mapping file into the database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    23
_ = unicode
24bf6f181d0e [pyro source] store pyro source mapping file into the database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    24
7995
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
    25
import logging
8136
273d8a03700c [sources management] fix crash mapping tab because chain() is not indexable. Closes #2124077
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7995
diff changeset
    26
from itertools import repeat
7995
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
    27
from logilab.mtconverter import xml_escape
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
    28
from logilab.common.decorators import cachedproperty
6724
24bf6f181d0e [pyro source] store pyro source mapping file into the database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    29
7995
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
    30
from cubicweb import Unauthorized, tags
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
    31
from cubicweb.utils import make_uid
8190
2a3c1b787688 [vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8166
diff changeset
    32
from cubicweb.predicates import (is_instance, score_entity, has_related_entities,
7995
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
    33
                                match_user_groups, match_kwargs, match_view)
6962
220e32f058be [management ui] add views to manage sources similarly to users
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6944
diff changeset
    34
from cubicweb.view import EntityView, StartupView
6724
24bf6f181d0e [pyro source] store pyro source mapping file into the database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    35
from cubicweb.schema import META_RTYPES, VIRTUAL_RTYPES, display_name
8665
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8408
diff changeset
    36
from cubicweb.web import formwidgets as wdgs, facet
7995
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
    37
from cubicweb.web.views import add_etype_button
8665
e65af61bde7d [uicfg] uicfg.py moves from web/ to web/views/ (prepares #2406609)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8408
diff changeset
    38
from cubicweb.web.views import (uicfg, tabs, actions, ibreadcrumbs, navigation,
7995
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
    39
                                tableview, pyviews)
6962
220e32f058be [management ui] add views to manage sources similarly to users
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6944
diff changeset
    40
7019
46413742f9b5 [source ui] uicfg tweaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6962
diff changeset
    41
46413742f9b5 [source ui] uicfg tweaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6962
diff changeset
    42
_abaa = uicfg.actionbox_appearsin_addmenu
7832
953f224357af [sources management] nicer source management view and breadcrumbs (closes #1946329)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7806
diff changeset
    43
# there are explicit 'add' buttons for those
7019
46413742f9b5 [source ui] uicfg tweaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6962
diff changeset
    44
_abaa.tag_object_of(('CWSourceSchemaConfig', 'cw_schema', '*'), False)
46413742f9b5 [source ui] uicfg tweaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6962
diff changeset
    45
_abaa.tag_object_of(('CWSourceSchemaConfig', 'cw_for_source', '*'), False)
7832
953f224357af [sources management] nicer source management view and breadcrumbs (closes #1946329)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7806
diff changeset
    46
_abaa.tag_object_of(('CWSourceSchemaConfig', 'cw_host_config_of', '*'), False)
7995
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
    47
_abaa.tag_object_of(('CWDataImport', 'cw_import_of', '*'), False)
7019
46413742f9b5 [source ui] uicfg tweaks
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6962
diff changeset
    48
7524
c019c3426049 [ui, sources] configure source form: hide synchronizing and mapping entities, use simple text input for parser
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7375
diff changeset
    49
_afs = uicfg.autoform_section
8150
b5a9706f839e [sources] hide some attributes from source edition form. Closes #2144160
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8136
diff changeset
    50
_afs.tag_attribute(('CWSource', 'latest_retrieval'), 'main', 'hidden')
b5a9706f839e [sources] hide some attributes from source edition form. Closes #2144160
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8136
diff changeset
    51
_afs.tag_attribute(('CWSource', 'in_synchronization'), 'main', 'hidden')
7524
c019c3426049 [ui, sources] configure source form: hide synchronizing and mapping entities, use simple text input for parser
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7375
diff changeset
    52
_afs.tag_object_of(('*', 'cw_for_source', 'CWSource'), 'main', 'hidden')
7832
953f224357af [sources management] nicer source management view and breadcrumbs (closes #1946329)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7806
diff changeset
    53
7524
c019c3426049 [ui, sources] configure source form: hide synchronizing and mapping entities, use simple text input for parser
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7375
diff changeset
    54
_affk = uicfg.autoform_field_kwargs
c019c3426049 [ui, sources] configure source form: hide synchronizing and mapping entities, use simple text input for parser
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7375
diff changeset
    55
_affk.tag_attribute(('CWSource', 'parser'), {'widget': wdgs.TextInput})
c019c3426049 [ui, sources] configure source form: hide synchronizing and mapping entities, use simple text input for parser
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7375
diff changeset
    56
6962
220e32f058be [management ui] add views to manage sources similarly to users
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6944
diff changeset
    57
# source primary views #########################################################
6724
24bf6f181d0e [pyro source] store pyro source mapping file into the database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    58
6944
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
    59
_pvs = uicfg.primaryview_section
7832
953f224357af [sources management] nicer source management view and breadcrumbs (closes #1946329)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7806
diff changeset
    60
_pvs.tag_attribute(('CWSource', 'name'), 'hidden')
6944
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
    61
_pvs.tag_object_of(('*', 'cw_for_source', 'CWSource'), 'hidden')
7832
953f224357af [sources management] nicer source management view and breadcrumbs (closes #1946329)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7806
diff changeset
    62
_pvs.tag_object_of(('*', 'cw_host_config_of', 'CWSource'), 'hidden')
953f224357af [sources management] nicer source management view and breadcrumbs (closes #1946329)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7806
diff changeset
    63
953f224357af [sources management] nicer source management view and breadcrumbs (closes #1946329)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7806
diff changeset
    64
_pvdc = uicfg.primaryview_display_ctrl
953f224357af [sources management] nicer source management view and breadcrumbs (closes #1946329)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7806
diff changeset
    65
_pvdc.tag_attribute(('CWSource', 'type'), {'vid': 'attribute'})# disable reledit
953f224357af [sources management] nicer source management view and breadcrumbs (closes #1946329)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7806
diff changeset
    66
953f224357af [sources management] nicer source management view and breadcrumbs (closes #1946329)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7806
diff changeset
    67
_rc = uicfg.reledit_ctrl
7846
dd3f0871d8b7 [primary view] add 'verbatim' attribute view (closes #1947475)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7832
diff changeset
    68
_rc.tag_attribute(('CWSource', 'config'), {'rvid': 'verbatimattr'})
dd3f0871d8b7 [primary view] add 'verbatim' attribute view (closes #1947475)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7832
diff changeset
    69
_rc.tag_attribute(('CWSourceHostConfig', 'config'), {'rvid': 'verbatimattr'})
dd3f0871d8b7 [primary view] add 'verbatim' attribute view (closes #1947475)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7832
diff changeset
    70
_rc.tag_attribute(('CWSourceSchemaConfig', 'options'), {'rvid': 'verbatimattr'})
6944
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
    71
6724
24bf6f181d0e [pyro source] store pyro source mapping file into the database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    72
24bf6f181d0e [pyro source] store pyro source mapping file into the database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    73
class CWSourcePrimaryView(tabs.TabbedPrimaryView):
24bf6f181d0e [pyro source] store pyro source mapping file into the database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    74
    __select__ = is_instance('CWSource')
7995
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
    75
    tabs = [_('cwsource-main'), _('cwsource-mapping'), _('cwsource-imports')]
6724
24bf6f181d0e [pyro source] store pyro source mapping file into the database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    76
    default_tab = 'cwsource-main'
24bf6f181d0e [pyro source] store pyro source mapping file into the database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    77
24bf6f181d0e [pyro source] store pyro source mapping file into the database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    78
24bf6f181d0e [pyro source] store pyro source mapping file into the database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    79
class CWSourceMainTab(tabs.PrimaryTab):
24bf6f181d0e [pyro source] store pyro source mapping file into the database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    80
    __regid__ = 'cwsource-main'
7995
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
    81
    __select__ = is_instance('CWSource')
6724
24bf6f181d0e [pyro source] store pyro source mapping file into the database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    82
7832
953f224357af [sources management] nicer source management view and breadcrumbs (closes #1946329)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7806
diff changeset
    83
    def render_entity_attributes(self, entity):
953f224357af [sources management] nicer source management view and breadcrumbs (closes #1946329)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7806
diff changeset
    84
        super(CWSourceMainTab, self).render_entity_attributes(entity)
953f224357af [sources management] nicer source management view and breadcrumbs (closes #1946329)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7806
diff changeset
    85
        self.w(add_etype_button(self._cw, 'CWSourceHostConfig',
953f224357af [sources management] nicer source management view and breadcrumbs (closes #1946329)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7806
diff changeset
    86
                                __linkto='cw_host_config_of:%s:subject' % entity.eid,
953f224357af [sources management] nicer source management view and breadcrumbs (closes #1946329)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7806
diff changeset
    87
                                __redirectpath=entity.rest_path()))
953f224357af [sources management] nicer source management view and breadcrumbs (closes #1946329)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7806
diff changeset
    88
        try:
953f224357af [sources management] nicer source management view and breadcrumbs (closes #1946329)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7806
diff changeset
    89
            hostconfig = self._cw.execute(
953f224357af [sources management] nicer source management view and breadcrumbs (closes #1946329)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7806
diff changeset
    90
                'Any X, XC, XH WHERE X cw_host_config_of S, S eid %(s)s, '
953f224357af [sources management] nicer source management view and breadcrumbs (closes #1946329)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7806
diff changeset
    91
                'X config XC, X match_host XH', {'s': entity.eid})
953f224357af [sources management] nicer source management view and breadcrumbs (closes #1946329)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7806
diff changeset
    92
        except Unauthorized:
953f224357af [sources management] nicer source management view and breadcrumbs (closes #1946329)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7806
diff changeset
    93
            pass
953f224357af [sources management] nicer source management view and breadcrumbs (closes #1946329)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7806
diff changeset
    94
        else:
953f224357af [sources management] nicer source management view and breadcrumbs (closes #1946329)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7806
diff changeset
    95
            if hostconfig:
953f224357af [sources management] nicer source management view and breadcrumbs (closes #1946329)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7806
diff changeset
    96
                self.w(u'<h3>%s</h3>' % self._cw._('CWSourceHostConfig_plural'))
7992
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7935
diff changeset
    97
                self._cw.view('table', hostconfig, w=self.w,
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7935
diff changeset
    98
                              displaycols=range(2),
4ff9f25cb06e [table views] closes #1986413: refactor TableView, EntityAttributesTableView, PyValTableView
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7935
diff changeset
    99
                              cellvids={1: 'editable-final'})
7832
953f224357af [sources management] nicer source management view and breadcrumbs (closes #1946329)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7806
diff changeset
   100
6724
24bf6f181d0e [pyro source] store pyro source mapping file into the database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   101
6944
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   102
MAPPED_SOURCE_TYPES = set( ('pyrorql', 'datafeed') )
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   103
6724
24bf6f181d0e [pyro source] store pyro source mapping file into the database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   104
class CWSourceMappingTab(EntityView):
24bf6f181d0e [pyro source] store pyro source mapping file into the database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   105
    __regid__ = 'cwsource-mapping'
7995
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   106
    __select__ = (is_instance('CWSource')
6944
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   107
                  & match_user_groups('managers')
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   108
                  & score_entity(lambda x:x.type in MAPPED_SOURCE_TYPES))
6724
24bf6f181d0e [pyro source] store pyro source mapping file into the database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   109
24bf6f181d0e [pyro source] store pyro source mapping file into the database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   110
    def entity_call(self, entity):
24bf6f181d0e [pyro source] store pyro source mapping file into the database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   111
        _ = self._cw._
6944
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   112
        self.w('<h3>%s</h3>' % _('Entity and relation supported by this source'))
7806
aa30c665bd06 [refactoring] introduce add_etype_button function to properly create button to add a new entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7804
diff changeset
   113
        self.w(add_etype_button(self._cw, 'CWSourceSchemaConfig',
aa30c665bd06 [refactoring] introduce add_etype_button function to properly create button to add a new entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7804
diff changeset
   114
                                __linkto='cw_for_source:%s:subject' % entity.eid))
aa30c665bd06 [refactoring] introduce add_etype_button function to properly create button to add a new entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7804
diff changeset
   115
        self.w(u'<div class="clear"></div>')
6944
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   116
        rset = self._cw.execute(
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   117
            'Any X, SCH, XO ORDERBY ET WHERE X options XO, X cw_for_source S, S eid %(s)s, '
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   118
            'X cw_schema SCH, SCH is ET', {'s': entity.eid})
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   119
        self.wview('table', rset, 'noresult')
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   120
        # self.w('<h3>%s</h3>' % _('Relations that should not be crossed'))
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   121
        # self.w('<p>%s</p>' % _(
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   122
        #     'By default, when a relation is not supported by a source, it is '
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   123
        #     'supposed that a local relation may point to an entity from the '
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   124
        #     'external source. Relations listed here won\'t have this '
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   125
        #     '"crossing" behaviour.'))
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   126
        # self.wview('list', entity.related('cw_dont_cross'), 'noresult')
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   127
        # self.w('<h3>%s</h3>' % _('Relations that can be crossed'))
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   128
        # self.w('<p>%s</p>' % _(
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   129
        #     'By default, when a relation is supported by a source, it is '
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   130
        #     'supposed that a local relation can\'t point to an entity from the '
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   131
        #     'external source. Relations listed here may have this '
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   132
        #     '"crossing" behaviour anyway.'))
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   133
        # self.wview('list', entity.related('cw_may_cross'), 'noresult')
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   134
        checker = MAPPING_CHECKERS.get(entity.type, MappingChecker)(entity)
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   135
        checker.check()
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   136
        if (checker.errors or checker.warnings or checker.infos):
7806
aa30c665bd06 [refactoring] introduce add_etype_button function to properly create button to add a new entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7804
diff changeset
   137
            self.w('<h2>%s</h2>' % _('Detected problems'))
aa30c665bd06 [refactoring] introduce add_etype_button function to properly create button to add a new entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7804
diff changeset
   138
            errors = zip(repeat(_('error')), checker.errors)
aa30c665bd06 [refactoring] introduce add_etype_button function to properly create button to add a new entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7804
diff changeset
   139
            warnings = zip(repeat(_('warning')), checker.warnings)
aa30c665bd06 [refactoring] introduce add_etype_button function to properly create button to add a new entity
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7804
diff changeset
   140
            infos = zip(repeat(_('warning')), checker.infos)
8136
273d8a03700c [sources management] fix crash mapping tab because chain() is not indexable. Closes #2124077
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7995
diff changeset
   141
            self.wview('pyvaltable', pyvalue=errors + warnings + infos)
6724
24bf6f181d0e [pyro source] store pyro source mapping file into the database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   142
6944
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   143
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   144
class MappingChecker(object):
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   145
    def __init__(self, cwsource):
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   146
        self.cwsource = cwsource
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   147
        self.errors = []
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   148
        self.warnings = []
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   149
        self.infos = []
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   150
        self.schema = cwsource._cw.vreg.schema
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   151
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   152
    def init(self):
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   153
        # supported entity types
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   154
        self.sentities = set()
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   155
        # supported relations
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   156
        self.srelations = {}
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   157
        # avoid duplicated messages
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   158
        self.seen = set()
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   159
        # first get mapping as dict/sets
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   160
        for schemacfg in self.cwsource.reverse_cw_for_source:
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   161
            self.init_schemacfg(schemacfg)
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   162
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   163
    def init_schemacfg(self, schemacfg):
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   164
        cwerschema = schemacfg.schema
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   165
        if cwerschema.__regid__ == 'CWEType':
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   166
            self.sentities.add(cwerschema.name)
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   167
        elif cwerschema.__regid__ == 'CWRType':
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   168
            assert not cwerschema.name in self.srelations
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   169
            self.srelations[cwerschema.name] = None
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   170
        else: # CWAttribute/CWRelation
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   171
            self.srelations.setdefault(cwerschema.rtype.name, []).append(
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   172
                (cwerschema.stype.name, cwerschema.otype.name) )
7375
c8a8fb32733b [cw source ui] fix mapping checking for datafeed source (avoid false positive error, but doesn't check that much things)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7019
diff changeset
   173
            self.sentities.add(cwerschema.stype.name)
c8a8fb32733b [cw source ui] fix mapping checking for datafeed source (avoid false positive error, but doesn't check that much things)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7019
diff changeset
   174
            self.sentities.add(cwerschema.otype.name)
6944
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   175
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   176
    def check(self):
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   177
        self.init()
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   178
        error = self.errors.append
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   179
        warning = self.warnings.append
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   180
        info = self.infos.append
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   181
        for etype in self.sentities:
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   182
            eschema = self.schema[etype]
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   183
            for rschema, ttypes, role in eschema.relation_definitions():
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   184
                if rschema in META_RTYPES:
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   185
                    continue
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   186
                ttypes = [ttype for ttype in ttypes if ttype in self.sentities]
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   187
                if not rschema in self.srelations:
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   188
                    for ttype in ttypes:
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   189
                        rdef = rschema.role_rdef(etype, ttype, role)
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   190
                        self.seen.add(rdef)
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   191
                        if rdef.role_cardinality(role) in '1+':
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   192
                            error(_('relation %(type)s with %(etype)s as %(role)s '
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   193
                                    'and target type %(target)s is mandatory but '
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   194
                                    'not supported') %
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   195
                                  {'rtype': rschema, 'etype': etype, 'role': role,
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   196
                                   'target': ttype})
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   197
                        elif ttype in self.sentities:
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   198
                            warning(_('%s could be supported') % rdef)
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   199
                elif not ttypes:
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   200
                    warning(_('relation %(rtype)s with %(etype)s as %(role)s is '
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   201
                              'supported but no target type supported') %
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   202
                            {'rtype': rschema, 'role': role, 'etype': etype})
7375
c8a8fb32733b [cw source ui] fix mapping checking for datafeed source (avoid false positive error, but doesn't check that much things)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7019
diff changeset
   203
        for rtype, rdefs in self.srelations.iteritems():
c8a8fb32733b [cw source ui] fix mapping checking for datafeed source (avoid false positive error, but doesn't check that much things)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7019
diff changeset
   204
            if rdefs is None:
c8a8fb32733b [cw source ui] fix mapping checking for datafeed source (avoid false positive error, but doesn't check that much things)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7019
diff changeset
   205
                rschema = self.schema[rtype]
c8a8fb32733b [cw source ui] fix mapping checking for datafeed source (avoid false positive error, but doesn't check that much things)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7019
diff changeset
   206
                for subj, obj in rschema.rdefs:
c8a8fb32733b [cw source ui] fix mapping checking for datafeed source (avoid false positive error, but doesn't check that much things)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7019
diff changeset
   207
                    if subj in self.sentities and obj in self.sentities:
c8a8fb32733b [cw source ui] fix mapping checking for datafeed source (avoid false positive error, but doesn't check that much things)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7019
diff changeset
   208
                        break
c8a8fb32733b [cw source ui] fix mapping checking for datafeed source (avoid false positive error, but doesn't check that much things)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7019
diff changeset
   209
                else:
c8a8fb32733b [cw source ui] fix mapping checking for datafeed source (avoid false positive error, but doesn't check that much things)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7019
diff changeset
   210
                    error(_('relation %s is supported but none of its definitions '
c8a8fb32733b [cw source ui] fix mapping checking for datafeed source (avoid false positive error, but doesn't check that much things)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7019
diff changeset
   211
                            'matches supported entities') % rtype)
6944
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   212
        self.custom_check()
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   213
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   214
    def custom_check(self):
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   215
        pass
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   216
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   217
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   218
class PyroRQLMappingChecker(MappingChecker):
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   219
    """pyrorql source mapping checker"""
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   220
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   221
    def init(self):
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   222
        self.dontcross = set()
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   223
        self.maycross = set()
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   224
        super(PyroRQLMappingChecker, self).init()
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   225
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   226
    def init_schemacfg(self, schemacfg):
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   227
        options = schemacfg.options or ()
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   228
        if 'dontcross' in options:
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   229
            self.dontcross.add(schemacfg.schema.name)
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   230
        else:
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   231
            super(PyroRQLMappingChecker, self).init_schemacfg(schemacfg)
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   232
            if 'maycross' in options:
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   233
                self.maycross.add(schemacfg.schema.name)
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   234
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   235
    def custom_check(self):
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   236
        error = self.errors.append
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   237
        info = self.infos.append
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   238
        for etype in self.sentities:
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   239
            eschema = self.schema[etype]
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   240
            for rschema, ttypes, role in eschema.relation_definitions():
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   241
                if rschema in META_RTYPES:
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   242
                    continue
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   243
                if not rschema in self.srelations:
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   244
                    if rschema not in self.dontcross:
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   245
                        if role == 'subject' and rschema.inlined:
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   246
                            error(_('inlined relation %(rtype)s of %(etype)s '
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   247
                                    'should be supported') %
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   248
                                  {'rtype': rschema, 'etype': etype})
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   249
                        elif (rschema not in self.seen and rschema not in self.maycross):
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   250
                            info(_('you may want to specify something for %s') %
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   251
                                 rschema)
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   252
                            self.seen.add(rschema)
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   253
                elif rschema in self.maycross and rschema.inlined:
6724
24bf6f181d0e [pyro source] store pyro source mapping file into the database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   254
                    error(_('you should un-inline relation %s which is '
24bf6f181d0e [pyro source] store pyro source mapping file into the database
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   255
                            'supported and may be crossed ') % rschema)
6944
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   256
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   257
MAPPING_CHECKERS = {
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   258
    'pyrorql': PyroRQLMappingChecker,
0cf10429ad39 [sources] rewrite the way pyrorql mapping are stored in the database so it can be reused for other sources (eg datafeed+cwxml)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6724
diff changeset
   259
    }
6962
220e32f058be [management ui] add views to manage sources similarly to users
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6944
diff changeset
   260
7995
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   261
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   262
class CWSourceImportsTab(EntityView):
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   263
    __regid__ = 'cwsource-imports'
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   264
    __select__ = (is_instance('CWSource')
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   265
                  & has_related_entities('cw_import_of', 'object'))
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   266
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   267
    def entity_call(self, entity):
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   268
        rset = self._cw.execute('Any X, XST, XET, XS ORDERBY XST DESC WHERE '
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   269
                                'X cw_import_of S, S eid %(s)s, X status XS, '
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   270
                                'X start_timestamp XST, X end_timestamp XET',
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   271
                                {'s': entity.eid})
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   272
        self._cw.view('cw.imports-table', rset, w=self.w)
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   273
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   274
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   275
class CWImportsTable(tableview.EntityTableView):
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   276
    __regid__ = 'cw.imports-table'
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   277
    __select__ = is_instance('CWDataImport')
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   278
    columns = ['import', 'start_timestamp', 'end_timestamp']
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   279
    column_renderers = {'import': tableview.MainEntityColRenderer()}
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   280
    layout_args = {'display_filter': 'top'}
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   281
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   282
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   283
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   284
6962
220e32f058be [management ui] add views to manage sources similarly to users
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6944
diff changeset
   285
# sources management view ######################################################
220e32f058be [management ui] add views to manage sources similarly to users
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6944
diff changeset
   286
220e32f058be [management ui] add views to manage sources similarly to users
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6944
diff changeset
   287
class ManageSourcesAction(actions.ManagersAction):
220e32f058be [management ui] add views to manage sources similarly to users
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6944
diff changeset
   288
    __regid__ = 'cwsource'
220e32f058be [management ui] add views to manage sources similarly to users
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6944
diff changeset
   289
    title = _('data sources')
220e32f058be [management ui] add views to manage sources similarly to users
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6944
diff changeset
   290
    category = 'manage'
220e32f058be [management ui] add views to manage sources similarly to users
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6944
diff changeset
   291
7994
af3fb709c061 [management table] upgrade sources groups management table to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7992
diff changeset
   292
af3fb709c061 [management table] upgrade sources groups management table to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7992
diff changeset
   293
class CWSourcesManagementView(StartupView):
af3fb709c061 [management table] upgrade sources groups management table to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7992
diff changeset
   294
    __regid__ = 'cw.sources-management'
af3fb709c061 [management table] upgrade sources groups management table to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7992
diff changeset
   295
    rql = ('Any S,ST,SP,SD,SN ORDERBY SN WHERE S is CWSource, S name SN, S type ST, '
7455
694b21f0fc62 [views] add columns parser and latest_retrieval to cwsource admin view
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 7375
diff changeset
   296
           'S latest_retrieval SD, S parser SP')
6962
220e32f058be [management ui] add views to manage sources similarly to users
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6944
diff changeset
   297
    title = _('data sources management')
220e32f058be [management ui] add views to manage sources similarly to users
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6944
diff changeset
   298
220e32f058be [management ui] add views to manage sources similarly to users
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6944
diff changeset
   299
    def call(self, **kwargs):
220e32f058be [management ui] add views to manage sources similarly to users
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6944
diff changeset
   300
        self.w('<h1>%s</h1>' % self._cw._(self.title))
7852
cb3f700399b2 [schema, cleanup] one more case for add_etype_button
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7846
diff changeset
   301
        self.w(add_etype_button(self._cw, 'CWSource'))
cb3f700399b2 [schema, cleanup] one more case for add_etype_button
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7846
diff changeset
   302
        self.w(u'<div class="clear"></div>')
7994
af3fb709c061 [management table] upgrade sources groups management table to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7992
diff changeset
   303
        self.wview('cw.sources-table', self._cw.execute(self.rql))
af3fb709c061 [management table] upgrade sources groups management table to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7992
diff changeset
   304
af3fb709c061 [management table] upgrade sources groups management table to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7992
diff changeset
   305
af3fb709c061 [management table] upgrade sources groups management table to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7992
diff changeset
   306
class CWSourcesTable(tableview.EntityTableView):
af3fb709c061 [management table] upgrade sources groups management table to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7992
diff changeset
   307
    __regid__ = 'cw.sources-table'
af3fb709c061 [management table] upgrade sources groups management table to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7992
diff changeset
   308
    __select__ = is_instance('CWSource')
7995
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   309
    columns = ['source', 'type', 'parser', 'latest_retrieval', 'latest_import']
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   310
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   311
    class LatestImportColRenderer(tableview.EntityTableColRenderer):
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   312
        def render_cell(self, w, rownum):
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   313
            entity = self.entity(rownum)
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   314
            rset = self._cw.execute('Any X,XS,XST ORDERBY XST DESC LIMIT 1 WHERE '
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   315
                                    'X cw_import_of S, S eid %(s)s, X status XS, '
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   316
                                    'X start_timestamp XST', {'s': entity.eid})
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   317
            if rset:
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   318
                self._cw.view('incontext', rset, row=0, w=w)
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   319
            else:
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   320
                w(self.empty_cell_content)
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   321
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   322
    column_renderers = {
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   323
        'source': tableview.MainEntityColRenderer(),
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   324
        'latest_import': LatestImportColRenderer(header=_('latest import'),
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   325
                                                 sortable=False)
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   326
        }
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   327
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   328
# datafeed source import #######################################################
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   329
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   330
REVERSE_SEVERITIES = {
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   331
    logging.DEBUG :   _('DEBUG'),
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   332
    logging.INFO :    _('INFO'),
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   333
    logging.WARNING : _('WARNING'),
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   334
    logging.ERROR :   _('ERROR'),
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   335
    logging.FATAL :   _('FATAL')
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   336
}
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   337
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   338
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   339
def log_to_table(req, rawdata):
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   340
    data = []
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   341
    for msg_idx, msg in enumerate(rawdata.split('<br/>')):
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   342
        record = msg.strip()
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   343
        if not record:
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   344
            continue
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   345
        try:
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   346
            severity, url, line, msg = record.split('\t', 3)
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   347
        except ValueError:
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   348
            req.warning('badly formated log %s' % record)
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   349
            url = line = u''
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   350
            severity = logging.DEBUG
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   351
            msg = record
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   352
        data.append( (severity, url, line, msg) )
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   353
    return data
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   354
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   355
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   356
class LogTableLayout(tableview.TableLayout):
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   357
    __select__ = match_view('cw.log.table')
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   358
    needs_js = tableview.TableLayout.needs_js + ('cubicweb.log.js',)
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   359
    needs_css = tableview.TableLayout.needs_css + ('cubicweb.log.css',)
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   360
    columns_css = {
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   361
        0: 'logSeverity',
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   362
        1: 'logPath',
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   363
        2: 'logLine',
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   364
        3: 'logMsg',
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   365
        }
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   366
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   367
    def render_table(self, w, actions, paginate):
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   368
        default_level = self.view.cw_extra_kwargs['default_level']
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   369
        if default_level != 'Debug':
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   370
            self._cw.add_onload('$("select.logFilter").val("%s").change();'
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   371
                           % self._cw.form.get('logLevel', default_level))
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   372
        w(u'\n<form action="#"><fieldset>')
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   373
        w(u'<label>%s</label>' % self._cw._(u'Message threshold'))
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   374
        w(u'<select class="log_filter" onchange="filterLog(\'%s\', this.options[this.selectedIndex].value)">'
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   375
          % self.view.domid)
8407
6874eb7a08e8 [logs table view] properly translate level buy using the correct msgid. Closes #2356329
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8405
diff changeset
   376
        for level in ('DEBUG', 'INFO', 'WARNING', 'ERROR', 'FATAL'):
6874eb7a08e8 [logs table view] properly translate level buy using the correct msgid. Closes #2356329
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8405
diff changeset
   377
            w('<option value="%s">%s</option>' % (level.capitalize(),
6874eb7a08e8 [logs table view] properly translate level buy using the correct msgid. Closes #2356329
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8405
diff changeset
   378
                                                  self._cw._(level)))
7995
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   379
        w(u'</select>')
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   380
        w(u'</fieldset></form>')
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   381
        super(LogTableLayout, self).render_table(w, actions, paginate)
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   382
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   383
    def table_attributes(self):
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   384
        attrs = super(LogTableLayout, self).table_attributes()
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   385
        attrs['id'] = 'table'+self.view.domid
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   386
        return attrs
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   387
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   388
    def row_attributes(self, rownum):
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   389
        attrs = super(LogTableLayout, self).row_attributes(rownum)
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   390
        attrs['id'] = 'log_msg_%i' % rownum
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   391
        severityname = REVERSE_SEVERITIES[int(self.view.pyvalue[rownum][0])]
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   392
        attrs['class'] = 'log%s' % severityname.capitalize()
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   393
        return attrs
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   394
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   395
    def cell_attributes(self, rownum, colnum, colid):
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   396
        attrs = super(LogTableLayout, self).cell_attributes(rownum, colnum, colid)
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   397
        attrs['class'] = self.columns_css[colnum]
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   398
        return attrs
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   399
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   400
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   401
class LogTable(pyviews.PyValTableView):
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   402
    __regid__ = 'cw.log.table'
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   403
    headers = [_('severity'), _('url'), _('line'), _('message')]
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   404
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   405
    @cachedproperty
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   406
    def domid(self):
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   407
        return make_uid('logTable')
7994
af3fb709c061 [management table] upgrade sources groups management table to new api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7992
diff changeset
   408
7995
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   409
    class SeverityRenderer(pyviews.PyValTableColRenderer):
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   410
        def render_cell(self, w, rownum):
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   411
            severity = self.data[rownum][0]
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   412
            w(u'<a class="internallink" href="javascript:;" title="%(title)s" '
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   413
              u'''onclick="document.location.hash='%(msg_id)s';">&#182;</a>'''
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   414
              u'&#160;%(severity)s' % {
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   415
                'severity': self._cw._(REVERSE_SEVERITIES[int(severity)]),
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   416
                'title': self._cw._('permalink to this message'),
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   417
                'msg_id': 'log_msg_%i' % rownum,
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   418
            })
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   419
        def sortvalue(self, rownum):
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   420
            return int(self.data[rownum][0])
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   421
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   422
    class URLRenderer(pyviews.PyValTableColRenderer):
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   423
        def render_cell(self, w, rownum):
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   424
            url = self.data[rownum][1]
8405
e83725261adf [logs table view] only put values starting with http in <a> tag
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8166
diff changeset
   425
            if url and url.startswith('http'):
e83725261adf [logs table view] only put values starting with http in <a> tag
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8166
diff changeset
   426
                url = tags.a(url, href=url)
e83725261adf [logs table view] only put values starting with http in <a> tag
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8166
diff changeset
   427
            w(url or u'&#160;')
7995
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   428
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   429
    class LineRenderer(pyviews.PyValTableColRenderer):
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   430
        def render_cell(self, w, rownum):
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   431
            line = self.data[rownum][2]
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   432
            w(line or u'&#160;')
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   433
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   434
    class MessageRenderer(pyviews.PyValTableColRenderer):
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   435
        snip_over = 7
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   436
        def render_cell(self, w, rownum):
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   437
            msg = self.data[rownum][3]
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   438
            lines = msg.splitlines()
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   439
            if len(lines) <= self.snip_over:
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   440
                w(u'<pre class="rawtext">%s</pre>' % msg)
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   441
            else:
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   442
                # The make_uid argument has no specific meaning here.
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   443
                div_snip_id = make_uid(u'log_snip_')
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   444
                div_full_id = make_uid(u'log_full_')
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   445
                divs_id = (div_snip_id, div_full_id)
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   446
                snip = u'\n'.join((lines[0], lines[1],
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   447
                                   u'  ...',
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   448
                                   u'    %i more lines [double click to expand]' % (len(lines)-4),
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   449
                                   u'  ...',
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   450
                                   lines[-2], lines[-1]))
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   451
                divs = (
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   452
                        (div_snip_id, snip, u'expand', "class='collapsed'"),
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   453
                        (div_full_id, msg,  u'collapse', "class='hidden'")
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   454
                )
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   455
                for div_id, content, button, h_class in divs:
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   456
                    text = self._cw._(button)
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   457
                    js = u"toggleVisibility('%s'); toggleVisibility('%s');" % divs_id
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   458
                    w(u'<div id="%s" %s>' % (div_id, h_class))
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   459
                    w(u'<pre class="raw_test" ondblclick="javascript: %s" '
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   460
                      u'title="%s" style="display: block;">' % (js, text))
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   461
                    w(content)
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   462
                    w(u'</pre>')
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   463
                    w(u'</div>')
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   464
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   465
    column_renderers = {0: SeverityRenderer(),
8166
20809488fe56 [datafeed] Don't pretend all columns are sortable in datafeed sources import log view. Closes #2146387
Julien Cristau <julien.cristau@logilab.fr>
parents: 8150
diff changeset
   466
                        1: URLRenderer(sortable=False),
20809488fe56 [datafeed] Don't pretend all columns are sortable in datafeed sources import log view. Closes #2146387
Julien Cristau <julien.cristau@logilab.fr>
parents: 8150
diff changeset
   467
                        2: LineRenderer(sortable=False),
20809488fe56 [datafeed] Don't pretend all columns are sortable in datafeed sources import log view. Closes #2146387
Julien Cristau <julien.cristau@logilab.fr>
parents: 8150
diff changeset
   468
                        3: MessageRenderer(sortable=False),
7995
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   469
                        }
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   470
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   471
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   472
class DataFeedSourceDataImport(EntityView):
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   473
    __select__ = EntityView.__select__ & match_kwargs('rtype')
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   474
    __regid__ = 'cw.formated_log'
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   475
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   476
    def cell_call(self, row, col, rtype, loglevel='Info', **kwargs):
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   477
        if 'dispctrl' in self.cw_extra_kwargs:
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   478
            loglevel = self.cw_extra_kwargs['dispctrl'].get('loglevel', loglevel)
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   479
        entity = self.cw_rset.get_entity(row, col)
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   480
        value = getattr(entity, rtype)
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   481
        if value:
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   482
            self._cw.view('cw.log.table', pyvalue=log_to_table(self._cw, value),
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   483
                          default_level=loglevel, w=self.w)
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   484
        else:
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   485
            self.w(self._cw._('no log to display'))
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   486
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   487
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   488
_pvs.tag_attribute(('CWDataImport', 'log'), 'relations')
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   489
_pvdc.tag_attribute(('CWDataImport', 'log'), {'vid': 'cw.formated_log'})
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   490
_pvs.tag_subject_of(('CWDataImport', 'cw_import_of', '*'), 'hidden') # in breadcrumbs
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   491
_pvs.tag_object_of(('*', 'cw_import_of', 'CWSource'), 'hidden') # in dedicated tab
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   492
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   493
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   494
class CWDataImportIPrevNextAdapter(navigation.IPrevNextAdapter):
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   495
    __select__ = is_instance('CWDataImport')
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   496
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   497
    def next_entity(self):
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   498
        if self.entity.start_timestamp is not None:
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   499
            # add NOT X eid %(e)s because > may not be enough
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   500
            rset = self._cw.execute(
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   501
                'Any X,XSTS ORDERBY 2 LIMIT 1 WHERE X is CWDataImport, '
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   502
                'X cw_import_of S, S eid %(s)s, NOT X eid %(e)s, '
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   503
                'X start_timestamp XSTS, X start_timestamp > %(sts)s',
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   504
                {'sts': self.entity.start_timestamp,
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   505
                 'e': self.entity.eid,
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   506
                 's': self.entity.cwsource.eid})
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   507
            if rset:
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   508
                return rset.get_entity(0, 0)
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   509
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   510
    def previous_entity(self):
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   511
        if self.entity.start_timestamp is not None:
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   512
            # add NOT X eid %(e)s because < may not be enough
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   513
            rset = self._cw.execute(
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   514
                'Any X,XSTS ORDERBY 2 DESC LIMIT 1 WHERE X is CWDataImport, '
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   515
                'X cw_import_of S, S eid %(s)s, NOT X eid %(e)s, '
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   516
                'X start_timestamp XSTS, X start_timestamp < %(sts)s',
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   517
                {'sts': self.entity.start_timestamp,
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   518
                 'e': self.entity.eid,
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   519
                 's': self.entity.cwsource.eid})
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   520
            if rset:
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   521
                return rset.get_entity(0, 0)
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   522
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   523
class CWDataImportStatusFacet(facet.AttributeFacet):
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   524
    __regid__ = 'datafeed.dataimport.status'
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   525
    __select__ = is_instance('CWDataImport')
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   526
    rtype = 'status'
7832
953f224357af [sources management] nicer source management view and breadcrumbs (closes #1946329)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7806
diff changeset
   527
953f224357af [sources management] nicer source management view and breadcrumbs (closes #1946329)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7806
diff changeset
   528
953f224357af [sources management] nicer source management view and breadcrumbs (closes #1946329)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7806
diff changeset
   529
# breadcrumbs configuration ####################################################
953f224357af [sources management] nicer source management view and breadcrumbs (closes #1946329)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7806
diff changeset
   530
953f224357af [sources management] nicer source management view and breadcrumbs (closes #1946329)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7806
diff changeset
   531
class CWsourceConfigIBreadCrumbsAdapter(ibreadcrumbs.IBreadCrumbsAdapter):
953f224357af [sources management] nicer source management view and breadcrumbs (closes #1946329)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7806
diff changeset
   532
    __select__ = is_instance('CWSourceHostConfig', 'CWSourceSchemaConfig')
953f224357af [sources management] nicer source management view and breadcrumbs (closes #1946329)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7806
diff changeset
   533
    def parent_entity(self):
953f224357af [sources management] nicer source management view and breadcrumbs (closes #1946329)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7806
diff changeset
   534
        return self.entity.cwsource
7995
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   535
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   536
class CWDataImportIBreadCrumbsAdapter(ibreadcrumbs.IBreadCrumbsAdapter):
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   537
    __select__ = is_instance('CWDataImport')
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   538
    def parent_entity(self):
9a9f35ef418c Record a log of datafeed source imports (closes #2026097)
Julien Cristau <julien.cristau@logilab.fr>
parents: 7994
diff changeset
   539
        return self.entity.cw_import_of[0]