web/views/cwsources.py
branchstable
changeset 7806 aa30c665bd06
parent 7804 814fb7f379a3
child 7832 953f224357af
equal deleted inserted replaced
7805:7111bb64b58f 7806:aa30c665bd06
    26 
    26 
    27 from cubicweb.selectors import is_instance, score_entity, match_user_groups
    27 from cubicweb.selectors import is_instance, score_entity, match_user_groups
    28 from cubicweb.view import EntityView, StartupView
    28 from cubicweb.view import EntityView, StartupView
    29 from cubicweb.schema import META_RTYPES, VIRTUAL_RTYPES, display_name
    29 from cubicweb.schema import META_RTYPES, VIRTUAL_RTYPES, display_name
    30 from cubicweb.web import uicfg, formwidgets as wdgs
    30 from cubicweb.web import uicfg, formwidgets as wdgs
    31 from cubicweb.web.views import tabs, actions
    31 from cubicweb.web.views import tabs, actions, add_etype_button
    32 
    32 
    33 
    33 
    34 _abaa = uicfg.actionbox_appearsin_addmenu
    34 _abaa = uicfg.actionbox_appearsin_addmenu
    35 _abaa.tag_object_of(('CWSourceSchemaConfig', 'cw_schema', '*'), False)
    35 _abaa.tag_object_of(('CWSourceSchemaConfig', 'cw_schema', '*'), False)
    36 _abaa.tag_object_of(('CWSourceSchemaConfig', 'cw_for_source', '*'), False)
    36 _abaa.tag_object_of(('CWSourceSchemaConfig', 'cw_for_source', '*'), False)
    67                   & score_entity(lambda x:x.type in MAPPED_SOURCE_TYPES))
    67                   & score_entity(lambda x:x.type in MAPPED_SOURCE_TYPES))
    68 
    68 
    69     def entity_call(self, entity):
    69     def entity_call(self, entity):
    70         _ = self._cw._
    70         _ = self._cw._
    71         self.w('<h3>%s</h3>' % _('Entity and relation supported by this source'))
    71         self.w('<h3>%s</h3>' % _('Entity and relation supported by this source'))
    72         eschema = self._cw.vreg.schema.eschema('CWSourceSchemaConfig')
    72         self.w(add_etype_button(self._cw, 'CWSourceSchemaConfig',
    73         if eschema.has_perm(self._cw, 'add'):
    73                                 __linkto='cw_for_source:%s:subject' % entity.eid))
    74             self.w(u'<a href="%s" class="addButton right">%s</a>' % (
    74         self.w(u'<div class="clear"></div>')
    75                 self._cw.build_url('add/%s' % eschema,
       
    76                                    __linkto='cw_for_source:%s:subject' % entity.eid),
       
    77                 self._cw._('add a CWSourceSchemaConfig')))
       
    78             self.w(u'<div class="clear"></div>')
       
    79         rset = self._cw.execute(
    75         rset = self._cw.execute(
    80             'Any X, SCH, XO ORDERBY ET WHERE X options XO, X cw_for_source S, S eid %(s)s, '
    76             'Any X, SCH, XO ORDERBY ET WHERE X options XO, X cw_for_source S, S eid %(s)s, '
    81             'X cw_schema SCH, SCH is ET', {'s': entity.eid})
    77             'X cw_schema SCH, SCH is ET', {'s': entity.eid})
    82         self.wview('table', rset, 'noresult')
    78         self.wview('table', rset, 'noresult')
    83         # self.w('<h3>%s</h3>' % _('Relations that should not be crossed'))
    79         # self.w('<h3>%s</h3>' % _('Relations that should not be crossed'))
    95         #     '"crossing" behaviour anyway.'))
    91         #     '"crossing" behaviour anyway.'))
    96         # self.wview('list', entity.related('cw_may_cross'), 'noresult')
    92         # self.wview('list', entity.related('cw_may_cross'), 'noresult')
    97         checker = MAPPING_CHECKERS.get(entity.type, MappingChecker)(entity)
    93         checker = MAPPING_CHECKERS.get(entity.type, MappingChecker)(entity)
    98         checker.check()
    94         checker.check()
    99         if (checker.errors or checker.warnings or checker.infos):
    95         if (checker.errors or checker.warnings or checker.infos):
   100                 self.w('<h2>%s</h2>' % _('Detected problems'))
    96             self.w('<h2>%s</h2>' % _('Detected problems'))
   101                 errors = zip(repeat(_('error')), checker.errors)
    97             errors = zip(repeat(_('error')), checker.errors)
   102                 warnings = zip(repeat(_('warning')), checker.warnings)
    98             warnings = zip(repeat(_('warning')), checker.warnings)
   103                 infos = zip(repeat(_('warning')), checker.infos)
    99             infos = zip(repeat(_('warning')), checker.infos)
   104                 self.wview('pyvaltable', pyvalue=chain(errors, warnings, infos))
   100             self.wview('pyvaltable', pyvalue=chain(errors, warnings, infos))
   105 
   101 
   106 
   102 
   107 class MappingChecker(object):
   103 class MappingChecker(object):
   108     def __init__(self, cwsource):
   104     def __init__(self, cwsource):
   109         self.cwsource = cwsource
   105         self.cwsource = cwsource