mozillapulse/messages/sumo.py
author Josh Matthews <josh@joshmatthews.net>
Tue, 02 Jul 2013 14:40:17 -0400
changeset 42 70837f169e9a8e2f58d7bd37160d910b1983d453
parent 41 68c2ee67e39ea1fbf8cbd7919f774e48ef9dc035
permissions -rw-r--r--
Add more SUMO messages.

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

from base import *
from mozillapulse.utils import email_to_routing_key

# ------------------------------------------------------------------------------
# Generic base class for messages that have to do with bugs
# ------------------------------------------------------------------------------

class GenericSupportMessage(GenericMessage):

    def __init__(self, locale, who, when):
        super(GenericSupportMessage, self).__init__()
        self.routing_parts.append('support')
        self.set_data('locale', locale)
        self.set_data('who', who)
        self.set_data('when', when)

    def _required_data_fields(self):
        tmp = super(GenericSupportMessage, self)._required_data_fields()
        tmp.append('who')
        tmp.append('when')
        tmp.append('locale')
        return tmp

# ------------------------------------------------------------------------------
# High-level messages (for end-user convenience)
# ------------------------------------------------------------------------------

class SUMOAnswerMessage(GenericSupportMessage):

    def __init__(self, locale, who, when, question, id, is_new, product, category):
        super(SUMOAnswerMessage, self).__init__(locale, who, when)
        self.routing_parts.append('answer')
        self.set_data('question', question)
        self.set_data('id', id)
        self.set_data('new', is_new)
        self.set_data('product', product)
        self.set_data('category', category)

    def _required_data_fields(self):
        tmp = super(SUMOAnswerMessage, self)._required_data_fields()
        tmp.append('question')
        tmp.append('id')
        tmp.append('new')
        tmp.append('product')
        tmp.append('category')
        return tmp


class SUMOQuestionMessage(GenericSupportMessage):

    def __init__(self, locale, who, when, id, product, category):
        super(SUMOQuestionMessage, self).__init__(locale, who, when)
        self.routing_parts.append('question')
        self.set_data('id', id)
        self.set_data('product', product)
        self.set_data('category', category)

    def _required_data_fields(self):
        tmp = super(SUMOQuestionMessage, self)._required_data_fields()
        tmp.append('id')
        tmp.append('product')
        tmp.append('category')
        return tmp


class SUMOForumPostMessage(GenericSupportMessage):

    def __init__(self, locale, who, when, slug, thead, id, is_new):
        super(SUMOForumPostMessage, self).__init__(locale, who, when)
        self.routing_parts.append('forum')
        self.set_data('thread', thread)
        self.set_data('id', id)
        self.set_data('new', is_new)
        self.set_data('slug', slug)

    def _required_data_fields(self):
        tmp = super(SUMOForumPostMessage, self)._required_data_fields()
        tmp.append('thread')
        tmp.append('id')
        tmp.append('new')
        tmp.append('slug')
        return tmp


class SUMOArticleDiscussionMessage(SUMOForumPostMessage):

    def __init__(self, locale, who, when, article_id, slug, thread, id, is_new):
        super(SUMOArticleDiscussionMessage, self).__init__(locale, who, when, slug,
                                                           thread, id, is_new)
        self.routing_parts.append('article')
        self.routing_parts.append('forum')
        self.set_data('article', article_id)

    def _required_data_fields(self):
        tmp = super(SUMOArticleDiscussionMessage, self)._required_data_fields()
        tmp.append('article')
        return tmp


class SUMOArticleRevisionMessage(GenericSupportMessage):

    def __init__(self, locale, who, when):
        super(SUMOArticleRevisionMessage, self).__init__(locale, who, when)
        self.routing_parts.append('article')

    def _required_data_fields(self):
        tmp = super(SUMOArticleRevisionMessage, self)._required_data_fields()
        tmp.append('article')
        tmp.append('revision')
        return tmp