示例#1
0
    def __init__(self, parent, challenge_id):
        # FIXME: late import to avoid circular dependencies problem
        from eureka.ui.desktop.idea import SubmitIdeaBox
        event_management._register_listener(parent, self)
        self.challenge_id = challenge_id
        self.challenge_repository = ChallengeRepository()
        self.submit_idea_box = component.Component(SubmitIdeaBox(self))
        self._ideas = None

        if not self.challenge:
            raise ValueError('Invalid challenge id')
def init_portal_submit(self, url, *args):
    challenge_id = None

    if len(url) == 2:
        challenge_id = to_int(url[1])
        # make sure the challenge exists and is active; otherwise, redirect to the "normal" submission
        challenge = ChallengeRepository().get_by_id(challenge_id)
        now = datetime.now()
        if not challenge or not challenge.is_active(now):
            raise redirect_to('/submit', permanent=True, base_url=get_url_service().base_url)

    self.show_submit_idea(challenge_id)
示例#3
0
    def __init__(self, challenge=None, mobile_access=False):
        self.id = challenge if (is_integer(challenge)
                                or challenge is None) else challenge.id
        self.challenge_repository = ChallengeRepository()
        self.mobile_access = mobile_access
        challenge = self.challenge

        # properties
        self.title = editor.Property(u'').validate(validators.non_empty_string)
        self.short_title = editor.Property(u'').validate(
            validators.non_empty_string)
        self.created_by = editor.Property(u'').validate(
            lambda t: validators.user_email(t, True))
        self.organization = editor.Property(u'').validate(
            validators.non_empty_string)
        self.associated_dis = editor.Property(u'').validate(
            validators.user_email_list)
        self.starting_date = editor.Property(u'').validate(
            validators.non_empty_date)
        self.ending_date = editor.Property(u'').validate(
            validators.non_empty_date)
        self.summary = editor.Property(u'').validate(
            validators.non_empty_string)
        self.description = editor.Property(u'').validate(
            validators.non_empty_string)
        self.mobile_description = editor.Property(u'')
        self.outcome = editor.Property(u'').validate(validators.string)
        self.tags = editor.Property(u'').validate(
            lambda t: validators.word_list(t, duplicates='remove'))

        if challenge:
            self.title.set(challenge.title)
            self.short_title.set(challenge.short_title)
            self.created_by.set(challenge.created_by.email)
            self.organization.set(challenge.organization)
            associated_dis_email = ','.join(
                user.email for user in challenge.associated_dis)
            self.associated_dis.set(associated_dis_email)
            self.starting_date.set(
                challenge.starting_date.date().strftime('%d/%m/%Y'))
            self.ending_date.set(
                challenge.ending_date.date().strftime('%d/%m/%Y'))
            self.summary.set(challenge.summary)
            self.description.set(challenge.description)
            self.mobile_description.set(challenge.mobile_description)
            self.outcome.set(challenge.outcome)
            self.tags.set(u', '.join(challenge.tags))

        # Because the mobile description is optional in each eureka instance
        # and the validator will be triggered if we do this before
        self.mobile_description.validate(validators.non_empty_string)
示例#4
0
 def _active_challenge_id(self):
     challenges = list(ChallengeRepository().get_by_active_at_date())
     return challenges[0].id if challenges else None
示例#5
0
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
示例#6
0
 def get_challenges(self):
     return ChallengeRepository().get_all()
示例#7
0
 def __init__(self, mobile_access):
     self.challenge_repository = ChallengeRepository()
     self.content = component.Component(None)
     self.mobile_access = mobile_access