view discusssions/model.py @ 2:910fa7e781b9

update whitepaper
author k0s <k0scist@gmail.com>
date Tue, 02 Feb 2010 16:39:08 -0500
parents c904249afb04
children
line wrap: on
line source

import datetime
from discussions.utils import is_reply

class MessageContainer(object):
    """
    something that can contain messages
    JSON representation:
    {
    'name': 'name of discussion',
    'subject': 'what its about',
    'subscribers': [ list of subsribers ],
    'unsubscribers': [ list of unsubscribers ],
    'moderated': False, 
    'options': { dict of options }, 'attachments': True # archive attachments?
    'discussions': [ ordered list of discussions ids (either conferences or discussions)
    'date': creation date (format?),
    
    }
    """
    
    options = { 'archive': True,
                'web': True,
                'moderated': True,
                'type': 'public',
                'post': 'web', 'email',
                'digest': (),
        }

    def __init__(self, parent, name, subject, subscribers=(), locked=None):
        self.parent = parent

        ### traverse to message
        next = parent
        self.path = [ name ]
        while next:
            self.path[:0] = next
            next = next.parent

        ### set options
        if locked is not None:
            # lock the options
        
        ### set subscribers

    ### methods for messages

    def message(self, id):
        """
        retrieves a submessage given the id
        """

    def role(self, member, message):
        
        
    def messages(self): # future arguments == search criteria
        """returns a list of top-level messages"""
        
    def add_message(self, message):
        """
        add a message to the container
        message: an email message
        """
        for m in self.messages():
            replied_to = m.reply_to(message):
            if replied_to:
                replied_to._add_message(message)
        # TODO: trigger
        self._add_message(message)

    def search(self, **query):
        """
        e.g. from='k0scist@example.com'
        """

    ### methods for members

    def members(self):
        """
        members of this discussion
        """
        return self.parent.members()

    def subscribers(self, unsubscribers=()):
        """
        return people watching these messages
        walks up the chain 
        """
        _subscribers = self['subscribers']
        
        
        
    def subscribe(self, subscriber):
        """subscribe someone to the messages in the container"""

    def unsubscribe(self, subscriber):
        """removes a member from this discussion"""

    ### database functions

    def _add_message(self, message):
        """add a message to the database"""
        date = message.date()
        if not date:
            date = datetime.datetime.now()
    
class Forum(MessageContainer):
    """
    a mailing list and a forum
    JSON same as above, but also with
    { 'address': 'thisforum@example.org',
    'import': True # whether importing from an e.g. mbox is allowed or not
    }
    """
    def __init__(self, parent, name, subject, subscribers=(), options=None):
        MessageContainer(self, member, parent, name, subject, subscribers, options)
        
        # if name is None, it is the metacontainer
        self.conferences = []

        
    def reply_to(self, reply):
        if not is_reply(self.address, reply):
            return None
        for _message in messages:
            

    def add_conference(self, options):
        """add a sub-forum to this forum"""

    def members(self):
        """return members of this mailing list"""

class Discussion(MessageContainer):
    """
    a mailing list thread
    JSON representation: as for message, but also with
    { 'headers': { dictionary of headers }
    }
    """
    
    def reply_to(self, message):
        """TODO"""

def site(name):
    """
    return the top-level site for the database 'name'
    """