"""
$URL: svn+ssh://svn.mems-exchange.org/repos/trunk/dulcinea/lib/misc.py $
$Id: misc.py 29610 2007-03-14 21:12:59Z dbinger $
"""
from durus.persistent import PersistentObject
from durus.persistent_list import PersistentList
from qp.lib.spec import specify, Specified
from qp.lib.spec import string, sequence, add_getters_and_setters, spec
from qp.pub.common import get_connection
from qp.pub.user import User

def get_misc_db():
    return get_connection().get_root().get('misc_db')

class MiscDatabase (PersistentObject, Specified):

    motd_is = spec(
        string,
        "Message-of-the-day")
    recent_users_is = spec(
        sequence(User, PersistentList),
        "A list of most recently registered users.")

    recent_users_limit = 10

    def __init__(self):
        specify(self, motd='', recent_users=PersistentList())

    def note_user_registration(self, user):
        self.recent_users.insert(0, user)
        self.recent_users = self.recent_users[:self.recent_users_limit]

add_getters_and_setters(MiscDatabase)
