Пример #1
0
    def forum_reply(self, group_id, category_id, thread_id):
        try:
            group_id = int(group_id)
            group = Group.get(group_id)
        except ValueError:
            group = Group.get(group_id)
        try:
            thread_id = int(thread_id)
            category_id = int(category_id)
        except ValueError:
            abort(404)
        category = ForumCategory.get(category_id)
        thread = ForumPost.get(thread_id)

        if group is None or category is None or thread is None:
            abort(404)

        post = make_forum_post(c.user, thread.title, self.form_result['message'],
                               group_id=group.group_id, category_id=category_id,
                               thread_id=thread_id, controller='forum')

        thread.mark_as_seen_by(c.user)
        meta.Session.commit()
        if request.params.has_key('js'):
            return render_mako_def('/sections/wall_entries.mako',
                                   'thread_reply',
                                   id=post.id,
                                   author_id=post.created.id,
                                   message=post.message,
                                   created_on=post.created_on,
                                   allow_comment_deletion=True)
        else:
            self._redirect()
Пример #2
0
def _send_emails(user, post, group_id=None, category_id=None, controller=""):
    if group_id:
        forum_title = Group.get(group_id).title
    else:
        forum_title = _("Community") if category_id == 1 else _("Bugs")

    thread = ForumPost.get(post.thread_id)
    new_thread = thread.is_thread()
    extra_vars = dict(
        message=post.message,
        person_title=user.fullname,
        forum_title=forum_title,
        thread_url=url(
            controller=controller,
            action="thread",
            id=group_id,
            category_id=category_id,
            thread_id=post.thread_id,
            qualified=True,
        ),
    )
    email_message = render("/emails/forum_message.mako", extra_vars=extra_vars)

    recipients = set()
    for subscription in thread.subscriptions:
        if subscription.active and subscription.user.id != user.id:
            for email in subscription.user.emails:
                if email.confirmed:
                    recipients.add(email.email)
                    break
        else:
            # Explicit unsubscription.
            for email in subscription.user.emails:
                try:
                    recipients.remove(email.email)
                except KeyError:
                    pass

    ml_id = group_id
    if not ml_id:
        ml_id = {1: _("ututi-community"), 2: _("ututi-bugs")}[int(category_id)]
    if recipients:
        re = "Re: " if not new_thread else ""
        send_email(
            config["ututi_email_from"],
            config["ututi_email_from"],
            "[%s] %s%s" % (ml_id, re, post.title),
            email_message,
            message_id=_generateMessageId(),
            send_to=list(recipients),
        )
Пример #3
0
    def set_up_context(self, id=None, category_id=None, thread_id=None):
        if id is not None:
            c.group = Group.get(id)
            if c.group is None:
                abort(404)
            c.group_id = c.group.group_id
            c.group_menu_items = group_menu_items()
            c.object_location = c.group.location
            c.security_context = c.group
            c.theme = c.group.location.get_theme()
            c.breadcrumbs.append({'title': c.group.title, 'link': c.group.url()})
        else:
            c.group = None
            c.group_id = None

        if category_id is not None:
            try:
                category_id = int(category_id)
            except ValueError:
                abort(404)
            c.category = ForumCategory.get(category_id)
            if c.category is None:
                abort(404)
            c.breadcrumbs.append({'title': c.category.title,
                                  'link': url(controller=c.controller,
                              action='index', id=id, category_id=category_id)})
        else:
            c.category = None

        if thread_id is not None:
            try:
                thread_id = int(thread_id)
            except ValueError:
                abort(404)
            c.thread = ForumPost.get(thread_id)
            if c.thread is None:
                abort(404)
            assert c.thread.category_id == int(c.category.id), repr(c.thread.category_id)
        else:
            c.thread = None