22 __docformat__ = "restructuredtext en" |
22 __docformat__ = "restructuredtext en" |
23 _ = unicode |
23 _ = unicode |
24 |
24 |
25 from itertools import repeat, chain |
25 from itertools import repeat, chain |
26 |
26 |
|
27 from cubicweb import Unauthorized |
27 from cubicweb.selectors import is_instance, score_entity, match_user_groups |
28 from cubicweb.selectors import is_instance, score_entity, match_user_groups |
28 from cubicweb.view import EntityView, StartupView |
29 from cubicweb.view import EntityView, StartupView |
29 from cubicweb.schema import META_RTYPES, VIRTUAL_RTYPES, display_name |
30 from cubicweb.schema import META_RTYPES, VIRTUAL_RTYPES, display_name |
30 from cubicweb.web import uicfg, formwidgets as wdgs |
31 from cubicweb.web import uicfg, formwidgets as wdgs |
31 from cubicweb.web.views import tabs, actions, add_etype_button |
32 from cubicweb.web.views import tabs, actions, ibreadcrumbs, add_etype_button |
32 |
33 |
33 |
34 |
34 _abaa = uicfg.actionbox_appearsin_addmenu |
35 _abaa = uicfg.actionbox_appearsin_addmenu |
|
36 # there are explicit 'add' buttons for those |
35 _abaa.tag_object_of(('CWSourceSchemaConfig', 'cw_schema', '*'), False) |
37 _abaa.tag_object_of(('CWSourceSchemaConfig', 'cw_schema', '*'), False) |
36 _abaa.tag_object_of(('CWSourceSchemaConfig', 'cw_for_source', '*'), False) |
38 _abaa.tag_object_of(('CWSourceSchemaConfig', 'cw_for_source', '*'), False) |
|
39 _abaa.tag_object_of(('CWSourceSchemaConfig', 'cw_host_config_of', '*'), False) |
37 |
40 |
38 _afs = uicfg.autoform_section |
41 _afs = uicfg.autoform_section |
39 _afs.tag_attribute(('CWSource', 'synchronizing'), 'main', 'hidden') |
42 _afs.tag_attribute(('CWSource', 'synchronizing'), 'main', 'hidden') |
40 _afs.tag_object_of(('*', 'cw_for_source', 'CWSource'), 'main', 'hidden') |
43 _afs.tag_object_of(('*', 'cw_for_source', 'CWSource'), 'main', 'hidden') |
|
44 |
41 _affk = uicfg.autoform_field_kwargs |
45 _affk = uicfg.autoform_field_kwargs |
42 _affk.tag_attribute(('CWSource', 'parser'), {'widget': wdgs.TextInput}) |
46 _affk.tag_attribute(('CWSource', 'parser'), {'widget': wdgs.TextInput}) |
43 |
47 |
44 # source primary views ######################################################### |
48 # source primary views ######################################################### |
45 |
49 |
46 _pvs = uicfg.primaryview_section |
50 _pvs = uicfg.primaryview_section |
|
51 _pvs.tag_attribute(('CWSource', 'name'), 'hidden') |
47 _pvs.tag_object_of(('*', 'cw_for_source', 'CWSource'), 'hidden') |
52 _pvs.tag_object_of(('*', 'cw_for_source', 'CWSource'), 'hidden') |
|
53 _pvs.tag_object_of(('*', 'cw_host_config_of', 'CWSource'), 'hidden') |
|
54 |
|
55 _pvdc = uicfg.primaryview_display_ctrl |
|
56 _pvdc.tag_attribute(('CWSource', 'type'), {'vid': 'attribute'})# disable reledit |
|
57 |
|
58 _rc = uicfg.reledit_ctrl |
|
59 _rc.tag_attribute(('CWSource', 'config'), {'rvid': 'verbatim'}) |
|
60 _rc.tag_attribute(('CWSourceHostConfig', 'config'), {'rvid': 'verbatim'}) |
|
61 _rc.tag_attribute(('CWSourceSchemaConfig', 'options'), {'rvid': 'verbatim'}) |
48 |
62 |
49 |
63 |
50 class CWSourcePrimaryView(tabs.TabbedPrimaryView): |
64 class CWSourcePrimaryView(tabs.TabbedPrimaryView): |
51 __select__ = is_instance('CWSource') |
65 __select__ = is_instance('CWSource') |
52 tabs = [_('cwsource-main'), _('cwsource-mapping')] |
66 tabs = [_('cwsource-main'), _('cwsource-mapping')] |
54 |
68 |
55 |
69 |
56 class CWSourceMainTab(tabs.PrimaryTab): |
70 class CWSourceMainTab(tabs.PrimaryTab): |
57 __regid__ = 'cwsource-main' |
71 __regid__ = 'cwsource-main' |
58 __select__ = tabs.PrimaryTab.__select__ & is_instance('CWSource') |
72 __select__ = tabs.PrimaryTab.__select__ & is_instance('CWSource') |
|
73 |
|
74 def render_entity_attributes(self, entity): |
|
75 super(CWSourceMainTab, self).render_entity_attributes(entity) |
|
76 self.w(add_etype_button(self._cw, 'CWSourceHostConfig', |
|
77 __linkto='cw_host_config_of:%s:subject' % entity.eid, |
|
78 __redirectpath=entity.rest_path())) |
|
79 try: |
|
80 hostconfig = self._cw.execute( |
|
81 'Any X, XC, XH WHERE X cw_host_config_of S, S eid %(s)s, ' |
|
82 'X config XC, X match_host XH', {'s': entity.eid}) |
|
83 except Unauthorized: |
|
84 pass |
|
85 else: |
|
86 if hostconfig: |
|
87 self.w(u'<h3>%s</h3>' % self._cw._('CWSourceHostConfig_plural')) |
|
88 self._cw.view('editable-table', hostconfig, |
|
89 displaycols=range(2), w=self.w) |
59 |
90 |
60 |
91 |
61 MAPPED_SOURCE_TYPES = set( ('pyrorql', 'datafeed') ) |
92 MAPPED_SOURCE_TYPES = set( ('pyrorql', 'datafeed') ) |
62 |
93 |
63 class CWSourceMappingTab(EntityView): |
94 class CWSourceMappingTab(EntityView): |
237 self.w(u'<a href="%s" class="addButton right">%s</a>' % ( |
268 self.w(u'<a href="%s" class="addButton right">%s</a>' % ( |
238 self._cw.build_url('add/%s' % eschema), |
269 self._cw.build_url('add/%s' % eschema), |
239 self._cw._('add a CWSource'))) |
270 self._cw._('add a CWSource'))) |
240 self.w(u'<div class="clear"></div>') |
271 self.w(u'<div class="clear"></div>') |
241 self.wview('table', self._cw.execute(self.rql), displaycols=range(4)) |
272 self.wview('table', self._cw.execute(self.rql), displaycols=range(4)) |
|
273 |
|
274 |
|
275 # breadcrumbs configuration #################################################### |
|
276 |
|
277 class CWsourceConfigIBreadCrumbsAdapter(ibreadcrumbs.IBreadCrumbsAdapter): |
|
278 __select__ = is_instance('CWSourceHostConfig', 'CWSourceSchemaConfig') |
|
279 def parent_entity(self): |
|
280 return self.entity.cwsource |