Ticket #36: 0001-Patch-for-Feature-306.patch

File 0001-Patch-for-Feature-306.patch, 3.7 KB (added by Aaron Williamson, 13 years ago)

0001-Patch-for-Feature-306.patch

  • mediagoblin/models.py

    From 270c8e81a7ef796a2dc24ae0dfa5c1e6678b3d96 Mon Sep 17 00:00:00 2001
    From: Aaron Williamson <aaron@copiesofcopies.org>
    Date: Tue, 10 May 2011 00:20:09 -0400
    Subject: [PATCH] Patch for Feature #306
    
    ---
     mediagoblin/models.py          |    4 ++++
     mediagoblin/submit/views.py    |    3 +++
     mediagoblin/tests/test_util.py |    7 +++++++
     mediagoblin/util.py            |   15 ++++++++++++++-
     setup.py                       |    1 +
     5 files changed, 29 insertions(+), 1 deletions(-)
    
    diff --git a/mediagoblin/models.py b/mediagoblin/models.py
    index 69b1f4f..96b2de7 100644
    a b import datetime, uuid  
    1818
    1919from mongokit import Document, Set
    2020
     21from mediagoblin import util
    2122from mediagoblin.auth import lib as auth_lib
    2223
    2324
    class MediaEntry(Document):  
    6667    structure = {
    6768        'uploader': User,
    6869        'title': unicode,
     70        'slug':unicode,
    6971        'created': datetime.datetime,
    7072        'description': unicode,
    7173        'media_type': unicode,
    class MediaEntry(Document):  
    98100    def main_mediafile(self):
    99101        pass
    100102
     103    def generate_slug(self):
     104        self['slug'] = util.slugify(self['title'])
    101105
    102106REGISTER_MODELS = [MediaEntry, User]
    103107
  • mediagoblin/submit/views.py

    diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py
    index 5e262f1..4e20cc6 100644
    a b def submit_start(request):  
    4646            entry['media_type'] = u'image' # heh
    4747            entry['uploader'] = request.user
    4848
     49            # Generate a slug from the title
     50            entry.generate_slug()
     51
    4952            # Save, just so we can get the entry id for the sake of using
    5053            # it to generate the file path
    5154            entry.save(validate=False)
  • mediagoblin/tests/test_util.py

    diff --git a/mediagoblin/tests/test_util.py b/mediagoblin/tests/test_util.py
    index 5bc31fd..861e8b6 100644
    a b I hope you like unit tests JUST AS MUCH AS I DO!"""  
    6969    assert mbox_message.get_payload(decode=True) == """HAYYY GUYS!
    7070
    7171I hope you like unit tests JUST AS MUCH AS I DO!"""
     72
     73def test_slugify():
     74    assert util.slugify('a walk in the park') == 'a-walk-in-the-park'
     75    assert util.slugify('A Walk in the Park') == 'a-walk-in-the-park'
     76    assert util.slugify('a  walk in the park') == 'a-walk-in-the-park'
     77    assert util.slugify('a walk in-the-park') == 'a-walk-in-the-park'
     78    assert util.slugify('a w@lk in the park?') == 'a-w-lk-in-the-park'
  • mediagoblin/util.py

    diff --git a/mediagoblin/util.py b/mediagoblin/util.py
    index 8695180..37bd532 100644
    a b  
    1717from email.MIMEText import MIMEText
    1818import smtplib
    1919import sys
    20 
     20import re
    2121import jinja2
    2222import mongokit
     23import translitcodec
    2324
    2425from mediagoblin import globals as mgoblin_globals
    2526
    def import_component(import_string):  
    8788    func = getattr(module, func_name)
    8889    return func
    8990
     91_punct_re = re.compile(r'[\t !"#$%&\'()*\-/<=>?@\[\\\]^_`{|},.]+')
     92
     93def slugify(text, delim=u'-'):
     94    """
     95    Generates an ASCII-only slug. Taken from http://flask.pocoo.org/snippets/5/
     96    """
     97    result = []
     98    for word in _punct_re.split(text.lower()):
     99        word = word.encode('translit/long')
     100        if word:
     101            result.append(word)
     102    return unicode(delim.join(result))
    90103
    91104### ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    92105### Special email test stuff begins HERE
  • setup.py

    diff --git a/setup.py b/setup.py
    index 7b483a5..283f9a2 100644
    a b setup(  
    3838        'jinja2',
    3939        'sphinx',
    4040        'PIL',
     41        'translitcodec',
    4142        ],
    4243    test_suite='nose.collector',
    4344