def get_project_events(self, project, days, minutes): """ List all events in project that happened in a given time span. """ events = [] project_href = Href(conf.url_projects_path + "/" + project.env_name) req = DummyReq('user', 'password', 'method', 'uri', 'args') req.permissions = ( 'TICKET_VIEW', 'CHANGESET_VIEW', 'WIKI_VIEW', 'ATTACHMENT_VIEW', 'DISCUSSION_VIEW', 'MILESTONE_VIEW') req.authname = 'authname' req.abs_href = project_href project_env = open_environment(conf.getEnvironmentSysPath(project.env_name), use_cache=True) event_provider = ProjectTimelineEvents(project_env) last_events = event_provider.get_timeline_events(req, time_in_days=days, time_in_minutes=minutes) for event in last_events: context = Context(resource=Resource(), href=project_href) context.req = req context.perm = req.perm events.append([project, event, context]) events.sort(lambda x, y: cmp(y[1]['date'], x[1]['date'])) return events
def _get_timeline_events(self, tracenviron): """ Get the timeline events for one project, based on the given in trac environment object. """ # skip empty projects if tracenviron is None: return None daterange = int(self.conf.activity_calculation_daterange) # end time of timeline is current time todate = datetime.now(datefmt.localtz) # start time of timeline is last update of if not known, last two monts fromdate = todate fromdate = fromdate - timedelta(days=daterange) stop = todate start = fromdate # events will continue the timeline events events = [] # Access event providers for timeline events event_providers = TimelineModule(tracenviron).event_providers # create a dummy request (see class above) req = DummyReq('user', 'password', 'method', 'uri', 'args') req.permissions = ('TICKET_VIEW', 'CHANGESET_VIEW', 'WIKI_VIEW', 'ATTACHMENT_VIEW', 'DISCUSSION_VIEW') req.authname = 'authname' # filters will contain the available timeline event types available_filters = [] for event_provider in event_providers: available_filters += event_provider.get_timeline_filters(req) or [] filters = [] # check the request or session for enabled filters, or use default for test in (lambda f: f[0] in req.args, lambda f: len(f) == 2 or f[2]): if filters: break filters = [f[0] for f in available_filters if test(f)] # do the actual event querying for provider in event_providers: # note: this is because if discussion is not in current project, do not fail try: for event in provider.get_timeline_events(req, start, stop, filters): events.append(self._event_data(provider, event)) except Exception: self.conf.log.exception( "ActivityCalculator.get_timeline_events(%s) couldn't get timeline events from %s." % (tracenviron.project_name, str(provider))) events.sort(lambda x, y: cmp(y['date'], x['date'])) return events
def get_project_events(self, project, days, minutes): """ List all events in project that happened in a given time span. """ events = [] project_href = Href(conf.url_projects_path + "/" + project.env_name) req = DummyReq('user', 'password', 'method', 'uri', 'args') req.permissions = ('TICKET_VIEW', 'CHANGESET_VIEW', 'WIKI_VIEW', 'ATTACHMENT_VIEW', 'DISCUSSION_VIEW', 'MILESTONE_VIEW') req.authname = 'authname' req.abs_href = project_href project_env = open_environment(conf.getEnvironmentSysPath( project.env_name), use_cache=True) event_provider = ProjectTimelineEvents(project_env) last_events = event_provider.get_timeline_events( req, time_in_days=days, time_in_minutes=minutes) for event in last_events: context = Context(resource=Resource(), href=project_href) context.req = req context.perm = req.perm events.append([project, event, context]) events.sort(lambda x, y: cmp(y[1]['date'], x[1]['date'])) return events
def _create_dummy_req(self, project_identifier): uri = "%s/%s" % (conf.url_projects_path, project_identifier) req = DummyReq('user', 'password', 'method', uri, 'args') try: req.permissions = self._read_all_actions() except: req.permissions = [] req.authname = 'authname' return req
def test_request_when_have_parent(self): view = multiproject.project.admin.projectrelations.ProjectForkingAdminPanel(self.cm) conf.use_test_db(True) self.load_fixtures() req = DummyReq("username", "password", "GET", "/trac/cartoons", {}) req.permissions = ['TRAC_ADMIN'] view.env = DummyEnv(req) page, data = view.render_admin_panel(req, None, None, None) self.assertEquals(page, 'admin_relations_panel.html') self.assertIn('_project_', data) self.assertIn('parent_project', data) self.assertIn('child_projects', data) self.assertIn('home', data) self.assertEquals(len(data['child_projects']), 0) self.assertEquals(data['parent_project'].env_name, 'publicroject')
def test_request_when_have_parent(self): view = multiproject.project.admin.projectrelations.ProjectForkingAdminPanel( self.cm) conf.use_test_db(True) self.load_fixtures() req = DummyReq("username", "password", "GET", "/trac/cartoons", {}) req.permissions = ['TRAC_ADMIN'] view.env = DummyEnv(req) page, data = view.render_admin_panel(req, None, None, None) self.assertEquals(page, 'admin_relations_panel.html') self.assertIn('_project_', data) self.assertIn('parent_project', data) self.assertIn('child_projects', data) self.assertIn('home', data) self.assertEquals(len(data['child_projects']), 0) self.assertEquals(data['parent_project'].env_name, 'publicroject')