real objects.
"""
+from mediagoblin import mg_globals
from mediagoblin.auth import lib as auth_lib
from mediagoblin.tools import common, licenses
from mediagoblin.tools.text import cleaned_markdown_conversion
+from mediagoblin.tools.url import slugify
class UserMixin(object):
class MediaEntryMixin(object):
+ def generate_slug(self):
+ # import this here due to a cyclic import issue
+ # (db.models -> db.mixin -> db.util -> db.models)
+ from mediagoblin.db.util import check_media_slug_used
+
+ self.slug = slugify(self.title)
+
+ duplicate = check_media_slug_used(mg_globals.database,
+ self.uploader, self.slug, self.id)
+
+ if duplicate:
+ if self.id is not None:
+ self.slug = "%s-%s" % (self.id, self.slug)
+ else:
+ self.slug = None
+
@property
def description_html(self):
"""
from mongokit import Document
-from mediagoblin import mg_globals
from mediagoblin.db.mongo import migrations
from mediagoblin.db.mongo.util import ASCENDING, DESCENDING, ObjectId
from mediagoblin.tools.pagination import Pagination
-from mediagoblin.tools import url
from mediagoblin.db.mixin import UserMixin, MediaEntryMixin, MediaCommentMixin
return self.db.MediaComment.find({
'media_entry': self._id}).sort('created', order)
- def generate_slug(self):
- self.slug = url.slugify(self.title)
-
- duplicate = mg_globals.database.media_entries.find_one(
- {'slug': self.slug})
-
- if duplicate:
- self.slug = "%s-%s" % (self._id, self.slug)
-
def url_to_prev(self, urlgen):
"""
Provide a url to the previous entry from this user, if there is one