Beispiel #1
0
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 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
Beispiel #3
0
def sort_by_state(q, states_order):
    """Utility function to sort ideas by state, in the specified order"""
    sorted_states_id = [StateData.get_by(label=state) for state in states_order]
    sorted_states_id = [a.id for a in sorted_states_id if a]
    state_rank_mapping = [(state, rank) for rank, state in enumerate(sorted_states_id)]
    q = q.add_column(case(value=StateData.id, whens=state_rank_mapping).label('states_rank'))
    q = q.order_by('states_rank')
    return q
Beispiel #4
0
    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)
Beispiel #5
0
    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 sort_by_state(q, states_order):
    """Utility function to sort ideas by state, in the specified order"""
    sorted_states_id = [
        StateData.get_by(label=state) for state in states_order
    ]
    sorted_states_id = [a.id for a in sorted_states_id if a]
    state_rank_mapping = [(state, rank)
                          for rank, state in enumerate(sorted_states_id)]
    q = q.add_column(
        case(value=StateData.id,
             whens=state_rank_mapping).label('states_rank'))
    q = q.order_by('states_rank')
    return q
Beispiel #7
0
def _report_state_changed(from_user, idea, new_state):
    from eureka.domain.models import EventType, StateData
    new_state_data = StateData.get_by(label=new_state)

    # send the state change event
    event_users = set(user for user in (idea.tracked_by + idea.authors) if user.uid != from_user.uid)
    for user in event_users:
        user.add_event(EventType.StateChanged, idea)

    # send the state change email
    comment = _(new_state_data.step.label).lower()
    mail_users = set(user for user in idea.tracked_by if user.uid != from_user.uid)
    for user in mail_users:
        mail_notification.send('mail-event-state-changed.html', to=user, comment=comment, idea=idea,
                               delivery_priority=mail_notification.DeliveryPriority.Low)
    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