Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SRCT
roomlist
Commits
c6d42c6b
Commit
c6d42c6b
authored
Feb 21, 2015
by
Daniel W Bond
Browse files
added get_absolute_url
parent
3a6101df
Changes
10
Hide whitespace changes
Inline
Side-by-side
roomlist/accounts/models.py
View file @
c6d42c6b
...
...
@@ -3,6 +3,7 @@ from model_utils.models import TimeStampedModel
from
django.contrib.auth.models
import
User
from
autoslug
import
AutoSlugField
from
django.core.urlresolvers
import
reverse
from
housing.models
import
Building
,
Room
,
Class
...
...
@@ -110,5 +111,8 @@ class Student(TimeStampedModel):
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
return
self
.
user
.
username
roomlist/accounts/templates/detailStudent.html
View file @
c6d42c6b
...
...
@@ -9,8 +9,10 @@
</div>
<div
class=
"col-md-6 text-center"
>
<h1><strong>
{{ student.user.first_name }} {{ student.user.last_name }}
</strong></h1>
<p
class=
"lead"
><strong>
{{ student.room }}
</strong></p>
<p><em>
shared with
</em>
:
<span
class=
"label label-default"
>
campus
</span></p>
{% if shares %}
<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>
...
...
@@ -20,7 +22,7 @@
<table
class=
"table table-hover text-center"
>
<tbody>
<tr>
<td><h4><strong>
Major
</strong>
: {{ student.major.
major_
name }}
</h4></td>
<td><h4><strong>
Major
</strong>
: {{ student.major.name }}
</h4></td>
</tr>
<tr>
...
...
roomlist/accounts/urls.py
View file @
c6d42c6b
...
...
@@ -11,7 +11,7 @@ urlpatterns = patterns('',
model
=
Student
,
context_object_name
=
'student'
,
template_name
=
'detailStudent.html'
),
name
=
'detail
S
tudent'
),
name
=
'detail
_s
tudent'
),
url
(
r
'^student/$'
,
DetailCurrentStudent
.
as_view
(
...
...
roomlist/accounts/views.py
View file @
c6d42c6b
...
...
@@ -17,13 +17,48 @@ class CreateStudent(LoginRequiredMixin, CreateView):
# details about the student
class
DetailStudent
(
LoginRequiredMixin
,
DetailView
):
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
class
DetailStudentSettings
(
LoginRequiredMixin
,
DetailView
):
model
=
Student
login_url
=
'/accounts/login/'
login_url
=
'/'
class
DetailCurrentStudent
(
LoginRequiredMixin
,
DetailView
):
...
...
roomlist/housing/models.py
View file @
c6d42c6b
...
...
@@ -3,6 +3,7 @@ from autoslug import AutoSlugField
from
model_utils.models
import
TimeStampedModel
#from localflavor.us.models import USStateField
from
django.core.urlresolvers
import
reverse
class
Building
(
TimeStampedModel
):
name
=
models
.
CharField
(
max_length
=
100
)
...
...
@@ -36,10 +37,16 @@ class Building(TimeStampedModel):
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
return
self
.
name
def
__unicode__
(
self
):
# __unicode__ on Python 2
return
unicode
(
self
.
name
)
class
Meta
:
ordering
=
[
'name'
]
class
Floor
(
TimeStampedModel
):
building
=
models
.
ForeignKey
(
'Building'
)
...
...
@@ -47,18 +54,37 @@ class Floor(TimeStampedModel):
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
return
self
.
building
.
__str__
()
+
" "
+
self
.
number
.
__str__
()
class
Meta
:
ordering
=
[
'number'
]
class
Room
(
TimeStampedModel
):
number
=
models
.
IntegerField
()
floor
=
models
.
ForeignKey
(
'Floor'
)
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
return
self
.
floor
.
building
.
__str__
()
+
" "
+
self
.
number
.
__str__
()
class
Meta
:
ordering
=
[
'number'
]
# buildings on campus don't have separate addresses yet
#class Address(TimeStampedModel):
...
...
roomlist/housing/templates/detail_building.html
View file @
c6d42c6b
...
...
@@ -14,7 +14,7 @@
<div
class=
"row"
>
{% for floor in floors %}
<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>
{% endfor %}
</div>
...
...
roomlist/housing/templates/detail_floor.html
View file @
c6d42c6b
...
...
@@ -20,9 +20,9 @@
{% for student in students %}
<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"
>
<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><a
href=
"
#
"
>
{{ student.room }}
</a></h5>
<h5><a
href=
"
{{ student.room.get_absolute_url }}
"
>
{{ student.room }}
</a></h5>
</div>
{% endfor %}
</div>
...
...
@@ -37,7 +37,7 @@
{% elif notInBuilding %}
You don't live in this building. Depending on individual privacy settings, not all students may be displayed.
{% 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 %}
</em></strong></div>
</div>
...
...
roomlist/housing/templates/detail_room.html
View file @
c6d42c6b
...
...
@@ -17,7 +17,7 @@
{% for student in students %}
<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"
>
<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>
</div>
{% endfor %}
...
...
roomlist/housing/templates/list_buildings.html
View file @
c6d42c6b
...
...
@@ -8,29 +8,35 @@ SRCT RoomList • Homepage
<div
class=
"row"
>
<div
class=
"col-lg-12 text-center"
>
<h1><strong>
GMU
</strong>
ROOMLIST
</h1>
<p
class=
"lead"
>
Building List
</p>
<p
class=
"lead"
>
<strong>
Buildings
</strong>
</p>
</div>
</div>
</div>
<legend>
Rappahannock
</legend>
<legend>
<strong>
Rappahannock
</
strong></
legend>
<
ul
>
<
div
class=
"row"
>
{% for building in rappahannock %}
<
li
>
<a
href=
"
/housing/buildings/{{ building.name }}"
>
{{ building.name }}
</a>
- {{ building.address }} {{ building.address.zip_code }}, {{ building.address.state}}
</
li
>
<
div
class=
"col-sm-3 text-center"
>
<a
href=
"
{{ building.get_absolute_url }}"
class=
"btn btn-primary btn-lg btn-block"
>
{{ building.name }}
</a>
</
div
>
{% endfor %}
</
ul
>
</
div
>
<
legend>
Shenandoah
</legend
>
<
br
/
>
<ul>
<legend><strong>
Shenandoah
</strong></legend>
<div
class=
"row"
>
{% for building in shenandoah %}
<
li
>
<a
href=
"
/housing/buildings/{{ building.name }}"
>
{{ building.name }}
</a>
- {{ building.address }} {{ building.address.zip_code }}, {{ building.address.state}}
</
li
>
<
div
class=
"col-sm-3 text-center"
>
<a
href=
"
{{ building.get_absolute_url }}"
class=
"btn btn-primary btn-lg btn-block"
>
{{ building.name }}
</a>
</
div
>
{% endfor %}
</ul>
</div>
<br
/>
<legend><strong>
Aquia
</strong></legend>
{% endblock %}
roomlist/housing/urls.py
View file @
c6d42c6b
...
...
@@ -22,17 +22,17 @@ urlpatterns = patterns('',
template_name
=
'detail_building.html'
),
name
=
'detail_building'
),
#
url(r'^buildings/
whitetop
/(?P<slug>[\w-]+)/$',
#
DetailFloor.as_view(
#
model=Floor,
#
context_object_name='floor',
#
template_name='detail_floor.html'),
#
name='detail_floor'),
url
(
r
'^buildings/
(?P<building>[\w-]+)
/(?P<slug>[\w-]+)/$'
,
DetailFloor
.
as_view
(
model
=
Floor
,
context_object_name
=
'floor'
,
template_name
=
'detail_floor.html'
),
name
=
'detail_floor'
),
#
url(r'^buildings/
whitetop/5/5542
/$',
#
DetailRoom.as_view(
#
model=Room,
#
context_object_name='room',
#
template_name='detail_room.html'),
#
name='detail_room'),
url
(
r
'^buildings/
(?P<building>[\w-]+)/(?P<floor>[\w-]+)/(?P<slug>[\w-]+)
/$'
,
DetailRoom
.
as_view
(
model
=
Room
,
context_object_name
=
'room'
,
template_name
=
'detail_room.html'
),
name
=
'detail_room'
),
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment