aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/db/models.py
diff options
context:
space:
mode:
authortilly-Q <nattilypigeonfowl@gmail.com>2013-06-24 16:35:31 -0700
committertilly-Q <nattilypigeonfowl@gmail.com>2013-06-24 16:35:31 -0700
commit30a9fe7c1cf128fdf413797a2b2edac2d5439bc2 (patch)
treeca7f8617751381bcef931bc3ff0cb7f74342eeca /mediagoblin/db/models.py
parent25aad338d4921ec76484c6d2af5e40c97904917d (diff)
downloadmediagoblin-30a9fe7c1cf128fdf413797a2b2edac2d5439bc2.tar.lz
mediagoblin-30a9fe7c1cf128fdf413797a2b2edac2d5439bc2.tar.xz
mediagoblin-30a9fe7c1cf128fdf413797a2b2edac2d5439bc2.zip
This is the first stage of my project of implenting admin/moderator functiona-
lity. At this point, I have finished all the of basic work with the models! I still need to do some tightening of their documentation, but they seem to be working well. Working with Models ======================================== --\ mediagoblin/db/models.py --| Added in the Report model and table. This model is strictly a parent ----| Added in the CommentReport model which holds information about a report | filed against a comment. This class inherits from Report. ----| Added in the MediaReport model which holds information about a report f- | -iled against a media entry. This class inherits from Report. --| Added in a UserBan model and table. This model is in a one to one relatio- | -nship with User. This object acts as a marker for whether a user is banned | or not. --| Added in a Group model. These objects are in a many-to-many relationship | with User to explain which privileges a User has. ----| Added in GroupUserAssociation which is a table used to hold this many to | many relationship between Group & User. --\ mediagoblin/db/migrations.py --| Added in the migrations for all of the additions to models --| Added UserBan_v0 --| Added Report_v0 ----| Added CommentReport_v0 ----| Added MediaReport_v0 --| Added Group_v0 ----| Added GroupUserAssociation_v0 Working with Templates, Views, and Routing =============================================== >>> Reporting a Comment or a MediaEntry --\ mediagoblin/user_pages/views.py --| Added in the function file_a_report to allow user to file reports against | MediaEntries or Comments. Handles GET and POST requests. --| Added in the function file_a_comment_report which uses file_a_report but | also catches appropriate information for comment_ids. I may be able to do | this more eloquently with decorators. --\ mediagoblin/user_pages/routing.py --| Added in route 'mediagoblin.user_pages.media_home.report_media' | (linked to address /u/<user>/m/<media>/report/ ) --| Added in route ''mediagoblin.user_pages.media_home.report_comment' | (linked to address /u/<user>/m/<media>/c/<comment>/report/ ) --\ mediagoblin/templates/mediagoblin/user_pages/report.html --| I created this file to handle the filing of a report. --\ mediagoblin/templates/mediagoblin/user_pages/media.html --| Modified this file to add in links allowing users to report either media | or comments. --\ mediagoblin/user_pages/lib.py --| Added in build_report_form which processes data as either a CommentReport or | a MediaReport depending on which parameters are present --\ mediagoblin/user_pages/forms.py --| Added in CommentReportForm --| Added in MediaReportForm --| note: ReportForm is vestigial to an earlier strategy I used and I'll remove it | promptly --\ mediagoblin/decorators.py --| Added in 'get_media_comment_by_id' for use in mediagoblin/user_pages/views.py >>> New Admin Panels --\ mediagoblin/admin/views.py --| Added in the function admin_users_panel --| Added in the function admin_reports_panel --\ mediagoblin/admin/routing.py --| Added in route 'mediagoblin.admin.users' | (linked to address '/a/users') --| Added in route 'mediagoblin.admin.reports' | (linked to address '/a/reports/') --\ mediagoblin/templates/admin/user.html --| Created this file as a template for monitoring users --\ mediagoblin/templates/admin/report.html --| Created this file as a template for monitoring reports filed against media or | comments
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