Commit 2192160f authored by Daniel W Bond's avatar Daniel W Bond
Browse files

slugs now functional-- see comments on issue

parent a5ae18ab
from django.db import models from django.db import models
from autoslug import AutoSlugField from autoslug import AutoSlugField
from model_utils.models import TimeStampedModel from model_utils.models import TimeStampedModel
from randomslugfield import RandomSlugField
#from localflavor.us.models import USStateField #from localflavor.us.models import USStateField
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
...@@ -33,12 +34,16 @@ class Building(TimeStampedModel): ...@@ -33,12 +34,16 @@ class Building(TimeStampedModel):
(FAIRFAX, 'Fairfax'), (FAIRFAX, 'Fairfax'),
) )
campus = models.CharField(max_length=100, choices=CAMPUS_CHOICES, default=NONE) campus = models.CharField(max_length=100, choices=CAMPUS_CHOICES, default='ff')
slug = AutoSlugField(populate_from='name', unique=True) slug = RandomSlugField(length=6)
building_name = AutoSlugField(populate_from='name')
def get_absolute_url(self): def get_absolute_url(self):
return reverse('detail_building', kwargs={'slug':self.slug}) return reverse('detail_building', kwargs={
'building':self.building_name,
'slug':self.slug,
})
def __str__(self): # __unicode__ on Python 2 def __str__(self): # __unicode__ on Python 2
return self.name return self.name
...@@ -52,13 +57,16 @@ class Floor(TimeStampedModel): ...@@ -52,13 +57,16 @@ class Floor(TimeStampedModel):
building = models.ForeignKey('Building') building = models.ForeignKey('Building')
number = models.IntegerField() number = models.IntegerField()
slug = AutoSlugField(populate_from='number',# unique_with='building') slug = RandomSlugField(length=6)
unique=True)
floor_num = AutoSlugField(populate_from='number',# unique_with='building')
)
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,
'floor':self.floor_num,
'slug':self.slug, 'slug':self.slug,
'building':self.building.slug,
}) })
def __str__(self): # __unicode__ on Python 2 def __str__(self): # __unicode__ on Python 2
...@@ -71,14 +79,17 @@ class Room(TimeStampedModel): ...@@ -71,14 +79,17 @@ class Room(TimeStampedModel):
number = models.IntegerField() number = models.IntegerField()
floor = models.ForeignKey('Floor') floor = models.ForeignKey('Floor')
slug = AutoSlugField(populate_from='number',# unique_with='floor') slug = RandomSlugField(length=6)
unique=True)
room_num = AutoSlugField(populate_from='number',# unique_with='floor')
)
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,
'building':self.floor.building.building_name,
'room':self.room_num,
'slug':self.slug, 'slug':self.slug,
'floor':self.floor.slug,
'building':self.floor.building.slug,
}) })
def __str__(self): # __unicode__ on Python 2 def __str__(self): # __unicode__ on Python 2
......
...@@ -14,7 +14,7 @@ urlpatterns = patterns('', ...@@ -14,7 +14,7 @@ urlpatterns = patterns('',
template_name='list_buildings.html'), template_name='list_buildings.html'),
name='list_buildings'), name='list_buildings'),
url(r'^(?P<slug>[\w-]+)/$', url(r'^(?P<slug>[\w-]+)/(?P<building>[\w-]+)/$',
DetailBuilding.as_view( DetailBuilding.as_view(
model=Building, model=Building,
slug_field='slug__iexact', slug_field='slug__iexact',
...@@ -22,14 +22,14 @@ urlpatterns = patterns('', ...@@ -22,14 +22,14 @@ urlpatterns = patterns('',
template_name='detail_building.html'), template_name='detail_building.html'),
name='detail_building'), name='detail_building'),
url(r'^(?P<building>[\w-]+)/(?P<slug>[\w-]+)/$', url(r'^(?P<slug>[\w-]+)/(?P<building>[\w-]+)/(?P<floor>[\w-]+)/$',
DetailFloor.as_view( DetailFloor.as_view(
model=Floor, model=Floor,
context_object_name='floor', context_object_name='floor',
template_name='detail_floor.html'), template_name='detail_floor.html'),
name='detail_floor'), name='detail_floor'),
url(r'^(?P<building>[\w-]+)/(?P<floor>[\w-]+)/(?P<slug>[\w-]+)/$', url(r'^(?P<slug>[\w-]+)/(?P<building>[\w-]+)/(?P<floor>[\w-]+)/(?P<room>[\w-]+)/$',
DetailRoom.as_view( DetailRoom.as_view(
model=Room, model=Room,
context_object_name='room', context_object_name='room',
......
...@@ -74,6 +74,7 @@ INSTALLED_APPS = ( ...@@ -74,6 +74,7 @@ INSTALLED_APPS = (
'crispy_forms', 'crispy_forms',
'django_gravatar', 'django_gravatar',
'analytical', 'analytical',
'randomslugfield',
'allauth', 'allauth',
'allauth.account', 'allauth.account',
'allauth.socialaccount', 'allauth.socialaccount',
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
<div id="navbar" class="navbar-collapse collapse"> <div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav"> <ul class="nav navbar-nav">
{% if user.is_authenticated %} {% if user.is_authenticated %}
<li><a href="/housing/buildings">Buildings</a> <li><a href="/housing">Buildings</a>
</li> </li>
{% else %} {% else %}
<li><a href="{% url 'about' %}">About</a> <li><a href="{% url 'about' %}">About</a>
......
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