def processChildCount(actions): ''' Process the child count for the provided actions list. ''' actions = sorted(actions, key=lambda action: action.Path) for k, action in enumerate(actions): actionWithCount = Action() copy(action, actionWithCount, exclude=('ChildrenCount', )) childCount, path = 0, action.Path + '.' for i in range(k + 1, len(actions)): if actions[i].Path.startswith(path): childCount += 1 else: break actionWithCount.ChildrenCount = childCount yield actionWithCount
def processChildCount(actions): ''' Process the child count for the provided actions list. ''' actions = sorted(actions, key=lambda action: action.Path) for k, action in enumerate(actions): actionWithCount = Action() copy(action, actionWithCount, exclude=('ChildrenCount',)) childCount, path = 0, action.Path + '.' for i in range(k + 1, len(actions)): if actions[i].Path.startswith(path): childCount += 1 else: break actionWithCount.ChildrenCount = childCount yield actionWithCount
def menuAction(): return Action('media-archive', Parent=defaults.menuAction(), Label=NC_('Menu', 'Media Archive'), Href='/media-archive', ScriptPath=getPublishedGui( 'media-archive/scripts/js/menu-media-archive.js'))
def modulesAction(): ''' Register default action name: modules This node should contain actions to be used inside the application as main modules (whole page for edit/add/etc.) ''' return Action('modules')
def modulesDashboardAction(): ''' Register default action name: modules.dashboard This node should contain actions to be used inside the dashboard of the application as main modules (whole page for edit/add/etc.) ''' return Action('dashboard', Parent=modulesAction())
def modulesAction() -> Action: ''' register image plugin on media archive actions ''' return Action( 'video', Parent=mediaArchiveAction(), Script=publishedURI('media-archive-video/scripts/js/media-archive/'))
def insert(self, action): ''' @see IActionManagerService.insert ''' assert isinstance(action, Action), 'Invalid action %s' % action insertModel(ActionMapped, action) path = action.Path while '.' in path: path = path[:path.rfind('.')] if self.session().query(ActionMapped.Path).filter( ActionMapped.Path == path).count(): break insertModel(ActionMapped, Action(Path=path)) return action.Path
def modulesManageCollaboratorsAction() -> Action: return Action( 'manage-collaborators', Parent=modulesAction(), Script=publishedURI('livedesk/scripts/js/manage-collaborators.js'))
def modulesConfigureAction() -> Action: return Action('configure', Parent=modulesAction(), Script=publishedURI('livedesk/scripts/js/configure-blog.js'))
def modulesConfigureAction(): return Action('configure', Parent=modulesAction(), ScriptPath=getPublishedGui( 'media-archive/scripts/js/configure-media-archive.js'))
def modulesAddAction() -> Action: return Action('add', Parent=modulesAction(), Script=publishedURI('superdesk/article/scripts/js/add.js'))
def modulesAction() -> Action: return Action('livedesk', Parent=defaults.modulesAction())
def menuAction() -> Action: return Action('livedesk', Parent=defaults.menuAction(), Label=NC_('menu', 'Live Blogs'))
def menuAction() -> Action: return Action('article', Parent=defaults.menuAction(), Label=NC_('menu', 'Article'), NavBar='/article', Script=publishedURI('superdesk/article/scripts/js/menu.js'))
def process(self, chain, solicit: Solicit, **keyargs): ''' @see: HandlerProcessor.process Synchronize the actions in the configuration file with the actions in the database. ''' assert isinstance(chain, Chain), 'Invalid chain %s' % chain assert isinstance(solicit, Solicit), 'Invalid solicit %s' % solicit assert isinstance( solicit.repository, Repository), 'Invalid repository %s' % solicit.repository groups = listBFS(solicit.repository, Repository.children, Repository.actions) actionsFromConfig = {} # check for actions with the same path -> display warning message isWarning = False for repository in groups: assert isinstance(repository, Repository), 'Invalid repository %s' % repository for action in repository.actions: if action.path in actionsFromConfig: action1, action2 = action, actionsFromConfig[action.path] diffs = self.compareActions(action1, action2) if diffs: isWarning = True warningId = '%s_%s_%s' % (action.path, action1.lineNumber, action2.lineNumber) if warningId in self._warnings: continue log.warning( 'Attributes: "%s" are different for Action with path="%s" at Line %s and Line %s', ', '.join(diffs), action1.path, action1.lineNumber, action2.lineNumber) self._warnings.add(warningId) else: actionsFromConfig[action.path] = action # if everything was ok, erase all warnings if not isWarning and len(self._warnings) > 0: log.warning('Actions OK') self._warnings.clear() actionsFromDb = set(self.actionManagerService.getAll()) for action in sorted(actionsFromConfig.values(), key=lambda action: action.path): assert isinstance(action, ActionDefinition), 'Invalid action %s' % action data = asData(action, ActionDefinition) data = { modifyFirst(name, True): value for name, value in data.items() } apiAction = copyContainer(data, Action()) resolved = False if action.path not in actionsFromDb: try: self.actionManagerService.insert(apiAction) resolved = True except: log.warn('Cannot add action %s, maybe already exists' % apiAction.Path) if not resolved: self.actionManagerService.update(apiAction) # except: log.warn('Cannot update action %s' % apiAction.Path) actionsFromDb.discard(action.path) for path in actionsFromDb: self.actionManagerService.delete(path)
def modulesMainAction() -> Action: return Action('list', Parent=modulesAction(), Script=publishedURI('superdesk/article/scripts/js/list.js'))
def modulesEditAction() -> Action: return Action('edit', Parent=modulesAction(), Script=publishedURI('superdesk/article/scripts/js/edit.js'))
def modulesManageFeedsAction() -> Action: return Action('manage-feeds', Parent=modulesAction(), Script=publishedURI('livedesk/scripts/js/manage-feeds.js'))
def modulesAddAction() -> Action: return Action('add', Parent=modulesAction(), Script=publishedURI('livedesk/scripts/js/add-live-blogs.js'))
def modulesArchiveAction() -> Action: return Action('archive', Parent=modulesAction(), Script=publishedURI('livedesk/scripts/js/archive.js'))
def modulesBlogPublishAction() -> Action: return Action('blog-publish', Parent=modulesAction(), Script=publishedURI('livedesk/scripts/js/blog-publish.js'))
def subMenuAction() -> Action: return Action( 'submenu', Parent=menuAction(), Script=publishedURI('livedesk/scripts/js/submenu-live-blogs.js'))
def modulesAction() -> Action: return Action('request', Parent=defaults.modulesAction())
def dashboardAction() -> Action: return Action('livedesk', Parent=defaults.modulesDashboardAction(), Script=publishedURI('livedesk/scripts/js/dashboard.js'))
def modulesAction() -> Action: return Action('article', Parent=defaults.modulesAction())
def modulesBlogEditAction() -> Action: # TODO: change to view return Action( 'blog-edit', Parent=modulesAction(), Script=publishedURI('livedesk/scripts/js/edit-live-blogs.js'))
def modulesAction(): return Action('media-archive', Parent=defaults.modulesAction())
def menuAction() -> Action: return Action('request', NC_('menu', 'Request'), Parent=defaults.menuAction(), NavBar='/api-requests', Script=publishedURI('superdesk/request/scripts/js/menu.js'))
def modulesAddAction(): return Action( 'add', Parent=modulesAction(), ScriptPath=getPublishedGui('media-archive/scripts/js/add-media.js'))
def modulesListAction() -> Action: return Action('list', Parent=modulesAction(), Script=publishedURI('superdesk/request/scripts/js/list.js'))
def modulesMainAction(): return Action('main', Parent=modulesAction(), ScriptPath=getPublishedGui( 'media-archive/scripts/js/media-archive-main.js'))