Let some code support "media without slug"
The upcoming SQL database will allow having media without a slug again. This might especially be useful for API support, where the uploaded image (media) does not have *any* information to generate a slug from. This code change mostly allows the sql backend to have no slug in its model and improves some parts to properly handle that. It specifically does not have any web frontend support to edit/create MediaEntries with no slug.
This commit is contained in:
parent
3c43cfc9f9
commit
3e907d5516
@ -63,6 +63,10 @@ class MediaEntryMixin(object):
|
||||
def main_mediafile(self):
|
||||
pass
|
||||
|
||||
@property
|
||||
def slug_or_id(self):
|
||||
return (self.slug or self._id)
|
||||
|
||||
def url_for_self(self, urlgen, **extra_args):
|
||||
"""
|
||||
Generate an appropriate url for ourselves
|
||||
@ -71,18 +75,11 @@ class MediaEntryMixin(object):
|
||||
"""
|
||||
uploader = self.get_uploader
|
||||
|
||||
if self.get('slug'):
|
||||
return urlgen(
|
||||
'mediagoblin.user_pages.media_home',
|
||||
user=uploader.username,
|
||||
media=self.slug,
|
||||
**extra_args)
|
||||
else:
|
||||
return urlgen(
|
||||
'mediagoblin.user_pages.media_home',
|
||||
user=uploader.username,
|
||||
media=unicode(self._id),
|
||||
**extra_args)
|
||||
return urlgen(
|
||||
'mediagoblin.user_pages.media_home',
|
||||
user=uploader.username,
|
||||
media=self.slug_or_id,
|
||||
**extra_args)
|
||||
|
||||
def get_fail_exception(self):
|
||||
"""
|
||||
|
@ -72,7 +72,7 @@ class MediaEntry(Base, MediaEntryMixin):
|
||||
id = Column(Integer, primary_key=True)
|
||||
uploader = Column(Integer, ForeignKey('users.id'), nullable=False)
|
||||
title = Column(Unicode, nullable=False)
|
||||
slug = Column(Unicode, nullable=False)
|
||||
slug = Column(Unicode)
|
||||
created = Column(DateTime, nullable=False, default=datetime.datetime.now)
|
||||
description = Column(UnicodeText) # ??
|
||||
description_html = Column(UnicodeText) # ??
|
||||
|
@ -127,7 +127,7 @@
|
||||
<a href="{{ request.urlgen('mediagoblin.user_pages.media_home.view_comment',
|
||||
comment = comment._id,
|
||||
user = media.get_uploader.username,
|
||||
media = media.slug) }}#comment">
|
||||
media = media.slug_or_id) }}#comment">
|
||||
{{ comment.created.strftime("%I:%M%p %Y-%m-%d") }}
|
||||
</a>
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user