# -*- coding: utf-8 -*- # vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 ############################################################################### # ScribeEngine - Open Source Blog Software # # --------------------------------------------------------------------------- # # Copyright (c) 2010 Raoul Snyman # # --------------------------------------------------------------------------- # # This program is free software; you can redistribute it and/or modify it # # under the terms of the GNU General Public License as published by the Free # # Software Foundation; version 2 of the License. # # # # This program is distributed in the hope that it will be useful, but WITHOUT # # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # # more details. # # # # You should have received a copy of the GNU General Public License along # # with this program; if not, write to the Free Software Foundation, Inc., 59 # # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### """ This module contains the Class definitions. """ class BaseModel(object): """ A base model class which all the other classes inherit from. This provides all model classes with a set of utility methods. """ def __init__(self, **kwargs): """ This constructor will set all the classes properties based on the keyword arguments supplied. """ for keyword, argument in kwargs.iteritems(): setattr(self, keyword, argument) def __repr__(self): if hasattr(self, 'id'): return '<%s id=%s>' % (self.__name__, self.id) class Category(BaseModel): """ This is a category for blog posts. """ pass class Comment(BaseModel): """ All blog posts have comments. This is a single comment. """ pass class Page(BaseModel): """ A page on the blog. This is separate from a blog entry, for things like about pages. """ pass class Permission(BaseModel): """ A single permission. """ pass class Post(BaseModel): """ The most import part of all of this, the blog post. """ pass class Role(BaseModel): """ A role defines a set of permissions. """ pass class Tag(BaseModel): """ A tag, an unstructured category, for blog posts. """ pass class User(BaseModel): """ The user. """ def has_permission(self, permission): if isinstance(permission, basestring): for role in self.roles: for perm in role.permissions: if perm.name == permission: return True return False elif isinstance(permission, Permission): for role in self.roles: for perm in role.permissions: if perm == permission: return True return False else: return False class Variable(BaseModel): """ System variables. """ pass