import datetime
from django.db import models
-from django.template import defaultfilters
+from django.utils.text import slugify
from karmaworld.settings.manual_unique_together import auto_add_check_unique_together
def save(self, *args, **kwargs):
""" Save school and generate a slug if one doesn't exist """
if not self.slug:
- self.slug = defaultfilters.slugify(self.name)
+ self.slug = slugify(self.name)
super(School, self).save(*args, **kwargs)
@staticmethod
def save(self, *args, **kwargs):
""" Save department and generate a slug if one doesn't exist """
if not self.slug:
- self.slug = defaultfilters.slugify(self.name)
+ self.slug = slugify(self.name)
super(Department, self).save(*args, **kwargs)
""" Save school and generate a slug if one doesn't exist """
super(Course, self).save(*args, **kwargs) # generate a self.id
if not self.slug:
- self.slug = defaultfilters.slugify("%s %s" % (self.name, self.id))
+ self.slug = slugify("%s %s" % (self.name, self.id))
self.save() # Save the slug
def get_updated_at_string(self):
from karmaworld.apps.courses.models import *
from django.test.client import Client
from django.core.urlresolvers import reverse
+from django.utils.text import slugify
import json
class CoursesTests(TestCase):
self.assertEqual(Course.objects.count(), 1)
def testSchoolSlug(self):
- self.assertEqual(self.harvard.slug, defaultfilters.slugify(self.harvard.name))
+ self.assertEqual(self.harvard.slug, slugify(self.harvard.name))
def testCourseSlug(self):
- self.assertEqual(self.course1.slug, defaultfilters.slugify("%s %s" % (self.course1.name, self.course1.id)))
+ self.assertEqual(self.course1.slug, slugify("%s %s" % (self.course1.name, self.course1.id)))
def testSearchForSchool(self):
"""Test searching for a school by partial name"""
from django.core.files import File
from django.core.files.storage import FileSystemStorage
from django.db import models
-from django.template import defaultfilters
+from django.utils.text import slugify
import django_filepicker
from lxml.html import fromstring, tostring
from taggit.managers import TaggableManager
def _generate_unique_slug(self):
""" generate a unique slug based on name and uploaded_at """
- _slug = defaultfilters.slugify(self.name)
+ _slug = slugify(self.name)
klass = self.__class__
collision = klass.objects.filter(slug=_slug)
if collision: