Commit c6d42c6b authored by Daniel W Bond's avatar Daniel W Bond
Browse files

added get_absolute_url

parent 3a6101df
...@@ -3,6 +3,7 @@ from model_utils.models import TimeStampedModel ...@@ -3,6 +3,7 @@ from model_utils.models import TimeStampedModel
from django.contrib.auth.models import User from django.contrib.auth.models import User
from autoslug import AutoSlugField from autoslug import AutoSlugField
from django.core.urlresolvers import reverse
from housing.models import Building, Room, Class from housing.models import Building, Room, Class
...@@ -110,5 +111,8 @@ class Student(TimeStampedModel): ...@@ -110,5 +111,8 @@ class Student(TimeStampedModel):
return "http://www.gravatar.com/avatar/{}?s=175".format(hashlib.md5(self.user.email).hexdigest()) return "http://www.gravatar.com/avatar/{}?s=175".format(hashlib.md5(self.user.email).hexdigest())
def get_absolute_url(self):
return reverse('detail_student', kwargs={'slug':self.slug})
def __str__(self): # __unicode__ on Python 2 def __str__(self): # __unicode__ on Python 2
return self.user.username return self.user.username
...@@ -9,8 +9,10 @@ ...@@ -9,8 +9,10 @@
</div> </div>
<div class="col-md-6 text-center"> <div class="col-md-6 text-center">
<h1><strong>{{ student.user.first_name }} {{ student.user.last_name }}</strong></h1> <h1><strong>{{ student.user.first_name }} {{ student.user.last_name }}</strong></h1>
<p class="lead"><strong>{{ student.room }}</strong></p> {% if shares %}
<p><em>shared with</em>: <span class="label label-default">campus</span></p> <p class="lead"><strong><a href="{{ student.room.get_absolute_url }}">{{ student.room }}</a></strong></p>
{% endif %}
<p><em>shares room with</em>: <span class="label label-default"><strong>{{ student.privacy }}</strong></span></p>
</div> </div>
</div> </div>
</div> </div>
...@@ -20,7 +22,7 @@ ...@@ -20,7 +22,7 @@
<table class="table table-hover text-center"> <table class="table table-hover text-center">
<tbody> <tbody>
<tr> <tr>
<td><h4><strong>Major</strong>: {{ student.major.major_name }}</h4></td> <td><h4><strong>Major</strong>: {{ student.major.name }}</h4></td>
</tr> </tr>
<tr> <tr>
......
...@@ -11,7 +11,7 @@ urlpatterns = patterns('', ...@@ -11,7 +11,7 @@ urlpatterns = patterns('',
model=Student, model=Student,
context_object_name='student', context_object_name='student',
template_name='detailStudent.html'), template_name='detailStudent.html'),
name='detailStudent'), name='detail_student'),
url(r'^student/$', url(r'^student/$',
DetailCurrentStudent.as_view( DetailCurrentStudent.as_view(
......
...@@ -17,13 +17,48 @@ class CreateStudent(LoginRequiredMixin, CreateView): ...@@ -17,13 +17,48 @@ class CreateStudent(LoginRequiredMixin, CreateView):
# details about the student # details about the student
class DetailStudent(LoginRequiredMixin, DetailView): class DetailStudent(LoginRequiredMixin, DetailView):
model = Student model = Student
login_url = '/accounts/login/'
def get_context_data(self, **kwargs):
context = super(DetailStudent, self).get_context_data(**kwargs)
# requesting_student = Student.objects.get(user=self.request.user)
requesting_student_filter = Student.objects.filter(user=self.request.user)
requesting_student = requesting_student_filter[0]
def onFloor():
floor_status = False
if requesting_student.get_floor() == self.get_object().get_floor():
floor_status = True
return floor_status
def inBuilding():
floor_status = False
if requesting_student.get_building() == self.get_object().get_building():
floor_status = True
return floor_status
def shares():
student_shares = False
# if the student's privacy is floor and the requesting user is on their floor
if(self.get_object().privacy == 'floor') and onFloor():
student_shares = True
# if the student's privacy is building and the requesting users is on their floor or in their building
elif(self.get_object().privacy == 'building') and inBuilding():
student_shares = True
# if the student's privacy is set to 'student'
elif(self.get_object().privacy == 'students'):
student_shares = True
return student_shares
context['shares'] = shares()
return context
login_url = '/'
# changeable student settings # changeable student settings
class DetailStudentSettings(LoginRequiredMixin, DetailView): class DetailStudentSettings(LoginRequiredMixin, DetailView):
model = Student model = Student
login_url = '/accounts/login/' login_url = '/'
class DetailCurrentStudent(LoginRequiredMixin, DetailView): class DetailCurrentStudent(LoginRequiredMixin, DetailView):
......
...@@ -3,6 +3,7 @@ from autoslug import AutoSlugField ...@@ -3,6 +3,7 @@ from autoslug import AutoSlugField
from model_utils.models import TimeStampedModel from model_utils.models import TimeStampedModel
#from localflavor.us.models import USStateField #from localflavor.us.models import USStateField
from django.core.urlresolvers import reverse
class Building(TimeStampedModel): class Building(TimeStampedModel):
name = models.CharField(max_length=100) name = models.CharField(max_length=100)
...@@ -36,29 +37,54 @@ class Building(TimeStampedModel): ...@@ -36,29 +37,54 @@ class Building(TimeStampedModel):
slug = AutoSlugField(populate_from='name', unique=True) slug = AutoSlugField(populate_from='name', unique=True)
def get_absolute_url(self):
return reverse('detail_building', kwargs={'slug':self.slug})
def __str__(self): # __unicode__ on Python 2 def __str__(self): # __unicode__ on Python 2
return self.name return self.name
def __unicode__(self): # __unicode__ on Python 2 def __unicode__(self): # __unicode__ on Python 2
return unicode(self.name) return unicode(self.name)
class Meta:
ordering = ['name']
class Floor(TimeStampedModel): class Floor(TimeStampedModel):
building = models.ForeignKey('Building') building = models.ForeignKey('Building')
number = models.IntegerField() number = models.IntegerField()
slug = AutoSlugField(populate_from='number') slug = AutoSlugField(populate_from='number')
def get_absolute_url(self):
return reverse('detail_floor', kwargs={
'slug':self.slug,
'building':self.building.slug,
})
def __str__(self): # __unicode__ on Python 2 def __str__(self): # __unicode__ on Python 2
return self.building.__str__()+" "+self.number.__str__() return self.building.__str__()+" "+self.number.__str__()
class Meta:
ordering = ['number']
class Room(TimeStampedModel): class Room(TimeStampedModel):
number = models.IntegerField() number = models.IntegerField()
floor = models.ForeignKey('Floor') floor = models.ForeignKey('Floor')
slug = AutoSlugField(populate_from='number') slug = AutoSlugField(populate_from='number')
def get_absolute_url(self):
return reverse('detail_room', kwargs={
'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
return self.floor.building.__str__()+" "+self.number.__str__() return self.floor.building.__str__()+" "+self.number.__str__()
class Meta:
ordering = ['number']
# buildings on campus don't have separate addresses yet # buildings on campus don't have separate addresses yet
#class Address(TimeStampedModel): #class Address(TimeStampedModel):
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
<div class="row"> <div class="row">
{% for floor in floors %} {% for floor in floors %}
<div class="col-sm-3 text-center"> <div class="col-sm-3 text-center">
<a href="#" class="btn btn-primary btn-lg btn-block">{{ floor.number }}</a> <a href="{{ floor.get_absolute_url }}" class="btn btn-primary btn-lg btn-block">{{ floor.number }}</a>
</div> </div>
{% endfor %} {% endfor %}
</div> </div>
......
...@@ -20,9 +20,9 @@ ...@@ -20,9 +20,9 @@
{% for student in students %} {% for student in students %}
<div class="col-sm-3 text-center"> <div class="col-sm-3 text-center">
<img class="img-circle img-responsive center center-block" src="{% gravatar_url student.user.email 100 %}" alt="{{ student.user.first_name }} Gravatar picture"> <img class="img-circle img-responsive center center-block" src="{% gravatar_url student.user.email 100 %}" alt="{{ student.user.first_name }} Gravatar picture">
<h4><a href="#"><strong>{{ student.user.first_name }} {{ student.user.last_name }}</strong></a></h4> <h4><a href="{{ student.get_absolute_url }}"><strong>{{ student.user.first_name }} {{ student.user.last_name }}</strong></a></h4>
<h5><em>{{ student.major.name }}</em></h5> <h5><em>{{ student.major.name }}</em></h5>
<h5><a href="#">{{ student.room }}</a></h5> <h5><a href="{{ student.room.get_absolute_url }}">{{ student.room }}</a></h5>
</div> </div>
{% endfor %} {% endfor %}
</div> </div>
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
{% elif notInBuilding %} {% elif notInBuilding %}
You don't live in this building. Depending on individual privacy settings, not all students may be displayed. You don't live in this building. Depending on individual privacy settings, not all students may be displayed.
{% else %} {% else %}
Don't see someone you know who lives here? Tell about SRCT Roomlist! Don't see someone you know who lives here? Tell them about SRCT Roomlist!
{% endif %} {% endif %}
</em></strong></div> </em></strong></div>
</div> </div>
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
{% for student in students %} {% for student in students %}
<div class="col-sm-3 text-center"> <div class="col-sm-3 text-center">
<img class="img-circle img-responsive center center-block" src="{% gravatar_url student.user.email 100 %}" alt="{{ student.user.first_name }} Gravatar picture"> <img class="img-circle img-responsive center center-block" src="{% gravatar_url student.user.email 100 %}" alt="{{ student.user.first_name }} Gravatar picture">
<h4><a href="#"><strong>{{ student.user.first_name }} {{ student.user.last_name }}</strong></a></h4> <h4><a href="{{ student.get_absolute_url }}"><strong>{{ student.user.first_name }} {{ student.user.last_name }}</strong></a></h4>
<h5><em>{{ student.major.name }}</em></h5> <h5><em>{{ student.major.name }}</em></h5>
</div> </div>
{% endfor %} {% endfor %}
......
...@@ -8,29 +8,35 @@ SRCT RoomList &bull; Homepage ...@@ -8,29 +8,35 @@ SRCT RoomList &bull; Homepage
<div class="row"> <div class="row">
<div class="col-lg-12 text-center"> <div class="col-lg-12 text-center">
<h1><strong>GMU</strong>ROOMLIST</h1> <h1><strong>GMU</strong>ROOMLIST</h1>
<p class="lead">Building List</p> <p class="lead"><strong>Buildings</strong></p>
</div> </div>
</div> </div>
</div> </div>
<legend>Rappahannock</legend> <legend><strong>Rappahannock</strong></legend>
<ul> <div class="row">
{% for building in rappahannock %} {% for building in rappahannock %}
<li> <div class="col-sm-3 text-center">
<a href="/housing/buildings/{{ building.name }}">{{ building.name }}</a> - {{ building.address }} {{ building.address.zip_code }}, {{ building.address.state}} <a href="{{ building.get_absolute_url }}" class="btn btn-primary btn-lg btn-block">{{ building.name }}</a>
</li> </div>
{% endfor %} {% endfor %}
</ul> </div>
<legend>Shenandoah</legend> <br />
<ul> <legend><strong>Shenandoah</strong></legend>
<div class="row">
{% for building in shenandoah %} {% for building in shenandoah %}
<li> <div class="col-sm-3 text-center">
<a href="/housing/buildings/{{ building.name }}">{{ building.name }}</a> - {{ building.address }} {{ building.address.zip_code }}, {{ building.address.state}} <a href="{{ building.get_absolute_url }}" class="btn btn-primary btn-lg btn-block">{{ building.name }}</a>
</li> </div>
{% endfor %} {% endfor %}
</ul> </div>
<br />
<legend><strong>Aquia</strong></legend>
{% endblock %} {% endblock %}
...@@ -22,17 +22,17 @@ urlpatterns = patterns('', ...@@ -22,17 +22,17 @@ urlpatterns = patterns('',
template_name='detail_building.html'), template_name='detail_building.html'),
name='detail_building'), name='detail_building'),
# url(r'^buildings/whitetop/(?P<slug>[\w-]+)/$', url(r'^buildings/(?P<building>[\w-]+)/(?P<slug>[\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'^buildings/whitetop/5/5542/$', url(r'^buildings/(?P<building>[\w-]+)/(?P<floor>[\w-]+)/(?P<slug>[\w-]+)/$',
# DetailRoom.as_view( DetailRoom.as_view(
# model=Room, model=Room,
# context_object_name='room', context_object_name='room',
# template_name='detail_room.html'), template_name='detail_room.html'),
# name='detail_room'), name='detail_room'),
) )
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