def import_tool(importer_path, project_name=None, mount_point=None, mount_label=None, **kw): importer = object_from_path(importer_path)() with ImportErrorHandler(importer, project_name, c.project) as handler,\ M.session.substitute_extensions(M.artifact_orm_session, [M.session.BatchIndexer]): try: M.artifact_orm_session._get().skip_last_updated = True app = importer.import_tool( c.project, c.user, project_name=project_name, mount_point=mount_point, mount_label=mount_label, **kw) # manually update project's last_updated field at the end of the # import instead of it being updated automatically by each artifact # since long-running task can cause stale project data to be saved M.Project.query.update( {'_id': c.project._id}, {'$set': {'last_updated': datetime.utcnow()}}) finally: M.artifact_orm_session._get().skip_last_updated = False M.artifact_orm_session.flush() M.session.BatchIndexer.flush() if app: with h.notifications_disabled(c.project, disabled=False): g.director.create_activity(c.user, "imported", app.config, related_nodes=[c.project], tags=['import']) handler.success(app)
def upsert_root(self, new_root, notify=True): p = WM.Page.query.get(app_config_id=self.config._id, title=new_root, deleted=False) if p is None: with h.push_config(c, app=self), h.notifications_disabled(c.project, disabled=not notify): p = WM.Page.upsert(new_root) p.viewable_by = ['all'] p.text = self.default_root_page_text() p.commit()
def _update_page(self, title, **post_data): with h.notifications_disabled(c.project): if not self.page: require_access(c.app, 'create') self.page = WM.Page.upsert(title) self.page.viewable_by = ['all'] else: require_access(self.page, 'edit') self.page.text = post_data['text'] if 'labels' in post_data: self.page.labels = post_data['labels'].split(',') self.page.commit() return {}
def _update_page(self, title, **post_data): with h.notifications_disabled(c.project): if not self.page: require_access(c.app, 'create') if WM.Page.is_limit_exceeded(c.app.config, user=c.user): log.warn('Page create/edit rate limit exceeded. %s', c.app.config.url()) raise forge_exc.HTTPTooManyRequests() self.page = WM.Page.upsert(title) self.page.viewable_by = ['all'] else: require_access(self.page, 'edit') self.page.text = post_data['text'] if 'labels' in post_data: self.page.labels = post_data['labels'].split(',') self.page.commit() return {}
def test_notifications_disabled(): project = Mock(notifications_disabled=False) with h.notifications_disabled(project): assert_equals(project.notifications_disabled, True) assert_equals(project.notifications_disabled, False)