mirror of
https://github.com/Hopiu/django-uuslug.git
synced 2026-03-16 20:10:24 +00:00
pep8 complient
This commit is contained in:
parent
a60cea5b23
commit
499264db5b
6 changed files with 33 additions and 36 deletions
|
|
@ -5,8 +5,10 @@ python:
|
|||
- "3.3"
|
||||
env:
|
||||
- DJANGO=1.5.5
|
||||
- DJANGO=1.6.1
|
||||
- DJANGO=1.6.2
|
||||
install:
|
||||
- pip install -q Django==$DJANGO --use-mirrors
|
||||
- pip install -q -r requirements.txt --use-mirrors
|
||||
- pip install pep8 --use-mirrors
|
||||
- pip install -q -e . --use-mirrors
|
||||
script: python manage.py test
|
||||
|
|
|
|||
12
pep8.sh
12
pep8.sh
|
|
@ -1,5 +1,11 @@
|
|||
#!/bin/bash
|
||||
|
||||
echo -e "\nRunning: (pep8 --show-source --show-pep8 --select=errors --testsuite=.)\n\n"
|
||||
pep8 --show-source --show-pep8 --select=errors --testsuite=./
|
||||
echo -e "\n\n"
|
||||
# Ignoring autogenerated files
|
||||
# -- Migration directories
|
||||
# Ignoring error codes
|
||||
# -- E128 continuation line under-indented for visual indent
|
||||
# -- E225 missing whitespace around operator
|
||||
# -- E501 line too long
|
||||
|
||||
pep8 --exclude=migrations --ignore=E128,E225,E501 .
|
||||
|
||||
|
|
|
|||
1
setup.py
1
setup.py
|
|
@ -25,6 +25,7 @@ classifiers = [
|
|||
'Topic :: Utilities'
|
||||
]
|
||||
|
||||
|
||||
def get_version(package):
|
||||
"""
|
||||
Return package version as listed in `__version__` in `init.py`.
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ from slugify import slugify as pyslugify
|
|||
|
||||
__all__ = ['slugify', 'uuslug']
|
||||
|
||||
|
||||
def slugify(text, entities=True, decimal=True, hexadecimal=True, max_length=0, word_boundary=False, separator='-'):
|
||||
""" Make a slug from a given text """
|
||||
|
||||
|
|
@ -14,7 +15,8 @@ def slugify(text, entities=True, decimal=True, hexadecimal=True, max_length=0, w
|
|||
|
||||
|
||||
def uuslug(s, instance, entities=True, decimal=True, hexadecimal=True,
|
||||
slug_field='slug', filter_dict=None, start_no=1, max_length=0, word_boundary=False, separator='-'):
|
||||
slug_field='slug', filter_dict=None, start_no=1, max_length=0,
|
||||
word_boundary=False, separator='-'):
|
||||
|
||||
""" This method tries a little harder than django's django.template.defaultfilters.slugify. """
|
||||
|
||||
|
|
@ -35,13 +37,8 @@ def uuslug(s, instance, entities=True, decimal=True, hexadecimal=True,
|
|||
while queryset.filter(**{slug_field: new_slug}).exists():
|
||||
if max_length > 0:
|
||||
if len(slug) + len(separator) + len(str(counter)) > max_length:
|
||||
slug = slug[:max_length-len(slug)-len(separator)-len(str(counter))] # make room for the "-1, -2 ... etc"
|
||||
slug = slug[:max_length-len(slug)-len(separator)-len(str(counter))]
|
||||
new_slug = "%s%s%s" % (slug, separator, counter)
|
||||
counter += 1
|
||||
|
||||
return new_slug
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import os
|
||||
|
||||
|
||||
# create a database table only in unit test mode
|
||||
if 'testsettings' in os.environ['DJANGO_SETTINGS_MODULE']:
|
||||
from django.db import models
|
||||
|
|
@ -16,7 +17,6 @@ if 'testsettings' in os.environ['DJANGO_SETTINGS_MODULE']:
|
|||
self.slug = uuslug(self.name, instance=self)
|
||||
super(CoolSlug, self).save(*args, **kwargs)
|
||||
|
||||
|
||||
class AnotherSlug(models.Model):
|
||||
name = models.CharField(max_length=100)
|
||||
slug = models.CharField(max_length=200)
|
||||
|
|
@ -28,7 +28,6 @@ if 'testsettings' in os.environ['DJANGO_SETTINGS_MODULE']:
|
|||
self.slug = uuslug(self.name, instance=self, start_no=2)
|
||||
super(AnotherSlug, self).save(*args, **kwargs)
|
||||
|
||||
|
||||
class TruncatedSlug(models.Model):
|
||||
name = models.CharField(max_length=15)
|
||||
slug = models.CharField(max_length=17)
|
||||
|
|
@ -40,7 +39,6 @@ if 'testsettings' in os.environ['DJANGO_SETTINGS_MODULE']:
|
|||
self.slug = uuslug(self.name, instance=self, start_no=2, max_length=17, word_boundary=False)
|
||||
super(TruncatedSlug, self).save(*args, **kwargs)
|
||||
|
||||
|
||||
class SmartTruncatedSlug(models.Model):
|
||||
name = models.CharField(max_length=17)
|
||||
slug = models.CharField(max_length=17)
|
||||
|
|
@ -52,7 +50,6 @@ if 'testsettings' in os.environ['DJANGO_SETTINGS_MODULE']:
|
|||
self.slug = uuslug(self.name, instance=self, start_no=2, max_length=17, word_boundary=True)
|
||||
super(SmartTruncatedSlug, self).save(*args, **kwargs)
|
||||
|
||||
|
||||
class SmartTruncatedExactWordBoundrySlug(models.Model):
|
||||
name = models.CharField(max_length=19)
|
||||
slug = models.CharField(max_length=19)
|
||||
|
|
@ -64,7 +61,6 @@ if 'testsettings' in os.environ['DJANGO_SETTINGS_MODULE']:
|
|||
self.slug = uuslug(self.name, instance=self, start_no=9, max_length=19, word_boundary=True)
|
||||
super(SmartTruncatedExactWordBoundrySlug, self).save(*args, **kwargs)
|
||||
|
||||
|
||||
class CoolSlugDifferentSeparator(models.Model):
|
||||
name = models.CharField(max_length=100)
|
||||
slug = models.CharField(max_length=200)
|
||||
|
|
@ -86,6 +82,3 @@ if 'testsettings' in os.environ['DJANGO_SETTINGS_MODULE']:
|
|||
def save(self, *args, **kwargs):
|
||||
self.slug = uuslug(self.name, instance=self, start_no=2, max_length=17, word_boundary=False, separator='_')
|
||||
super(TruncatedSlugDifferentSeparator, self).save(*args, **kwargs)
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ from uuslug.models import (CoolSlug, AnotherSlug, TruncatedSlug,
|
|||
SmartTruncatedSlug, SmartTruncatedExactWordBoundrySlug,
|
||||
CoolSlugDifferentSeparator, TruncatedSlugDifferentSeparator)
|
||||
|
||||
|
||||
class SlugUnicodeTestCase(TestCase):
|
||||
"""Tests for Slug - Unicode"""
|
||||
|
||||
|
|
@ -18,11 +19,11 @@ class SlugUnicodeTestCase(TestCase):
|
|||
txt = "This is a test ---"
|
||||
r = slugify(txt)
|
||||
self.assertEquals(r, "this-is-a-test")
|
||||
|
||||
|
||||
txt = "This -- is a ## test ---"
|
||||
r = slugify(txt)
|
||||
self.assertEquals(r, "this-is-a-test")
|
||||
|
||||
|
||||
txt = 'C\'est déjà l\'été.'
|
||||
r = slugify(txt)
|
||||
self.assertEquals(r, "cest-deja-lete")
|
||||
|
|
@ -71,9 +72,10 @@ class SlugUnicodeTestCase(TestCase):
|
|||
r = slugify(txt, max_length=20, word_boundary=True, separator="ZZZZZZ")
|
||||
self.assertEquals(r, "jajaZZZZZZlolZZZZZZmememeooZZZZZZa")
|
||||
|
||||
|
||||
class SlugUniqueTestCase(TestCase):
|
||||
"""Tests for Slug - Unique"""
|
||||
|
||||
|
||||
def test_manager(self):
|
||||
name = "john"
|
||||
|
||||
|
|
@ -119,31 +121,30 @@ class SlugUniqueTestCase(TestCase):
|
|||
obj = AnotherSlug.objects.create(name=name)
|
||||
self.assertEquals(obj.slug, "foo-bar-3")
|
||||
|
||||
|
||||
def test_max_length(self):
|
||||
name = 'jaja---lol-méméméoo--a'
|
||||
|
||||
obj = TruncatedSlug.objects.create(name=name)
|
||||
self.assertEquals(obj.slug, "jaja-lol-mememeoo") # 17 is max_length
|
||||
self.assertEquals(obj.slug, "jaja-lol-mememeoo") # 17 is max_length
|
||||
|
||||
obj = TruncatedSlug.objects.create(name=name)
|
||||
self.assertEquals(obj.slug, "jaja-lol-mememe-2") # 17 is max_length
|
||||
self.assertEquals(obj.slug, "jaja-lol-mememe-2") # 17 is max_length
|
||||
|
||||
obj = TruncatedSlug.objects.create(name=name)
|
||||
self.assertEquals(obj.slug, "jaja-lol-mememe-3") # 17 is max_length
|
||||
|
||||
self.assertEquals(obj.slug, "jaja-lol-mememe-3") # 17 is max_length
|
||||
|
||||
def test_max_length_exact_word_boundry(self):
|
||||
name = 'jaja---lol-méméméoo--a'
|
||||
|
||||
obj = SmartTruncatedExactWordBoundrySlug.objects.create(name=name)
|
||||
self.assertEquals(obj.slug, "jaja-lol-mememeoo") # 19 is max_length
|
||||
self.assertEquals(obj.slug, "jaja-lol-mememeoo") # 19 is max_length
|
||||
|
||||
obj = SmartTruncatedExactWordBoundrySlug.objects.create(name=name)
|
||||
self.assertEquals(obj.slug, "jaja-lol-mememeoo-9") # 19 is max_length, start_no = 9
|
||||
self.assertEquals(obj.slug, "jaja-lol-mememeoo-9") # 19 is max_length, start_no = 9
|
||||
|
||||
obj = SmartTruncatedExactWordBoundrySlug.objects.create(name=name)
|
||||
self.assertEquals(obj.slug, "jaja-lol-mememeo-10") # 19 is max_length, readjust for "-10"
|
||||
self.assertEquals(obj.slug, "jaja-lol-mememeo-10") # 19 is max_length, readjust for "-10"
|
||||
|
||||
|
||||
class SlugUniqueDifferentSeparatorTestCase(TestCase):
|
||||
"""Tests for Slug - Unique with different separator """
|
||||
|
|
@ -178,13 +179,10 @@ class SlugUniqueDifferentSeparatorTestCase(TestCase):
|
|||
name = 'jaja---lol-méméméoo--a'
|
||||
|
||||
obj = TruncatedSlugDifferentSeparator.objects.create(name=name)
|
||||
self.assertEquals(obj.slug, "jaja_lol_mememeoo") # 17 is max_length
|
||||
self.assertEquals(obj.slug, "jaja_lol_mememeoo") # 17 is max_length
|
||||
|
||||
obj = TruncatedSlugDifferentSeparator.objects.create(name=name)
|
||||
self.assertEquals(obj.slug, "jaja_lol_mememe_2") # 17 is max_length
|
||||
self.assertEquals(obj.slug, "jaja_lol_mememe_2") # 17 is max_length
|
||||
|
||||
obj = TruncatedSlugDifferentSeparator.objects.create(name=name)
|
||||
self.assertEquals(obj.slug, "jaja_lol_mememe_3") # 17 is max_length
|
||||
|
||||
|
||||
|
||||
self.assertEquals(obj.slug, "jaja_lol_mememe_3") # 17 is max_length
|
||||
|
|
|
|||
Loading…
Reference in a new issue