Commit 857536ee authored by Daniel W Bond's avatar Daniel W Bond
Browse files

this'll slow page retrieval down by a fraction of a second, but it removes the...

this'll slow page retrieval down by a fraction of a second, but it removes the slugs from the urls, making things more obvious... slugs are left in the model because these exiting changes don't require migrations
parent fcd20dbb
......@@ -11,7 +11,7 @@ from autoslug import AutoSlugField
class Building(TimeStampedModel):
name = models.CharField(max_length=100)
name = models.CharField(max_length=100, unique=True)
NONE = 'na'
AQUIA = 'aq'
......@@ -47,7 +47,6 @@ class Building(TimeStampedModel):
def get_absolute_url(self):
return reverse('detail_building', kwargs={
'building': slugify(self.building_name),
'slug': self.slug,
})
def __str__(self): # __unicode__ on Python 2
......@@ -92,7 +91,6 @@ class Floor(TimeStampedModel):
return reverse('detail_floor', kwargs={
'building': slugify(self.building.building_name),
'floor': self.floor_num,
'slug': self.slug,
})
def __str__(self): # __unicode__ on Python 2
......@@ -115,6 +113,7 @@ class Floor(TimeStampedModel):
class Meta:
ordering = ['building', 'number']
unique_together = ('number', 'building')
class Room(TimeStampedModel):
......@@ -130,7 +129,6 @@ class Room(TimeStampedModel):
'floor': self.floor.floor_num,
'building': slugify(self.floor.building.building_name),
'room': self.room_num,
'slug': self.slug,
})
def __str__(self): # __unicode__ on Python 2
......@@ -147,3 +145,4 @@ class Room(TimeStampedModel):
class Meta:
ordering = ['number']
unique_together = ('number', 'floor',)
......@@ -10,13 +10,13 @@ urlpatterns = patterns('',
url(r'^$', ListBuildings.as_view(), name='list_buildings'),
url(r'^(?P<slug>[\w-]+)/(?P<building>[\w-]+)/$',
url(r'^(?P<building>[\w-]+)/$',
DetailBuilding.as_view(), name='detail_building'),
url(r'^(?P<slug>[\w-]+)/(?P<building>[\w-]+)/(?P<floor>[\w-]+)/$',
url(r'^(?P<building>[\w-]+)/(?P<floor>[\w-]+)/$',
DetailFloor.as_view(), name='detail_floor'),
url(r'^(?P<slug>[\w-]+)/(?P<building>[\w-]+)/(?P<floor>[\w-]+)/(?P<room>[\w-]+)/$',
url(r'^(?P<building>[\w-]+)/(?P<floor>[\w-]+)/(?P<room>[\w-]+)/$',
DetailRoom.as_view(), name='detail_room'),
)
......@@ -36,6 +36,13 @@ class DetailBuilding(LoginRequiredMixin, DetailView):
login_url = 'login'
def get_object(self):
url_parts = self.request.get_full_path().split('/')
# [u'', u'housing', u'building',]
building_name = url_parts[2].replace('-', ' ').title()
building = Building.objects.get(name=building_name)
return building
def get_context_data(self, **kwargs):
context = super(DetailBuilding, self).get_context_data(**kwargs)
context['floors'] = Floor.objects.filter(building=self.get_object()).order_by('number')
......@@ -48,6 +55,16 @@ class DetailFloor(LoginRequiredMixin, DetailView):
context_object_name = 'floor'
template_name = 'detail_floor.html'
def get_object(self):
url_parts = self.request.get_full_path().split('/')
# [u'', u'housing', u'building', u'floor', ]
building_name = url_parts[2].replace('-', ' ').title()
floor_number = int(url_parts[3])
building = Building.objects.get(name=building_name)
floor = Floor.objects.get(number=floor_number,
building=building)
return floor
def get_context_data(self, **kwargs):
context = super(DetailFloor, self).get_context_data(**kwargs)
......@@ -64,6 +81,19 @@ class DetailRoom(LoginRequiredMixin, DetailView):
context_object_name = 'room'
template_name = 'detail_room.html'
def get_object(self):
url_parts = self.request.get_full_path().split('/')
# [u'', u'housing', u'building', u'floor', u'room', ]
building_name = url_parts[2].replace('-', ' ').title()
floor_number = int(url_parts[3])
room_number = int(url_parts[4])
building = Building.objects.get(name=building_name)
floor = Floor.objects.get(number=floor_number,
building=building)
room = Room.objects.get(floor=floor,
number=room_number)
return room
def get_context_data(self, **kwargs):
context = super(DetailRoom, self).get_context_data(**kwargs)
......
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