aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--docs/hackinghowto.rst21
-rw-r--r--mediagoblin/db/models.py124
-rw-r--r--mediagoblin/tests/test_migrations.py3
3 files changed, 140 insertions, 8 deletions
diff --git a/docs/hackinghowto.rst b/docs/hackinghowto.rst
index 4cdbf03c..caafba53 100644
--- a/docs/hackinghowto.rst
+++ b/docs/hackinghowto.rst
@@ -194,7 +194,26 @@ If it's installed, check the mongodb log. On my machine, that's
old lock file: /var/lib/mongodb/mongod.lock. probably means...
-Then delete the lock file and relaunch mongodb.
+in that case you might have had an unclean shutdown. Try::
+
+ sudo mongod --repair
+
+If that didn't work, just delete the lock file and relaunch mongodb.
+
+Anyway, then start the mongodb server in whatever way is appropriate
+for your distro / OS.
+
+
+pkg_resources.DistributionNotFound: distribute
+----------------------------------------------
+
+If you get this while running buildout::
+
+ pkg_resources.DistributionNotFound: distribute
+
+Try this commmand instead::
+
+ python bootstrap.py --distribute && ./bin/buildout
Wiping your user data
diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py
index 9d7bcf6b..bad15aca 100644
--- a/mediagoblin/db/models.py
+++ b/mediagoblin/db/models.py
@@ -37,6 +37,32 @@ from mediagoblin.util import DISPLAY_IMAGE_FETCHING_ORDER
class User(Document):
+ """
+ A user of MediaGoblin.
+
+ Structure:
+ - username: The username of this user, should be unique to this instance.
+ - email: Email address of this user
+ - created: When the user was created
+ - plugin_data: a mapping of extra plugin information for this User.
+ Nothing uses this yet as we don't have plugins, but someday we
+ might... :)
+ - pw_hash: Hashed version of user's password.
+ - email_verified: Whether or not the user has verified their email or not.
+ Most parts of the site are disabled for users who haven't yet.
+ - status: whether or not the user is active, etc. Currently only has two
+ values, 'needs_email_verification' or 'active'. (In the future, maybe
+ we'll change this to a boolean with a key of 'active' and have a
+ separate field for a reason the user's been disabled if that's
+ appropriate... email_verified is already separate, after all.)
+ - verification_key: If the user is awaiting email verification, the user
+ will have to provide this key (which will be encoded in the presented
+ URL) in order to confirm their email as active.
+ - is_admin: Whether or not this user is an administrator or not.
+ - url: this user's personal webpage/website, if appropriate.
+ - bio: biography of this user (plaintext, in markdown)
+ - bio_html: biography of the user converted to proper HTML.
+ """
__collection__ = 'users'
structure = {
@@ -62,7 +88,7 @@ class User(Document):
'status': u'needs_email_verification',
'verification_key': lambda: unicode(uuid.uuid4()),
'is_admin': False}
-
+
def check_login(self, password):
"""
See if a user can login with this password
@@ -72,6 +98,80 @@ class User(Document):
class MediaEntry(Document):
+ """
+ Record of a piece of media.
+
+ Structure:
+ - uploader: A reference to a User who uploaded this.
+
+ - title: Title of this work
+
+ - slug: A normalized "slug" which can be used as part of a URL to retrieve
+ this work, such as 'my-works-name-in-slug-form' may be viewable by
+ 'http://mg.example.org/u/username/m/my-works-name-in-slug-form/'
+ Note that since URLs are constructed this way, slugs must be unique
+ per-uploader. (An index is provided to enforce that but code should be
+ written on the python side to ensure this as well.)
+
+ - created: Date and time of when this piece of work was uploaded.
+
+ - description: Uploader-set description of this work. This can be marked
+ up with MarkDown for slight fanciness (links, boldness, italics,
+ paragraphs...)
+
+ - description_html: Rendered version of the description, run through
+ Markdown and cleaned with our cleaning tool.
+
+ - media_type: What type of media is this? Currently we only support
+ 'image' ;)
+
+ - media_data: Extra information that's media-format-dependent.
+ For example, images might contain some EXIF data that's not appropriate
+ to other formats. You might store it like:
+
+ mediaentry['media_data']['exif'] = {
+ 'manufacturer': 'CASIO',
+ 'model': 'QV-4000',
+ 'exposure_time': .659}
+
+ Alternately for video you might store:
+
+ # play length in seconds
+ mediaentry['media_data']['play_length'] = 340
+
+ ... so what's appropriate here really depends on the media type.
+
+ - plugin_data: a mapping of extra plugin information for this User.
+ Nothing uses this yet as we don't have plugins, but someday we
+ might... :)
+
+ - tags: A list of tags. Each tag is stored as a dictionary that has a key
+ for the actual name and the normalized name-as-slug, so ultimately this
+ looks like:
+ [{'name': 'Gully Gardens',
+ 'slug': 'gully-gardens'},
+ {'name': 'Castle Adventure Time?!",
+ 'slug': 'castle-adventure-time'}]
+
+ - state: What's the state of this file? Active, inactive, disabled, etc...
+ But really for now there are only two states:
+ "unprocessed": uploaded but needs to go through processing for display
+ "processed": processed and able to be displayed
+
+ - queued_media_file: storage interface style filepath describing a file
+ queued for processing. This is stored in the mg_globals.queue_store
+ storage system.
+
+ - media_files: Files relevant to this that have actually been processed
+ and are available for various types of display. Stored like:
+ {'thumb': ['dir1', 'dir2', 'pic.png'}
+
+ - attachment_files: A list of "attachment" files, ones that aren't
+ critical to this piece of media but may be usefully relevant to people
+ viewing the work. (currently unused.)
+
+ - thumbnail_file: Deprecated... we should remove this ;)
+ """
__collection__ = 'media_entries'
structure = {
@@ -138,7 +238,7 @@ class MediaEntry(Document):
duplicate = mg_globals.database.media_entries.find_one(
{'slug': self['slug']})
-
+
if duplicate:
self['slug'] = "%s-%s" % (self['_id'], self['slug'])
@@ -160,12 +260,12 @@ class MediaEntry(Document):
'mediagoblin.user_pages.media_home',
user=uploader['username'],
media=unicode(self['_id']))
-
+
def url_to_prev(self, urlgen):
"""
Provide a url to the previous entry from this user, if there is one
"""
- cursor = self.db.MediaEntry.find({'_id' : {"$gt": self['_id']},
+ cursor = self.db.MediaEntry.find({'_id' : {"$gt": self['_id']},
'uploader': self['uploader'],
'state': 'processed'}).sort(
'_id', ASCENDING).limit(1)
@@ -173,12 +273,12 @@ class MediaEntry(Document):
return urlgen('mediagoblin.user_pages.media_home',
user=self.uploader()['username'],
media=unicode(cursor[0]['slug']))
-
+
def url_to_next(self, urlgen):
"""
Provide a url to the next entry from this user, if there is one
"""
- cursor = self.db.MediaEntry.find({'_id' : {"$lt": self['_id']},
+ cursor = self.db.MediaEntry.find({'_id' : {"$lt": self['_id']},
'uploader': self['uploader'],
'state': 'processed'}).sort(
'_id', DESCENDING).limit(1)
@@ -193,6 +293,18 @@ class MediaEntry(Document):
class MediaComment(Document):
+ """
+ A comment on a MediaEntry.
+
+ Structure:
+ - media_entry: The media entry this comment is attached to
+ - author: user who posted this comment
+ - created: when the comment was created
+ - content: plaintext (but markdown'able) version of the comment's content.
+ - content_html: the actual html-rendered version of the comment displayed.
+ Run through Markdown and the HTML cleaner.
+ """
+
__collection__ = 'media_comments'
structure = {
diff --git a/mediagoblin/tests/test_migrations.py b/mediagoblin/tests/test_migrations.py
index 127b90e1..c100a26a 100644
--- a/mediagoblin/tests/test_migrations.py
+++ b/mediagoblin/tests/test_migrations.py
@@ -42,7 +42,8 @@ def creature_add_magical_powers(database):
Add lists of magical powers.
This defaults to [], an empty list. Since we haven't declared any
- magical powers, all existing monsters should
+ magical powers, all existing monsters, setting to an empty list is
+ fine.
"""
database['creatures'].update(
{'magical_powers': {'$exists': False}},