aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/db/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'mediagoblin/db/models.py')
-rw-r--r--mediagoblin/db/models.py88
1 files changed, 86 insertions, 2 deletions
diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py
index 2b925983..f524b220 100644
--- a/mediagoblin/db/models.py
+++ b/mediagoblin/db/models.py
@@ -29,6 +29,7 @@ from sqlalchemy.orm.collections import attribute_mapped_collection
from sqlalchemy.sql.expression import desc
from sqlalchemy.ext.associationproxy import association_proxy
from sqlalchemy.util import memoized_property
+from sqlalchemy.schema import Table
from mediagoblin.db.extratypes import PathTupleWithSlashes, JSONEncoded
from mediagoblin.db.base import Base, DictReadAttrProxy
@@ -484,10 +485,93 @@ class ProcessingMetaData(Base):
return DictReadAttrProxy(self)
+class ReportBase(Base):
+ """
+
+ """
+ __tablename__ = 'core__reports'
+ id = Column(Integer, primary_key=True)
+ reporter_id = Column(Integer, ForeignKey(User.id), nullable=False)
+ reporter = relationship(User, backref=backref("reports_filed_by",
+ lazy="dynamic",
+ cascade="all, delete-orphan"))
+ report_content = Column(UnicodeText)
+ created = Column(DateTime, nullable=False, default=datetime.datetime.now())
+ resolved = Column(DateTime)
+ discriminator = Column('type', Unicode(50))
+ __mapper_args__ = {'polymorphic_on': discriminator}
+
+
+class CommentReport(ReportBase):
+ """
+ A class to keep track of reports that have been filed on comments
+ """
+ __tablename__ = 'core__reports_on_comments'
+ __mapper_args__ = {'polymorphic_identity': 'comment_report'}
+
+ id = Column('id',Integer, ForeignKey('core__reports.id'),
+ primary_key=True)
+ comment_id = Column(Integer, ForeignKey(MediaComment.id), nullable=False)
+ comment = relationship(MediaComment, backref=backref("reports_filed_on",
+ lazy="dynamic",
+ cascade="all, delete-orphan"))
+
+class MediaReport(ReportBase):
+ """
+ A class to keep track of reports that have been filed on media entries
+ """
+ __tablename__ = 'core__reports_on_media'
+ __mapper_args__ = {'polymorphic_identity': 'media_report'}
+
+ id = Column('id',Integer, ForeignKey('core__reports.id'),
+ primary_key=True)
+ media_entry_id = Column(Integer, ForeignKey(MediaEntry.id), nullable=False)
+ media_entry = relationship(MediaEntry, backref=backref("reports_filed_on",
+ lazy="dynamic",
+ cascade="all, delete-orphan"))
+
+class UserBan(Base):
+ """
+ Holds the information on a specific user's ban-state. As long as one of these
+ is attached to a user, they are banned from accessing mediagoblin. When they
+ try to log in, they are greeted with a page that tells them the reason why
+ they are banned and when (if ever) the ban will be lifted
+ :param user_id Holds the id of the user this object is attached to.
+ This should be a one-to-one relationship.
+ :param expiration_date Holds the date that the ban will be lifted. If this
+ is null, the ban is permanent unless a moderator
+ manually lifts it.
+ :param reason Holds the reason why the user was banned.
+ """
+ __tablename__ = 'core__user_bans'
+
+ user_id = Column('id',Integer, ForeignKey(User.id), nullable=False,
+ primary_key=True)
+ expiration_date = Column(DateTime)
+ reason = Column(UnicodeText, nullable=False)
+
+
+class Group(Base):
+ __tablename__ = 'core__groups'
+
+ id = Column(Integer, nullable=False, primary_key=True)
+ group_name = Column(Unicode, nullable=False)
+ all_users = relationship(User, backref='all_groups', secondary="core__group_user_associations")
+
+ def __repr__(self):
+ return "<Group %s>" % (self.group_name)
+
+class GroupUserAssociation(Base):
+ __tablename__ = 'core__group_user_associations'
+
+ group_id = Column('core__group_id', Integer, ForeignKey(User.id), primary_key=True)
+ user_id = Column('core__user_id', Integer, ForeignKey(Group.id), primary_key=True)
+
+
+
MODELS = [
User, MediaEntry, Tag, MediaTag, MediaComment, Collection, CollectionItem, MediaFile, FileKeynames,
- MediaAttachmentFile, ProcessingMetaData]
-
+ MediaAttachmentFile, ProcessingMetaData, CommentReport, MediaReport, UserBan, Group, GroupUserAssociation]
######################################################
# Special, migrations-tracking table