def test_actions(self): def _available_events(user): actions = (switching_actions(user, self.idea) + recommendation_actions(user, self.idea)) return [item[1] for item in actions] WFEvents = get_workflow().WFEvents # submit the idea self.process_event(self.author, WFEvents.SUBMIT_EVENT) self.assertEqual(self.facilitator, self.idea.wf_context.assignated_fi) # here is the scenario that we're going to run scenario = ( (self.facilitator, WFEvents.ASK_INFORMATIONS_EVENT), (self.author, WFEvents.SUBMIT_EVENT), (self.facilitator, WFEvents.SEND_DI_EVENT), (self.developer, WFEvents.REFUSE_EVENT), (self.developer, WFEvents.REOPEN_EVENT), (self.developer, WFEvents.APPROVAL_EVENT), (self.admin, WFEvents.DISTURBING_IDEA_EVENT), (self.admin, WFEvents.NOT_DISTURBING_IDEA_EVENT), (self.admin, WFEvents.SELECT_EVENT), (self.admin, WFEvents.SEND_PROJECT_EVENT), (self.admin, WFEvents.SEND_PROTOTYPE_EVENT), (self.admin, WFEvents.EXTEND_EVENT), ) for user, event in scenario: self.assertIn(event, _available_events(user)) self.process_event(user, event)
def get_idea_events(event_filter=None): # get a mixture of Comments & comments sorted by submission_date q1 = session.query(WFCommentData.submission_date.label('date'), UserData.uid.label('user_uid'), StateData.label.label('event'), IdeaData.id.label('idea_id')) q1 = q1.join(WFCommentData.to_state, WFCommentData.created_by, WFCommentData.idea_wf, IdeaWFContextData.idea) q2 = session.query(CommentData.submission_date.label('date'), UserData.uid.label('user_uid'), literal(u'COMMENT').label('event'), IdeaData.id.label('idea_id')) q2 = q2.join(CommentData.created_by, CommentData.idea, IdeaData.wf_context, IdeaWFContextData.state) # mask comments for ideas that are not in a published state q2 = q2.filter(StateData.label.in_(get_workflow().get_published_states())) q = q1.union(q2) # mask ideas that are currently in the dsig_basket_state q = q.filter(~IdeaData.id.in_(get_dsig_basket_state_ideas())) if event_filter: q = q.filter(column('event').in_(event_filter)) q = q.order_by(desc('date')) return q
def launched_ideas_step_filters(): workflow = get_workflow() return [ IdeaStateFilter('PROJECT_STEP', _(u'PROJECT_STEP'), workflow.get_project_states()), IdeaStateFilter('PROTOTYPE_STEP', _(u'PROTOTYPE_STEP'), workflow.get_prototype_states()), IdeaStateFilter('EXTENDED_STEP', _(u'EXTENDED_STEP'), workflow.get_extended_states()), ]
def create(self, title, description, impact, submitted_by, domain, challenge=None, tags=None, submission_date=None, **kw): # FIXME: this code should be the default constructor of the IdeaData idea = IdeaData(**kw) idea.title = title idea.description = description idea.impact = impact idea.submitted_by = submitted_by idea.domain = domain idea.challenge = challenge idea.tags = tags or [] idea.submission_date = submission_date or datetime.now() idea.authors = [submitted_by] # at least # initialize a workflow context # Â FIXME: this code should be the default constructor of the IdeaWFContextData initial_state = StateData.get_by( label=get_workflow().WFStates.INITIAL_STATE) idea.wf_context = IdeaWFContextData() idea.wf_context.state = initial_state # initialize an evaluation context # FIXME: should be initialized at the moment when the idea is submitted (i.e. enters in the workflow...) idea.eval_context = IdeaEvalContextData() idea.eval_context.title = title idea.eval_context.description = description idea.eval_context.impact = impact return idea
def state_filters(): """ Returns a list of IdeaStateFilter for each step """ workflow = get_workflow() return [ IdeaStateFilter('SUBMITTED_STEP', _(u'SUBMITTED_STEP'), workflow.get_submitted_states()), IdeaStateFilter('STUDY_STEP', _(u'STUDY_STEP'), workflow.get_study_states()), IdeaStateFilter('SUGGESTED_STEP', _(u'SUGGESTED_STEP'), workflow.get_approved_states()), IdeaStateFilter('SELECTED_STEP', _(u'SELECTED_STEP'), workflow.get_selected_states()), IdeaStateFilter('PROJECT_STEP', _(u'PROJECT_STEP'), workflow.get_project_states()), IdeaStateFilter('PROTOTYPE_STEP', _(u'PROTOTYPE_STEP'), workflow.get_prototype_states()), IdeaStateFilter('EXTENDED_STEP', _(u'EXTENDED_STEP'), workflow.get_extended_states()), IdeaStateFilter('refused', _(u"Non-retained"), workflow.get_refused_states()), IdeaStateFilter('progressing_ideas', _(u"Ideas in progress"), workflow.get_progressing_ideas_states()), ]
def populate_states(): workflow = get_workflow() WFSteps = workflow.WFSteps WFStates = workflow.WFStates states = ( (WFStates.INITIAL_STATE, WFSteps.NO_STEP), (WFStates.DRAFT_STATE, WFSteps.NO_STEP), (WFStates.FI_NORMALIZE_STATE, WFSteps.SUBMITTED_STEP), (WFStates.AUTHOR_NORMALIZE_STATE, WFSteps.SUBMITTED_STEP), (WFStates.DI_APPRAISAL_STATE, WFSteps.STUDY_STEP), (WFStates.RETURNED_BY_DI_STATE, WFSteps.STUDY_STEP), (WFStates.DI_APPROVED_STATE, WFSteps.SUGGESTED_STEP), (WFStates.SELECTED_STATE, WFSteps.SELECTED_STEP), (WFStates.PROJECT_STATE, WFSteps.PROJECT_STEP), (WFStates.PROTOTYPE_STATE, WFSteps.PROTOTYPE_STEP), (WFStates.EXTENDED_STATE, WFSteps.EXTENDED_STEP), (WFStates.FI_REFUSED_STATE, WFSteps.SUBMITTED_STEP), (WFStates.PROTOTYPE_REFUSED_STATE, WFSteps.PROTOTYPE_STEP), (WFStates.DI_REFUSED_STATE, WFSteps.STUDY_STEP), (WFStates.PROJECT_REFUSED_STATE, WFSteps.PROJECT_STEP), (WFStates.SELECT_REFUSED_STATE, WFSteps.SELECTED_STEP), (WFStates.APPROVAL_REFUSED_STATE, WFSteps.SUGGESTED_STEP), (WFStates.DSIG_BASKET_STATE, WFSteps.NO_STEP), ) for label, step in states: step = StepData.get_by(label=step) StateData(label=label, step=step) session.flush()
def test_actions(self): def _available_events(user): actions = ( switching_actions(user, self.idea) + recommendation_actions(user, self.idea) ) return [item[1] for item in actions] WFEvents = get_workflow().WFEvents # submit the idea self.process_event(self.author, WFEvents.SUBMIT_EVENT) self.assertEqual(self.facilitator, self.idea.wf_context.assignated_fi) # here is the scenario that we're going to run scenario = ( (self.facilitator, WFEvents.ASK_INFORMATIONS_EVENT), (self.author, WFEvents.SUBMIT_EVENT), (self.facilitator, WFEvents.SEND_DI_EVENT), (self.developer, WFEvents.REFUSE_EVENT), (self.developer, WFEvents.REOPEN_EVENT), (self.developer, WFEvents.APPROVAL_EVENT), (self.admin, WFEvents.DISTURBING_IDEA_EVENT), (self.admin, WFEvents.NOT_DISTURBING_IDEA_EVENT), (self.admin, WFEvents.SELECT_EVENT), (self.admin, WFEvents.SEND_PROJECT_EVENT), (self.admin, WFEvents.SEND_PROTOTYPE_EVENT), (self.admin, WFEvents.EXTEND_EVENT), ) for user, event in scenario: self.assertIn(event, _available_events(user)) self.process_event(user, event)
def find_state_changed_ideas(self, reverse=False): if not self.is_validated(): return [] # query workflow comments that have occured since the reference date wfcomments = WFCommentRepository().get_by_submission_after_date( self.reference_date) # (from_state, to_state) -> [(idea1, change_date1), (idea2, change_date2), ...] mapping = {} for wfcomment in wfcomments: # Omit transitions from DI_APPRAISAL_STATE to DI_APPRAISAL_STATE (changed developer for the idea) if wfcomment.from_state.label == wfcomment.to_state.label == get_workflow( ).WFStates.DI_APPRAISAL_STATE: continue k = (wfcomment.from_state, wfcomment.to_state) v = (wfcomment.idea_wf.idea, wfcomment.submission_date) mapping.setdefault(k, []).append(v) # FIXME: filter relevant states? return sorted(mapping.items(), key=lambda (state_change, ideas): (state_change[0].id, state_change[1].id), reverse=reverse)
def fi_states_labels(): workflow = get_workflow() return ( (workflow.WFStates.FI_NORMALIZE_STATE, _L(u'You have %d ideas to review')), (workflow.WFStates.AUTHOR_NORMALIZE_STATE, _L(u'You have sent back %d ideas to innovators')), (workflow.WFStates.DI_APPRAISAL_STATE, _L(u'You have sent %d ideas to developers')), (workflow.WFStates.FI_REFUSED_STATE, _L(u'You have refused %d ideas')), )
def get_all_published_ideas_unordered(states=[]): """ Returns an iterator on published ideas """ if states: return get_all_ideas_unordered().filter(StateData.label.in_(states)) else: return get_all_ideas_unordered().filter( StateData.label.in_(get_workflow().get_published_states()))
def get_di_ideas_count(uid): return (lambda uid=uid: session.query( StateData.label.label('state'), func.count(IdeaWFContextData.id).label('count')).outerjoin(StateData. state_for). filter(IdeaWFContextData.assignated_di == UserData.query. filter(UserData.uid == uid).first()).filter( StateData.label.in_(get_workflow().get_di_basket_states( ))).group_by(StateData.label))
def find_count_by_domain(self): return (session.query(DomainData.id, DomainData.i18n_label_column(), func.count(IdeaData.id)) .join(DomainData.ideas) .join(IdeaData.wf_context) .join(IdeaWFContextData.state) .filter(StateData.label.in_(get_workflow().get_published_states())) .group_by(DomainData.id) .having(func.count(IdeaData.id) > 0) .order_by(DomainData.rank, DomainData.i18n_label_column()))
def get_ideas_count_by_success_states_chart(self, width, legend_width, height): ideas_count_by_state = self.get_ideas_count_by_state().filter( StateData.label.in_(get_workflow().get_success_states())) pie_data = [] for idx, item in enumerate(ideas_count_by_state): pie_data.append( (item.count, _(item.state), self.DEFAULT_COLORS[idx])) return self._create_pie_chart(pie_data, width, height, legend_width)
def find_count_by_domain(self): return (session.query(DomainData.id, DomainData.label, func.count(IdeaData.id)) .join(DomainData.ideas) .join(IdeaData.wf_context) .join(IdeaWFContextData.state) .filter(StateData.label.in_(get_workflow().get_published_states())) .group_by(DomainData.id) .having(func.count(IdeaData.id) > 0) .order_by(DomainData.rank, DomainData.label))
def render_ideas_on_alert(self, h, comp, *args): challenges = [None] + list(ChallengeRepository().get_all()) domains = list(DomainRepository().get_all()) workflow = get_workflow() states = [s for s in workflow.get_progression_states() if s != workflow.WFStates.RETURNED_BY_DI_STATE] ideas_on_alert = self.get_ideas_on_alert() all_ideas = self.get_ideas_by_states(states) ideas_on_alert_grouped = self.group_by_challenge_and_domain(ideas_on_alert) all_ideas_grouped = self.group_by_challenge_and_domain(all_ideas) with h.table(class_='datatable'): # data with h.tbody: for challenge in challenges: available_domains = [ domain for domain in domains if (challenge, domain) in ideas_on_alert_grouped ] if available_domains: with h.tr: domain = available_domains[0] h << h.td(challenge.title if challenge else _(u'Off challenge'), rowspan=len(available_domains)) h << h.td(domain.i18n_label) render_ideas_on_alert_item(h, states, ideas_on_alert_grouped[(challenge, domain)], all_ideas_grouped[(challenge, domain)], comp.answer) for domain in available_domains[1:]: with h.tr: h << h.td(domain.i18n_label) render_ideas_on_alert_item(h, states, ideas_on_alert_grouped[(challenge, domain)], all_ideas_grouped[(challenge, domain)], comp.answer) # column headings with h.thead: with h.tr: h << h.th(colspan=2) h << h.th(_(u'State'), colspan=len(states)) with h.tr: h << h.th(_(u'Challenge')) h << h.th(_(u'Domain')) for state in states: h << h.th(_(state)) # totals with h.tfoot: with h.tr: h << h.td(_(u'Totals'), colspan=2) for state in states: total = len([idea for idea in ideas_on_alert if idea.wf_context.state.label == state]) total_all = len([idea for idea in all_ideas if idea.wf_context.state.label == state]) h << h.td('%s (%s)' % (total, total_all), style='white-space:nowrap') return h.root
def get_di_ideas_count(uid): return (lambda uid=uid: session.query( StateData.label.label('state'), func.count(IdeaWFContextData.id).label('count') ).outerjoin(StateData.state_for) .filter(IdeaWFContextData.assignated_di == UserData.query.filter( UserData.uid == uid).first()) .filter(StateData.label.in_(get_workflow().get_di_basket_states())) .group_by(StateData.label))
def get_all_published_ideas_unordered(states=[]): """ Returns an iterator on published ideas """ if states: return get_all_ideas_unordered().filter( StateData.label.in_(states)) else: return get_all_ideas_unordered().filter( StateData.label.in_(get_workflow().get_published_states()))
def __init__(self, parent): event_management._register_listener(parent, self) items = StateData.get_ideas_count_by_states(get_workflow().get_chart_states()) self.items = [(r.state, r.count) for r in reversed(items.all())] self.chart = component.Component( BarChart(self.items, _('Your ideas have potential'), clickable=True) ) self.chart.on_answer(self.call_ideas)
def get_ideas_count_in_fi_baskets(): fi_basket_states = get_workflow().get_fi_basket_states() query = session.query(UserData, StateData, func.count(IdeaWFContextData.id).label('count')) \ .join(IdeaWFContextData.assignated_fi) \ .join(IdeaWFContextData.state) \ .filter(StateData.label.in_(fi_basket_states)) \ .group_by(UserData.uid, StateData.id) return query
def __init__(self, idea, event): self.idea_id = idea if is_integer(idea) else idea.id self.event = event self.comment = editor.Property('') # for some workflow events, we must choose a new developer self.di = editor.Property('') refuse_event = get_workflow().WFEvents.REFUSE_EVENT if event in (refuse_event,): self.comment.validate(validators.non_empty_string) self.show_all = var.Var(False)
def __init__(self, idea, event): self.idea_id = idea if is_integer(idea) else idea.id self.event = event self.comment = editor.Property('') # for some workflow events, we must choose a new developer self.di = editor.Property('') refuse_event = get_workflow().WFEvents.REFUSE_EVENT if event in (refuse_event, ): self.comment.validate(validators.non_empty_string) self.show_all = var.Var(False)
def get_fi_process_ideas(uid): """ Returns an iterator on idea for facilitator current process """ return (lambda uid=uid: IdeaData.query.join(IdeaData.wf_context).outerjoin( IdeaWFContextData.state).filter( and_( StateData.label == get_workflow().WFStates.FI_NORMALIZE_STATE, IdeaWFContextData.assignated_fi == UserData.query.filter( UserData.uid == uid).first())).order_by( desc(IdeaData.submission_date)))
def get_ideas_count_by_fi(self): results = [] for user, iter in itertools.groupby( queries.get_ideas_count_in_fi_baskets(), operator.itemgetter(0)): ideas_counts = dict( (state.label, count) for _, state, count in iter) results.append( (user.uid, user.fullname, sum(ideas_counts.values()), ideas_counts.get(get_workflow().WFStates.FI_NORMALIZE_STATE, 0))) return results
def get_latecomer_fi(self, n_days=7): n_days_ago = datetime.now() - timedelta(days=n_days) query = session.query(IdeaWFContextData, func.max(WFCommentData.submission_date)) \ .join(WFCommentData.idea_wf) \ .join(IdeaWFContextData.state) \ .filter(StateData.label == get_workflow().WFStates.FI_NORMALIZE_STATE) \ .group_by(IdeaWFContextData.id) # there's at least one idea in FI_NORMALIZE_STATE that is older than n_days_ago return set(wfcontext.assignated_fi_uid for wfcontext, date in query if date < n_days_ago)
def query(limit=limit): q = session.query(TagData.label, func.count(IdeaData.id).label('ideas_count')) q = q.outerjoin(TagData.ideas) q = q.outerjoin(IdeaData.wf_context) q = q.outerjoin(IdeaWFContextData.state) q = q.filter(StateData.label.in_( get_workflow().get_published_states())) q = q.order_by(desc('ideas_count')) q = q.group_by(TagData.label) q = q.limit(limit) return q
def get_ideas_count_by_fi(self): results = [] for user, iter in itertools.groupby( queries.get_ideas_count_in_fi_baskets(), operator.itemgetter(0)): ideas_counts = dict( (state.label, count) for _, state, count in iter) results.append((user.uid, user.fullname, sum(ideas_counts.values()), ideas_counts.get(get_workflow().WFStates.FI_NORMALIZE_STATE, 0))) return results
def di_states_labels(): workflow = get_workflow() return ( (workflow.WFStates.DI_APPRAISAL_STATE, _L(u'You have %d ideas to review')), (workflow.WFStates.DSIG_BASKET_STATE, _L(u'You have sent %d ideas to DSIG')), (workflow.WFStates.DI_REFUSED_STATE, _L(u'You have refused %d ideas')), (workflow.WFStates.DI_APPROVED_STATE, _L(u'You have approved %d ideas')), (workflow.WFStates.SELECTED_STATE, _L(u'You have %d selected ideas')), (workflow.WFStates.PROJECT_STATE, _L(u'You have %d projected ideas')), (workflow.WFStates.PROTOTYPE_STATE, _L(u'You have %d prototyped ideas')), (workflow.WFStates.EXTENDED_STATE, _L(u'You have %d extended ideas')), )
def populate_steps(): wfsteps = get_workflow().WFSteps steps = ((wfsteps.NO_STEP, 100), (wfsteps.SUBMITTED_STEP, 1), (wfsteps.STUDY_STEP, 2), (wfsteps.SUGGESTED_STEP, 3), (wfsteps.SELECTED_STEP, 4), (wfsteps.PROJECT_STEP, 5), (wfsteps.PROTOTYPE_STEP, 6), (wfsteps.EXTENDED_STEP, 7)) for label, rank in steps: StepData(label=label, rank=rank) session.flush()
def has_permission_submit_comment(self, user, perm, subject): if not user: return True idea = subject.i state = idea.wf_context.state.label workflow = get_workflow() if state in workflow.get_refused_states(): return False return True
def get_fi_process_ideas(uid): """ Returns an iterator on idea for facilitator current process """ return (lambda uid=uid: IdeaData.query.join(IdeaData.wf_context) .outerjoin(IdeaWFContextData.state) .filter(and_( StateData.label == get_workflow().WFStates.FI_NORMALIZE_STATE, IdeaWFContextData.assignated_fi == UserData.query.filter( UserData.uid == uid).first())) .order_by(desc(IdeaData.submission_date)))
def has_permission_view_evaluation_menu(self, user, perm, subject): if not user: return False user = user.entity idea = subject.idea state = subject.state if user.is_developer(idea) and state in get_workflow().get_study_states(): return True return user.is_dsig()
def __init__(self, parent): event_management._register_listener(parent, self) items = StateData.get_ideas_count_by_states( get_workflow().get_chart_states()) self.items = [(r.state, r.count) for r in reversed(items.all())] self.chart = component.Component( BarChart(self.items, _('Your ideas have potential'), clickable=True)) self.chart.on_answer(self.call_ideas)
def get_ideas_count_by_refused_states_chart(self, width, legend_width, height): ideas_count_by_state = self.get_ideas_count_by_state().filter( StateData.label.in_(get_workflow().get_refused_states())) pie_data = [] for idx, item in enumerate(ideas_count_by_state): pie_data.append( (item.count, _(item.state), self.DEFAULT_COLORS[idx])) try: return self._create_pie_chart(pie_data, width, height, legend_width) except ZeroDivisionError as e: import ipdb; ipdb.set_trace() raise
def get_ideas_count_by_di(): WFStates = get_workflow().WFStates sub_query = (IdeaWFContextData.query.outerjoin( IdeaWFContextData.state).filter( StateData.label == WFStates.DI_APPRAISAL_STATE).subquery()) return session.query( UserData, func.count(sub_query.c.id) ).filter(UserData.enabled == True) \ .outerjoin((sub_query, sub_query.c.assignated_di_uid == UserData.uid)) \ .join(RoleData) \ .filter(RoleData.type == RoleType.Developer).group_by(UserData.uid)
def query(limit=limit): q = session.query( TagData.label, func.count(IdeaData.id).label('ideas_count')) q = q.outerjoin(TagData.ideas) q = q.outerjoin(IdeaData.wf_context) q = q.outerjoin(IdeaWFContextData.state) q = q.filter( StateData.label.in_(get_workflow().get_published_states())) q = q.order_by(desc('ideas_count')) q = q.group_by(TagData.label) q = q.limit(limit) return q
def get_ideas_count_by_di(): WFStates = get_workflow().WFStates sub_query = (IdeaWFContextData.query.outerjoin(IdeaWFContextData.state) .filter(StateData.label == WFStates.DI_APPRAISAL_STATE) .subquery()) return session.query( UserData, func.count(sub_query.c.id) ).filter(UserData.enabled == True) \ .outerjoin((sub_query, sub_query.c.assignated_di_uid == UserData.uid)) \ .join(RoleData) \ .filter(RoleData.type == RoleType.Developer).group_by(UserData.uid)
def has_permission_delete_idea(self, user, perm, subject): if not user: return False user = user.entity idea = subject.i state = idea.wf_context.state.label workflow = get_workflow() if state in workflow.get_draft_states(): return True return user.is_dsig()
def get_ideas_count_by_refused_states_chart(self, width, legend_width, height): ideas_count_by_state = self.get_ideas_count_by_state().filter( StateData.label.in_(get_workflow().get_refused_states())) pie_data = [] for idx, item in enumerate(ideas_count_by_state): pie_data.append( (item.count, _(item.state), self.DEFAULT_COLORS[idx])) try: return self._create_pie_chart(pie_data, width, height, legend_width) except ZeroDivisionError as e: import ipdb ipdb.set_trace() raise
def get_idea_published_tag(idea_id): tag_ids = [elt[0] for elt in session.query(TagData.id).outerjoin(TagData.ideas).filter( IdeaData.id == idea_id)] result = (session.query( TagData.label, func.sum(StateData.label.in_(get_workflow().get_published_states())).label( 'ideas_count') ).outerjoin(TagData.ideas)) result = (result.outerjoin(IdeaData.wf_context) .outerjoin(IdeaWFContextData.state) .filter(TagData.id.in_(tag_ids)) .group_by(TagData.label)) return result
def get_idea_published_tag(idea_id): tag_ids = [ elt[0] for elt in session.query(TagData.id).outerjoin(TagData.ideas).filter( IdeaData.id == idea_id) ] result = (session.query( TagData.label, func.sum(StateData.label.in_( get_workflow().get_published_states())).label( 'ideas_count')).outerjoin(TagData.ideas)) result = (result.outerjoin( IdeaData.wf_context).outerjoin(IdeaWFContextData.state).filter( TagData.id.in_(tag_ids)).group_by(TagData.label)) return result
def populate_steps(): wfsteps = get_workflow().WFSteps steps = ( (wfsteps.NO_STEP, 100), (wfsteps.SUBMITTED_STEP, 1), (wfsteps.STUDY_STEP, 2), (wfsteps.SUGGESTED_STEP, 3), (wfsteps.SELECTED_STEP, 4), (wfsteps.PROJECT_STEP, 5), (wfsteps.PROTOTYPE_STEP, 6), (wfsteps.EXTENDED_STEP, 7) ) for label, rank in steps: StepData(label=label, rank=rank) session.flush()
def get_ideas_count_by_domain_state(self): workflow = get_workflow() q = session.query(DomainData.id, DomainData.i18n_label_column(), func.count(IdeaData.id), StateData.label) q = q.outerjoin(DomainData.ideas).outerjoin(IdeaData.wf_context) q = q.outerjoin(IdeaWFContextData.state) q = q.filter( StateData.label.in_(workflow.get_approved_states() + workflow.get_refused_states())) q = q.group_by(DomainData.id, StateData.label) res = collections.defaultdict(lambda: [0, 0]) for domain_id, domain_label, count, state in q: if state == workflow.WFStates.DI_APPROVED_STATE: res[domain_label][0] = int(count) else: res[domain_label][1] = int(count) return res
def has_permission_track_idea(self, user, perm, subject): if not user: return True user = user.entity idea = subject.i state = idea.wf_context.state.label workflow = get_workflow() if user in idea.authors: return False if state in workflow.get_refused_states(): return False if state in workflow.get_published_states(): return True return False
def has_permission_edit_idea(self, user, perm, subject): if not user: return False user = user.entity idea = subject.i state = idea.wf_context.state.label workflow = get_workflow() if user in idea.authors and state in workflow.get_author_edit_states(): return True if user.is_facilitator(idea) and state in workflow.get_submitted_states(): return True if idea.proxy_submitter and user.uid == idea.proxy_submitter.uid: return True return user.is_dsig()
def get_ideas_count_day_by_day(self, from_date): # count ideas day by day (not draft) since the from_date date = IdeaData.submission_date.label('date') db_type = urlparse(database._engines.keys()[0]).scheme if db_type == 'sqlite': formatted_date = func.strftime( '%d/%m/%Y', IdeaData.submission_date).label('formatted_date') else: formatted_date = func.date_format( IdeaData.submission_date, '%d/%m/%y').label('formatted_date') q = (session.query( formatted_date, date, func.count(IdeaData.id).label('count')).outerjoin( IdeaData.wf_context).outerjoin(IdeaWFContextData.state).filter( StateData.label.in_( get_workflow().get_workflow_states())).filter( IdeaData.submission_date >= from_date).group_by( formatted_date).order_by(formatted_date)) return q
def get_ideas_count_day_by_day(self, from_date): # count ideas day by day (not draft) since the from_date date = IdeaData.submission_date.label('date') db_type = urlparse(database._engines.keys()[0]).scheme if db_type == 'sqlite': formatted_date = func.strftime( '%d/%m/%Y', IdeaData.submission_date).label('formatted_date') else: formatted_date = func.date_format( IdeaData.submission_date, '%d/%m/%y').label('formatted_date') q = (session.query(formatted_date, date, func.count(IdeaData.id).label('count')) .outerjoin(IdeaData.wf_context) .outerjoin(IdeaWFContextData.state) .filter(StateData.label.in_(get_workflow().get_workflow_states())) .filter(IdeaData.submission_date >= from_date) .group_by(formatted_date) .order_by(formatted_date)) return q