From e7413b8319a0057ac3067bea152bed87c485a671 Mon Sep 17 00:00:00 2001
From: Aaron Williamson <aaron@copiesofcopies.org>
Date: Thu, 12 May 2011 16:34:16 -0400
Subject: [PATCH 2/3] Add id to non-unique slugs, add unit test for unicode
characters.
---
mediagoblin/models.py | 7 ++++---
mediagoblin/submit/views.py | 6 +++---
mediagoblin/tests/test_util.py | 1 +
mediagoblin/views.py | 1 +
4 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/mediagoblin/models.py b/mediagoblin/models.py
index dd5ea5b..a858ffe 100644
a
|
b
|
from mongokit import Document, Set
|
20 | 20 | |
21 | 21 | from mediagoblin import util |
22 | 22 | from mediagoblin.auth import lib as auth_lib |
23 | | |
| 23 | from mediagoblin import globals as mediagoblin_globals |
24 | 24 | |
25 | 25 | ################### |
26 | 26 | # Custom validators |
… |
… |
class MediaEntry(Document):
|
104 | 104 | """ Generate a unique slug based on the image's title """ |
105 | 105 | |
106 | 106 | self['slug'] = util.slugify(self['title']) |
107 | | media = MediaEntry.find_one({'slug': self['slug']}) |
| 107 | |
| 108 | duplicate = mediagoblin_globals.database.media_entries.find_one({'slug': self['slug']}) |
108 | 109 | |
109 | | if media: |
| 110 | if duplicate: |
110 | 111 | self['slug'] = "%s-%s" % (self['_id'], self['slug']) |
111 | 112 | |
112 | 113 | REGISTER_MODELS = [MediaEntry, User] |
diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py
index 4e20cc6..eda77b0 100644
a
|
b
|
def submit_start(request):
|
46 | 46 | entry['media_type'] = u'image' # heh |
47 | 47 | entry['uploader'] = request.user |
48 | 48 | |
49 | | # Generate a slug from the title |
50 | | entry.generate_slug() |
51 | | |
52 | 49 | # Save, just so we can get the entry id for the sake of using |
53 | 50 | # it to generate the file path |
54 | 51 | entry.save(validate=False) |
55 | 52 | |
| 53 | # Generate a slug from the title |
| 54 | entry.generate_slug() |
| 55 | |
56 | 56 | # Now store generate the queueing related filename |
57 | 57 | queue_filepath = request.app.queue_store.get_unique_filepath( |
58 | 58 | ['media_entries', |
diff --git a/mediagoblin/tests/test_util.py b/mediagoblin/tests/test_util.py
index 861e8b6..db74956 100644
a
|
b
|
def test_slugify():
|
76 | 76 | assert util.slugify('a walk in the park') == 'a-walk-in-the-park' |
77 | 77 | assert util.slugify('a walk in-the-park') == 'a-walk-in-the-park' |
78 | 78 | assert util.slugify('a w@lk in the park?') == 'a-w-lk-in-the-park' |
| 79 | assert util.slugify(u'a walk in the par\u0107') == 'a-walk-in-the-parc' |
diff --git a/mediagoblin/views.py b/mediagoblin/views.py
index 95d0be7..7f925bb 100644
a
|
b
|
from webob import Response, exc
|
20 | 20 | import wtforms |
21 | 21 | from mongokit import ObjectId |
22 | 22 | from mediagoblin import models |
| 23 | import gettext |
23 | 24 | |
24 | 25 | def root_view(request): |
25 | 26 | media_entries = request.db.MediaEntry.find( |