Пример #1
0
    def _save_locale(self, response):
        language = i18n.get_locale().language
        response.set_cookie('language', language, max_age=timedelta(days=365))

        current_user = get_current_user()
        if current_user:
            current_user.locale = language
Пример #2
0
    def _save_locale(self, response):
        language = i18n.get_locale().language
        response.set_cookie("language", language, max_age=timedelta(days=365))

        current_user = get_current_user()
        if current_user:
            current_user.locale = language
Пример #3
0
    def send_email_direction(self, direction_label, message):
        user = get_current_user()

        if user:
            mailer = mail.get_mailer()

            base_url = get_url_service().base_url

            substitutions = {
                u'SENDER': user.email,
                u'FIRSTNAME': user.firstname,
                u'LASTNAME': user.lastname,
                u'IDEA_LINK': self.idea.absolute_url,
                u'IDEA_ID': str(self.idea.id),
                u'DIRECTION_LABEL': direction_label,
                u'MESSAGE': message,
                u'EUREKA_LINK': render_link(_(u'Eurêka'), base_url),
                u'RECIPIENTS': mailer.get_substitutions()[u'DSIG_EMAIL']
            }

            content = _perform_substitutions(
                'mail-idea-duplicated-direction.html',
                'fr', substitutions)
            (content, subject, sender, to_recipients,
             cc_recipients, bcc_recipients) = _extract_metadata(content)

            mailer.send_mail(subject, from_=sender, to=to_recipients,
                             cc=cc_recipients, bcc=bcc_recipients,
                             content=content, type='html')
Пример #4
0
    def send_email_direction(self, direction_label, message):
        user = get_current_user()

        if user:
            mailer = mail.get_mailer()

            base_url = get_url_service().base_url

            substitutions = {
                u'SENDER': user.email,
                u'FIRSTNAME': user.firstname,
                u'LASTNAME': user.lastname,
                u'IDEA_LINK': self.idea.absolute_url,
                u'IDEA_ID': str(self.idea.id),
                u'DIRECTION_LABEL': direction_label,
                u'MESSAGE': message,
                u'EUREKA_LINK': render_link(_(u'Eurêka'), base_url),
                u'RECIPIENTS': mailer.get_substitutions()[u'DSIG_EMAIL']
            }

            content = _perform_substitutions(
                'mail-idea-duplicated-direction.html', 'fr', substitutions)
            (content, subject, sender, to_recipients, cc_recipients,
             bcc_recipients) = _extract_metadata(content)

            mailer.send_mail(subject,
                             from_=sender,
                             to=to_recipients,
                             cc=cc_recipients,
                             bcc=bcc_recipients,
                             content=content,
                             type='html')
Пример #5
0
 def export_xls(self, filename_prefix='export'):
     idea_ids = [i.id for i in self.get_query()]
     if idea_ids:
         current_user = get_current_user()
         first_idea = IdeaData.query.filter_by(id=idea_ids[0]).one()
         permission = _permission(current_user, first_idea)
     else:
         permission = None
     content, filename = export(idea_ids, permission, filename_prefix)
     raise excel_response(content, filename)
Пример #6
0
 def export_xls(self, filename_prefix='export'):
     idea_ids = [i.id for i in self.get_query()]
     if idea_ids:
         current_user = get_current_user()
         first_idea = IdeaData.query.filter_by(id=idea_ids[0]).one()
         permission = _permission(current_user, first_idea)
     else:
         permission = None
     content, filename = export(idea_ids, permission, filename_prefix)
     raise excel_response(content, filename)
Пример #7
0
    def get_ideas(self):
        idea_repository = IdeaRepository()

        current_user = get_current_user()
        if not current_user:
            query = idea_repository.get_by_home_settings()
        else:
            query = idea_repository.get_by_home_settings(current_user.home_settings)

        query = query.order_by(None)  # remove the default ordering
        return idea_repository.sort_by_last_wf_comment_date(query)
Пример #8
0
    def _install_locale(self, request):
        current_user = get_current_user()
        language = current_user.locale if current_user else request.cookies.get("language")
        if language:
            locale = i18n.Locale(language, domain=self.domain)
        else:
            locales = [(lang,) for lang, __ in available_locales]
            default_locale = (available_locales[0][0], None)
            locale = i18n.NegotiatedLocale(request, locales, default_locale, domain=self.domain)

        self.set_locale(locale)
Пример #9
0
    def get_ideas(self):
        idea_repository = IdeaRepository()

        current_user = get_current_user()
        if not current_user:
            query = idea_repository.get_by_home_settings()
        else:
            query = idea_repository.get_by_home_settings(
                current_user.home_settings)

        query = query.order_by(None)  # remove the default ordering
        return idea_repository.sort_by_last_wf_comment_date(query)
Пример #10
0
    def vote(self, rate, user=None):
        user = user or get_current_user()

        if not security.has_permissions('vote_idea', self):
            flashmessage.set_flash(
                _("Sorry but you can't vote for this idea anymore"))
            return

        vote = self.find_vote(user)
        if not vote:
            self.i.vote(user, rate)
        elif user.is_dsig():  # a DSIG can cheat by voting more than once
            self.i.vote(user, rate + vote.rate)  # accumulate the rates
Пример #11
0
    def vote(self, rate, user=None):
        user = user or get_current_user()

        if not security.has_permissions('vote_idea', self):
            flashmessage.set_flash(
                _("Sorry but you can't vote for this idea anymore"))
            return

        vote = self.find_vote(user)
        if not vote:
            self.i.vote(user, rate)
        elif user.is_dsig():  # a DSIG can cheat by voting more than once
            self.i.vote(user, rate + vote.rate)  # accumulate the rates
Пример #12
0
    def with_login(self, action, *args, **kwargs):
        if get_current_user():
            action(*args, **kwargs)
            return

        def on_answer(answer):
            self.initial_setup()
            if isinstance(answer, LoginEvent):
                action(*args, **kwargs)
            elif isinstance(answer, ResetPasswordEvent):
                self.show_reset_password()

        self._show_modal(Login(), model='prompt',
                         title=_('You must log in to perform this action'),
                         on_answer=on_answer)
Пример #13
0
    def _install_locale(self, request):
        current_user = get_current_user()
        language = current_user.locale if current_user\
            else request.cookies.get('language')
        if language:
            locale = i18n.Locale(language, domain=self.domain)
        else:
            locales = [(lang, ) for lang, __ in available_locales]
            default_locale = (available_locales[0][0], None)
            locale = i18n.NegotiatedLocale(request,
                                           locales,
                                           default_locale,
                                           domain=self.domain)

        self.set_locale(locale)
Пример #14
0
    def create_comment(self):
        if not self.is_valid():
            return None

        # create the comment
        idea = self.idea
        content = self.content.value
        user = get_current_user()
        attachment = self.create_attachment(self.attachment.value)
        comment = idea.add_comment(user, content, attachment)

        # clear fields
        self.reset()

        flashmessage.set_flash(_(u'Comment added'))
        return comment
Пример #15
0
    def with_login(self, action, *args, **kwargs):
        if get_current_user():
            action(*args, **kwargs)
            return

        def on_answer(answer):
            self.initial_setup()
            if isinstance(answer, LoginEvent):
                action(*args, **kwargs)
            elif isinstance(answer, ResetPasswordEvent):
                self.show_reset_password()

        self._show_modal(Login(),
                         model='prompt',
                         title=_('You must log in to perform this action'),
                         on_answer=on_answer)
Пример #16
0
    def create_comment(self):
        if not self.is_valid():
            return None

        # create the comment
        idea = self.idea
        content = self.content.value
        user = get_current_user()
        attachment = self.create_attachment(self.attachment.value)
        comment = idea.add_comment(user, content, attachment)

        # clear fields
        self.reset()

        flashmessage.set_flash(_(u'Comment added'))
        return comment
Пример #17
0
    def goto(self, idea_id, mode=u"view"):
        assert is_integer(idea_id)

        self.idea_i = None
        self.content.becomes(None)

        idea = IdeaRepository().get_by_id(idea_id)
        if not idea:
            raise HTTPNotFound()

        i = self._create_idea(idea)

        # Show the editor when the current user is the creator and the
        # idea state is DRAFT or AUTHOR_NORMALIZATION
        workflow = get_workflow()
        edit_state = i.i.wf_context.state.label in (
            workflow.WFStates.INITIAL_STATE, workflow.WFStates.DRAFT_STATE,
            workflow.WFStates.AUTHOR_NORMALIZE_STATE,
            workflow.WFStates.RETURNED_BY_DI_STATE)

        # FIXME: is this a good idea to force the mode like this?!
        current_user = get_current_user()
        if current_user and (current_user in i.i.authors) and edit_state:
            mode = u"edit"

        if mode == u"edit":
            self.content.becomes(IdeaUpdater(i), model='form')
        else:
            self.content.becomes(i, model='detail')

        if current_user:
            # FIXME: WTF! Remove this!
            # Note: we do not use the association proxy and even no
            #       entity to avoid the index crawling extension to be
            #       notified of a change: we do not want to update the
            #       document each time it is viewed!
            ReadIdeaData(user_uid=current_user.uid,
                         idea_id=i.id,
                         timestamp=datetime.now())
            idea.readers_updated()

        event_management._emit_signal(self, "VIEW_IDEA", mode=mode)
Пример #18
0
    def goto(self, idea_id, mode=u"view"):
        assert is_integer(idea_id)

        self.idea_i = None
        self.content.becomes(None)

        idea = IdeaRepository().get_by_id(idea_id)
        if not idea:
            raise HTTPNotFound()

        i = self._create_idea(idea)

        # Show the editor when the current user is the creator and the
        # idea state is DRAFT or AUTHOR_NORMALIZATION
        workflow = get_workflow()
        edit_state = i.i.wf_context.state.label in (workflow.WFStates.INITIAL_STATE,
                                                    workflow.WFStates.DRAFT_STATE,
                                                    workflow.WFStates.AUTHOR_NORMALIZE_STATE,
                                                    workflow.WFStates.RETURNED_BY_DI_STATE)

        # FIXME: is this a good idea to force the mode like this?!
        current_user = get_current_user()
        if current_user and (current_user in i.i.authors) and edit_state:
            mode = u"edit"

        if mode == u"edit":
            self.content.becomes(IdeaUpdater(i), model='form')
        else:
            self.content.becomes(i, model='detail')

        if current_user:
            # FIXME: WTF! Remove this!
            # Note: we do not use the association proxy and even no
            #       entity to avoid the index crawling extension to be
            #       notified of a change: we do not want to update the
            #       document each time it is viewed!
            ReadIdeaData(user_uid=current_user.uid, idea_id=i.id, timestamp=datetime.now())
            idea.readers_updated()

        event_management._emit_signal(self, "VIEW_IDEA", mode=mode)
Пример #19
0
 def remove_vote(self):
     vote = self.comment.find_vote_from_user(get_current_user())
     self.comment.votes.remove(vote)
Пример #20
0
 def find_vote(self, user=None):
     user = user or get_current_user()
     assert user
     return self.i.find_vote(user)
Пример #21
0
 def moderate(self):
     self.comment.moderated = True
     # FIXME: the moderation mail should be sent from a CommentData method, not from here
     self.send_moderation_mail(get_current_user())
Пример #22
0
    def initial_setup(self):

        poll = get_all_enabled_polls().first()
        if poll:
            self.poll = component.Component(Poll(poll.id))
        else:
            self.poll = component.Component(None)

        self.locale_box.becomes(LocaleChoice())

        self.idea_submit.becomes(SubmitIdeaBox(self))
        self.search.becomes(SearchBlock(self))

        self.idea_chart.becomes(IdeaBarChart(self))

        self.welcome.becomes(Welcome(self))
        self.online_shop.becomes(OnlineShop(self))
        self.faq.becomes(FAQ(self))
        self.terms_of_use.becomes(TermsOfUse(self))

        self.login_box.becomes(Login())

        # Note: setup done here because we need to access the current user and check the
        #       permissions in order to setup the component but they are not available when
        #       the Portal component is created.

        # password change modal dialog
        current_user = get_current_user()
        if current_user and current_user.should_change_password():
            self.show_password_editor(current_user)

        current_user = get_current_user()
        if current_user:
            self.login_box.becomes(User(self, current_user),
                                   model='login_status')

        self.menu_items = [
            (_(u'home'), _(u"Go to the home page"), 'home', self.show_home),
            (_(u'news'), None, 'news', self.show_articles_by_type),
            (_(u'challenge'), _(u"View, comment and vote for challenge ideas"),
             'challenges', self.show_challenge_ideas),
            (_(u'ideas'), _(u"View, comment and vote for ideas"), 'ideas',
             self.show_ideas),
        ]

        self.menu_items.extend([
            (_(u"discover eurêka"), None, 'welcome', self.show_welcome),
            (_(u'gifts'), None, 'shop', self.show_shop),
            (_(u'help'), None, 'help', self.show_help),
            (_(u'contact us'), None, 'contact_us', self.show_contact)
        ])

        self.menu.becomes(Menu(self.menu_items), model='list')

        self.footer_menu_items = [
            (_(u'Help'), None, 'help', self.show_help),
            (_(u'Suggestions'), None, 'improvements', self.show_suggestions),
            (_(u'Terms of use'), None, 'terms_of_use', self.show_terms_of_use),
        ]
        self.footer_menu.becomes(Menu(self.footer_menu_items), model='links')

        # initial the content if necessary (that is, when no presentation.init_for rule was
        # called)
        if not self.content():
            self.select_tab(0)
Пример #23
0
 def untrack_idea(self):
     user = get_current_user()
     assert user
     user.untrack_idea(self.id)
     flashmessage.set_flash(_(u'Idea removed from tracking'))
Пример #24
0
 def untrack_idea(self):
     user = get_current_user()
     assert user
     user.untrack_idea(self.id)
     flashmessage.set_flash(_(u'Idea removed from tracking'))
Пример #25
0
 def add_vote(self):
     self.comment.add_vote_for_user(get_current_user())
Пример #26
0
 def process_event(idea, event):
     wf_process_event(from_user=get_current_user(),
                      idea=idea,
                      event=event,
                      notify=flashmessage.set_flash)
Пример #27
0
 def moderate(self):
     self.comment.moderated = True
     # FIXME: the moderation mail should be sent from a CommentData method, not from here
     self.send_moderation_mail(get_current_user())
Пример #28
0
 def add_vote(self):
     self.comment.add_vote_for_user(get_current_user())
Пример #29
0
    def edit_idea(self, draft):
        # read the fields
        submission_date = self.idea.i.submission_date if self.idea else datetime.now()
        title = self.title.value
        description = self.description.value
        impact = self.impact.value
        domain = DomainRepository().get_by_id(self.domain_id.value)

        challenge_id = self.challenge_id.value
        challenge = ChallengeRepository().get_by_id(
            challenge_id) if challenge_id else None
        # make sure the challenge was active at the submission_date
        if challenge and not challenge.is_active(submission_date):
            challenge = None

        tags = [self.get_or_create_tag(tag.lower()) for tag in self.tags.value]

        # create or update the idea
        # mandatory fields
        mandatory_fields = dict(
            title=title,
            description=description,
            impact=impact,
            domain=domain,
            challenge=challenge,
            tags=tags,
        )

        if not self.idea:
            idea = IdeaRepository().create(submitted_by=get_current_user(),
                                           submission_date=submission_date,
                                           **mandatory_fields)
        else:
            idea = IdeaRepository().get_by_id(self.idea.id)
            idea.set(**mandatory_fields)

        # Optional fields
        idea.benefit_department = self.benefit_department.value
        idea.origin = self.origin.value
        idea.implementation = self.implementation.value

        self.update_idea_authors(idea)

        for attr in ('attachment_1', 'attachment_2', 'attachment_3'):
            property_value = getattr(self, attr).value
            if property_value is not None:
                idea_attachment = getattr(idea, attr)
                if idea_attachment:
                    setattr(idea, attr, None)
                    # idea_attachment.delete()
                setattr(idea, attr, self.create_attachement(property_value))

        idea.show_creator = not self.anonymous.value
        idea.already_done = self.already_done.value

        # workflow
        workflow = get_workflow()
        draft_event = workflow.WFEvents.DRAFT_EVENT
        submit_event = workflow.WFEvents.SUBMIT_EVENT

        def process_event(idea, event):
            wf_process_event(from_user=get_current_user(),
                             idea=idea,
                             event=event,
                             notify=flashmessage.set_flash)

        if draft:  # save as a draft
            process_event(idea, draft_event)
        else:  # submit the idea
            process_event(idea, submit_event)

        return idea
Пример #30
0
 def remove_vote(self):
     vote = self.comment.find_vote_from_user(get_current_user())
     self.comment.votes.remove(vote)
Пример #31
0
    def _uid(self, user=None):
        if user is None:
            user = get_current_user()
            assert user

        return user if is_string(user) else user.uid
Пример #32
0
 def has_vote(self):
     current_user = get_current_user()
     if current_user:
         return self.comment.find_vote_from_user(current_user) is not None
     else:
         return False
Пример #33
0
 def is_tracked(self):
     user = get_current_user()
     assert user
     return self.i in user.tracked_ideas
Пример #34
0
    def initial_setup(self):

        poll = get_all_enabled_polls().first()
        if poll:
            self.poll = component.Component(Poll(poll.id))
        else:
            self.poll = component.Component(None)

        self.locale_box.becomes(LocaleChoice())

        self.idea_submit.becomes(SubmitIdeaBox(self))
        self.search.becomes(SearchBlock(self))

        self.idea_chart.becomes(IdeaBarChart(self))

        self.welcome.becomes(Welcome(self))
        self.online_shop.becomes(OnlineShop(self))
        self.faq.becomes(FAQ(self))
        self.terms_of_use.becomes(TermsOfUse(self))

        self.login_box.becomes(Login())

        # Note: setup done here because we need to access the current user and check the
        #       permissions in order to setup the component but they are not available when
        #       the Portal component is created.

        # password change modal dialog
        current_user = get_current_user()
        if current_user and current_user.should_change_password():
            self.show_password_editor(current_user)

        current_user = get_current_user()
        if current_user:
            self.login_box.becomes(User(self, current_user),
                                   model='login_status')

        self.menu_items = [
            (_(u'home'), _(u"Go to the home page"), 'home', self.show_home),
            (_(u'news'), None, 'news', self.show_articles_by_type),
            (_(u'challenge'), _(u"View, comment and vote for challenge ideas"),
             'challenges', self.show_challenge_ideas),
            (_(u'ideas'), _(u"View, comment and vote for ideas"), 'ideas',
             self.show_ideas),
        ]

        self.menu_items.extend([
            (_(u"discover eurêka"), None, 'welcome', self.show_welcome),
            (_(u'gifts'), None, 'shop', self.show_shop),
            (_(u'help'), None, 'help', self.show_help),
            (_(u'contact us'), None, 'contact_us', self.show_contact)
        ])

        self.menu.becomes(Menu(self.menu_items), model='list')

        self.footer_menu_items = [(_(u'Help'), None, 'help', self.show_help),
                                  (_(u'Suggestions'), None, 'improvements',
                                   self.show_suggestions),
                                  (_(u'Terms of use'), None, 'terms_of_use',
                                   self.show_terms_of_use), ]
        self.footer_menu.becomes(Menu(self.footer_menu_items), model='links')

        # initial the content if necessary (that is, when no presentation.init_for rule was
        # called)
        if not self.content():
            self.select_tab(0)
Пример #35
0
    def track_idea(self):
        user = get_current_user()
        assert user

        user.track_idea(self.id)
        flashmessage.set_flash(_(u'Idea added to tracking'))
Пример #36
0
 def is_tracked(self):
     user = get_current_user()
     assert user
     return self.i in user.tracked_ideas
Пример #37
0
 def find_vote(self, user=None):
     user = user or get_current_user()
     assert user
     return self.i.find_vote(user)
Пример #38
0
    def track_idea(self):
        user = get_current_user()
        assert user

        user.track_idea(self.id)
        flashmessage.set_flash(_(u'Idea added to tracking'))
Пример #39
0
 def has_vote(self):
     current_user = get_current_user()
     if current_user:
         return self.comment.find_vote_from_user(current_user) is not None
     else:
         return False
Пример #40
0
    def _uid(self, user=None):
        if user is None:
            user = get_current_user()
            assert user

        return user if is_string(user) else user.uid