if duplicate:
self['slug'] = "%s-%s" % (self['_id'], self['slug'])
+ def url_for_self(self, urlgen):
+ """
+ Generate an appropriate url for ourselves
+
+ Use a slug if we have one, else use our '_id'.
+ """
+ if self.get('slug'):
+ return urlgen(
+ 'mediagoblin.user_pages.media_home',
+ user=self['uploader']['username'],
+ media=self['slug'])
+ else:
+ return urlgen(
+ 'mediagoblin.user_pages.media_home',
+ user=self['uploader']['username'],
+ media=unicode(self['_id']))
+
+
REGISTER_MODELS = [MediaEntry, User]
<ul>
{% for entry in media_entries %}
<li>
- <a href="{{ request.urlgen('mediagoblin.user_pages.media_home',
- user= entry.uploader.username, m_id= entry._id) }}">
+ <a href="{{ entry.url_for_self(request.urlgen) }}">
<img src="{{ request.app.public_store.file_url(
entry['media_files']['thumb']) }}" /></a>
</li>
<ul>
{% for entry in media_entries %}
<li>
- <a href="{{ request.urlgen('mediagoblin.user_pages.media_home',
- user= entry.uploader.username, m_id= entry._id) }}">
+ <a href="{{ entry.url_for_self(request.urlgen) }}">
<img src="{{ request.app.public_store.file_url(
entry['media_files']['thumb']) }}" /></a>
</li>