diff -r 282880f81311 -r ef1cfc80d51c web/views/cwsources.py --- a/web/views/cwsources.py Mon Nov 30 14:54:30 2015 +0100 +++ b/web/views/cwsources.py Wed Dec 09 16:15:00 2015 +0100 @@ -33,10 +33,10 @@ from cubicweb import Unauthorized, tags from cubicweb.utils import make_uid from cubicweb.predicates import (is_instance, score_entity, has_related_entities, - match_user_groups, match_kwargs, match_view) + match_user_groups, match_kwargs, match_view, one_line_rset) from cubicweb.view import EntityView, StartupView from cubicweb.schema import META_RTYPES, VIRTUAL_RTYPES, display_name -from cubicweb.web import formwidgets as wdgs, facet +from cubicweb.web import Redirect, formwidgets as wdgs, facet, action from cubicweb.web.views import add_etype_button from cubicweb.web.views import (uicfg, tabs, actions, ibreadcrumbs, navigation, tableview, pyviews) @@ -226,6 +226,36 @@ layout_args = {'display_filter': 'top'} +class CWSourceSyncAction(action.Action): + __regid__ = 'cw.source-sync' + __select__ = (action.Action.__select__ & match_user_groups('managers') + & one_line_rset() & is_instance('CWSource') + & score_entity(lambda x: x.name != 'system')) + + title = _('synchronize') + category = 'mainactions' + order = 20 + + def url(self): + entity = self.cw_rset.get_entity(self.cw_row or 0, self.cw_col or 0) + return entity.absolute_url(vid=self.__regid__) + + +class CWSourceSyncView(EntityView): + __regid__ = 'cw.source-sync' + __select__ = (match_user_groups('managers') + & one_line_rset() & is_instance('CWSource') + & score_entity(lambda x: x.name != 'system')) + + title = _('synchronize') + + def entity_call(self, entity): + self._cw.call_service('source-sync', source_eid=entity.eid) + msg = self._cw._('Source has been synchronized') + url = entity.absolute_url(tab='cwsource-imports', __message=msg) + raise Redirect(url) + + # sources management view ######################################################