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
Exemple #2
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
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
Exemple #4
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