Commit 5fe5a785 authored by Daniel W Bond's avatar Daniel W Bond
Browse files

slugified name, to account for edge cases with whitespace

parent c7b606be
...@@ -5,6 +5,7 @@ from django.db import models ...@@ -5,6 +5,7 @@ from django.db import models
from model_utils.models import TimeStampedModel from model_utils.models import TimeStampedModel
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.utils.text import slugify
# third party imports # third party imports
from autoslug import AutoSlugField from autoslug import AutoSlugField
from allauth.socialaccount.models import SocialAccount from allauth.socialaccount.models import SocialAccount
...@@ -28,7 +29,10 @@ class Major(TimeStampedModel): ...@@ -28,7 +29,10 @@ class Major(TimeStampedModel):
return unicode(self.name) return unicode(self.name)
def get_absolute_url(self): def get_absolute_url(self):
return reverse('detail_major', kwargs={'slug': self.slug}) return reverse('detail_major', kwargs={
'slug': self.slug,
'major': slugify(self.name),
})
class Meta: class Meta:
ordering = ['name'] ordering = ['name']
......
# core django imports # core django imports
from django.db import models from django.db import models
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.utils.text import slugify
# third party imports # third party imports
from model_utils.models import TimeStampedModel from model_utils.models import TimeStampedModel
from randomslugfield import RandomSlugField from randomslugfield import RandomSlugField
...@@ -43,7 +44,7 @@ class Building(TimeStampedModel): ...@@ -43,7 +44,7 @@ class Building(TimeStampedModel):
def get_absolute_url(self): def get_absolute_url(self):
return reverse('detail_building', kwargs={ return reverse('detail_building', kwargs={
'building': self.building_name, 'building': slugify(self.building_name),
'slug': self.slug, 'slug': self.slug,
}) })
...@@ -67,7 +68,7 @@ class Floor(TimeStampedModel): ...@@ -67,7 +68,7 @@ class Floor(TimeStampedModel):
def get_absolute_url(self): def get_absolute_url(self):
return reverse('detail_floor', kwargs={ return reverse('detail_floor', kwargs={
'building': self.building.building_name, 'building': slugify(self.building.building_name),
'floor': self.floor_num, 'floor': self.floor_num,
'slug': self.slug, 'slug': self.slug,
}) })
...@@ -90,7 +91,7 @@ class Room(TimeStampedModel): ...@@ -90,7 +91,7 @@ class Room(TimeStampedModel):
def get_absolute_url(self): def get_absolute_url(self):
return reverse('detail_room', kwargs={ return reverse('detail_room', kwargs={
'floor': self.floor.floor_num, 'floor': self.floor.floor_num,
'building': self.floor.building.building_name, 'building': slugify(self.floor.building.building_name),
'room': self.room_num, 'room': self.room_num,
'slug': self.slug, 'slug': self.slug,
}) })
...@@ -118,7 +119,7 @@ class Room(TimeStampedModel): ...@@ -118,7 +119,7 @@ class Room(TimeStampedModel):
class Class(TimeStampedModel): class Class(TimeStampedModel):
grad_year = models.PositiveIntegerField() grad_year = models.PositiveIntegerField(null=True, blank=True)
FRESHMAN = 'FR' FRESHMAN = 'FR'
SOPHOMORE = 'SO' SOPHOMORE = 'SO'
JUNIOR = 'JR' JUNIOR = 'JR'
...@@ -139,4 +140,4 @@ class Class(TimeStampedModel): ...@@ -139,4 +140,4 @@ class Class(TimeStampedModel):
verbose_name_plural = 'classes' verbose_name_plural = 'classes'
def __str__(self): # __unicode__ on Python 2 def __str__(self): # __unicode__ on Python 2
return str(self.year_int) return str(self.year_in_school)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment