Commit d3624748 authored by Jason D Yeomans's avatar Jason D Yeomans
Browse files

Merge branch 'privacy' into 'master'

Privacy

See merge request !1
parents 44ac6dff 04cc1bcd
...@@ -45,3 +45,6 @@ docs/_build/ ...@@ -45,3 +45,6 @@ docs/_build/
target/ target/
# Vim files # Vim files
*.sw* *.sw*
# config, secret settings
config.py
secret.py
...@@ -9,23 +9,97 @@ from housing.models import Building, Room, Class ...@@ -9,23 +9,97 @@ from housing.models import Building, Room, Class
from allauth.socialaccount.models import SocialAccount from allauth.socialaccount.models import SocialAccount
import hashlib import hashlib
# Create your models here.
class Major(TimeStampedModel): class Major(TimeStampedModel):
name = models.CharField(max_length = 50) name = models.CharField(max_length = 50)
# I believe the longest is "Government and International Politics" # I believe the longest is "Government and International Politics"
def __str__(self):
return self.name
class StudentQuerySet(models.query.QuerySet):
def floor(self):
return self.filter(privacy='floor')
def building(self):
return self.filter(privacy='building')
def students(self):
return self.filter(privacy='students')
# when a student is not on a floor, but in a building
def building_students(self):
building = self.building()
students = self.students()
return list(building) + list(set(students) - set(building))
# when a student is on a floor
def floor_building_students(self):
floor = self.floor()
building = self.building()
students = self.students()
# using the function above results in UnboundLocalError excpetion
#building_students = building_students()
building_students = list(building) + list(set(students) - set(building))
return list(floor) + list(set(building_students) - set(floor))
class StudentManager(models.Manager):
# this 'duplication' allows for queryset chaining
def get_queryset(self):
return StudentQuerySet(self.model, using=self._db)
def floor(self):
return self.get_queryset().floor()
def building(self):
return self.get_queryset().building()
def students(self):
return self.get_queryset().students()
def building_students(self):
return self.get_queryset().building_students()
def floor_building_students(self):
return self.get_queryset().floor_building_students()
class Student(TimeStampedModel): class Student(TimeStampedModel):
user = models.OneToOneField(User) user = models.OneToOneField(User)
# Django user includes a username, password, email, first name, and last name # Django user includes a username, password, email, first name, and last name
FLOOR = 'floor'
BUILDING = 'building'
STUDENTS = 'students'
PRIVACY_CHOICES = (
(FLOOR, 'My Floor'),
(BUILDING, 'My Building'),
(STUDENTS, 'All Students'),
)
privacy = models.CharField(max_length=100, choices=PRIVACY_CHOICES, default=FLOOR)
room = models.OneToOneField(Room) room = models.OneToOneField(Room)
clas = models.OneToOneField(Class) clas = models.OneToOneField(Class)
major = models.OneToOneField(Major) major = models.OneToOneField(Major)
# major = models.
# social media accounts # social media accounts
slug = AutoSlugField(populate_from='user', unique=True) slug = AutoSlugField(populate_from='user', unique=True)
objects = StudentManager()
def get_floor(self):
floor = self.room.floor
return floor
def get_building(self):
building = self.room.floor.building
return building
def profile_image_url(self): def profile_image_url(self):
fb_uid = SocialAccount.objects.filter(user=self.user.id, provider='facebook') fb_uid = SocialAccount.objects.filter(user=self.user.id, provider='facebook')
print("profile_image") print("profile_image")
......
from django.contrib import admin from django.contrib import admin
from housing.models import Class, Building, Room from housing.models import Class, Building, Floor, Room
# Register your models here. # Register your models here.
admin.site.register(Class) admin.site.register(Class)
admin.site.register(Building) admin.site.register(Building)
admin.site.register(Floor)
admin.site.register(Room) admin.site.register(Room)
...@@ -2,7 +2,7 @@ from django.db import models ...@@ -2,7 +2,7 @@ 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 localflavor.us.models import USStateField #from localflavor.us.models import USStateField
class Building(TimeStampedModel): class Building(TimeStampedModel):
name = models.CharField(max_length=100) name = models.CharField(max_length=100)
...@@ -28,7 +28,7 @@ class Building(TimeStampedModel): ...@@ -28,7 +28,7 @@ class Building(TimeStampedModel):
CAMPUS_CHOICES = ( CAMPUS_CHOICES = (
(NONE, 'None'), (NONE, 'None'),
(PRINCE_WILLIAM, 'Prince William'), (PRINCE_WILLIAM, 'Prince William'),
(MASONVALE, 'mv'), (MASONVALE, 'MasonVale'),
(FAIRFAX, 'Fairfax'), (FAIRFAX, 'Fairfax'),
) )
...@@ -41,16 +41,24 @@ class Building(TimeStampedModel): ...@@ -41,16 +41,24 @@ class Building(TimeStampedModel):
def __unicode__(self): # __unicode__ on Python 2 def __unicode__(self): # __unicode__ on Python 2
return unicode(self.name) return unicode(self.name)
class Room(TimeStampedModel): class Floor(TimeStampedModel):
number = models.IntegerField()
floor = models.IntegerField()
building = models.ForeignKey('Building') building = models.ForeignKey('Building')
number = models.IntegerField()
slug = AutoSlugField(populate_from='number', unique=True) slug = AutoSlugField(populate_from='number')
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 Room(TimeStampedModel):
number = models.IntegerField()
floor = models.ForeignKey('Floor')
slug = AutoSlugField(populate_from='number')
def __str__(self): # __unicode__ on Python 2
return self.floor.building.__str__()+" "+self.number.__str__()
# buildings on campus don't have separate addresses yet # buildings on campus don't have separate addresses yet
#class Address(TimeStampedModel): #class Address(TimeStampedModel):
......
...@@ -6,39 +6,17 @@ ...@@ -6,39 +6,17 @@
<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.name }}</p> <p class="lead"><strong>{{ building.name }}</strong></p>
</div> </div>
</div> </div>
</div> </div>
<ul style="list-style-type: none"> <div class="row">
{% for room in room_list %} {% for floor in floors %}
<li> <div class="col-sm-3 text-center">
{{ room.number }} <a href="#" class="btn btn-primary btn-lg btn-block">{{ floor.number }}</a>
</li> </div>
<li>
<ul>
<li>
{{ room.bedA }}
</li>
{% if room.bedB %}
<li>
{{ room.bedB }}
</li>
{% endif %}
{% if room.bedC %}
<li>
{{ room.bedC }}
</li>
{% endif %}
{% if room.bedD %}
<li>
{{ room.bedD }}
</li>
{% endif %}
</ul>
</li>
{% endfor %} {% endfor %}
</ul> </div>
{% endblock %} {% endblock %}
{% extends 'layouts/base.html' %}
{% block title %} SRCT RoomList &bull; {{ floor.building.name }} {{ floor.number }}{% endblock %}
{% block content %}
<div class="page-header" id="banner">
<div class="row">
<div class="col-lg-12 text-center">
<h1><strong>GMU</strong>ROOMLIST</h1>
<p class="lead"><strong>{{ floor.building.name }}{{ floor.number }}</strong></p>
</div>
</div>
</div>
<div class="row">
{% for student in students %}
{{ student }}
{% endfor %}
</div>
{% endblock %}
{% extends 'layouts/base.html' %}
{% block title %} SRCT RoomList &bull; {{ room.floor.building.name }} {{ room.number }}{% endblock %}
{% block content %}
<div class="page-header" id="banner">
<div class="row">
<div class="col-lg-12 text-center">
<h1><strong>GMU</strong>ROOMLIST</h1>
<p class="lead"><strong>{{ room.floor.building.name }}{{ room.number }}</strong></p>
</div>
</div>
</div>
<div class="row">
{% for student in students %}
{{ student }}
{% endfor %}
</div>
{% endblock %}
from django.conf.urls import patterns, include, url from django.conf.urls import patterns, include, url
from housing.views import ListBuildings, DetailBuilding, ListRooms, DetailRoom from housing.views import ListBuildings, DetailBuilding, DetailFloor, DetailRoom
from housing.models import Building, Room from housing.models import Building, Floor, Room
urlpatterns = patterns('', urlpatterns = patterns('',
...@@ -11,15 +11,28 @@ urlpatterns = patterns('', ...@@ -11,15 +11,28 @@ urlpatterns = patterns('',
#paginate_by='10', #paginate_by='10',
queryset=Building.objects.all(), queryset=Building.objects.all(),
context_object_name='buildings', context_object_name='buildings',
template_name='listBuildings.html'), template_name='list_buildings.html'),
name='listBuildings'), name='list_buildings'),
url(r'^buildings/(?P<slug>[\w-]+)/$', url(r'^buildings/(?P<slug>[\w-]+)/$',
DetailBuilding.as_view( DetailBuilding.as_view(
model=Building, model=Building,
slug_field='slug__iexact', slug_field='slug__iexact',
context_object_name='building', context_object_name='building',
template_name='detailBuilding.html'), template_name='detail_building.html'),
name='detailBuilding'), 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/whitetop/5/5542/$',
# DetailRoom.as_view(
# model=Room,
# context_object_name='room',
# template_name='detail_room.html'),
# name='detail_room'),
) )
from django.views.generic import DetailView, ListView, CreateView, UpdateView, DeleteView from django.views.generic import DetailView, ListView, CreateView, UpdateView, DeleteView
from housing.models import Building, Room from housing.models import Building, Floor, Room
from accounts.models import Student from accounts.models import Student
from braces.views import LoginRequiredMixin from braces.views import LoginRequiredMixin
...@@ -25,32 +25,87 @@ class DetailBuilding(LoginRequiredMixin, DetailView): ...@@ -25,32 +25,87 @@ class DetailBuilding(LoginRequiredMixin, DetailView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super(DetailBuilding, self).get_context_data(**kwargs) context = super(DetailBuilding, self).get_context_data(**kwargs)
context['room_list'] = Room.objects.filter(building__name=''+self.get_object().name).order_by('number') context['floors'] = Floor.objects.filter(building__name=''+self.get_object().name).order_by('number')
return context return context
login_url = '/' login_url = '/'
# this lists the rooms on the floor # this lists the rooms on the floor
class ListRooms(LoginRequiredMixin, ListView): class DetailFloor(LoginRequiredMixin, DetailView):
model = Room model = Floor
login_url = '/' context_object_name = 'floor'
template_name = 'detail_floor.html'
def get_context_data(self, **kwargs):
context = super(DetailFloor, 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]
# if self.request.user is on the floor
def onFloor():
floor_status = False
if requesting_student.get_floor() == self.get_object():
floor_status = True
return floor_status
# if self.request.user is in the building
def inBuilding():
building_status = False
if requesting_student.get_building() == self.get_object().building:
building_status = True
return building_status
rooms = Room.objects.filter(floor=self.get_object()).order_by('number')
floor_students = []
for room in rooms:
if onFloor():
floor_students.extend(Student.objects.filter(room=room).floor_building_students())
elif inBuilding():
floor_students.extend(Student.objects.filter(room=room).building_students())
else:
floor_students.extend(Student.objects.filter(room=room).students())
context['students'] = floor_students
return context
# this lists students in a room class DetailRoom(LoginRequiredMixin, DetailView):
class DetailRoom(LoginRequiredMixin, ListView):
model = Room model = Room
login_url = '/' context_object_name = 'room'
template_name='detailBuilding.html'
def get_context_data(self, **kwargs):
context = super(DetailRoom, 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]
# update a student # if self.request.user is on the floor
#class UpdateStudent(LoginRequiredMixin, UpdateView): def onFloor():
# model = Student floor_status = False
# form_class = '/' if requesting_student.get_floor == self.get_object().floor:
# success_url = '/' # change the success url to something more interesting floor_status = True
return floor_status
# login_url = '/' # if self.request.user is in the building
def inBuilding():
building_status = False
if requesting_student.get_building == self.get_object().get_building:
building_status = True
return building_status
# update a room if onFloor():
#class updateroom(loginrequiredmixin, updateview): students = Student.objects.filter(room=self.get_object()).floor_building_students()
# model = room elif inBuilding():
# form_class = students = Student.objects.filter(room=self.get_object()).building_students()
# success_url = '/' # change the success url to something more interesting else:
students = Student.objects.filter(room=self.get_object()).students()
context['students'] = students
return context
login_url = '/'
# login_url = '/' # deleted 'UpdateRoom' view-- that will be handled on the user's page
...@@ -62,9 +62,11 @@ INSTALLED_APPS = ( ...@@ -62,9 +62,11 @@ INSTALLED_APPS = (
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'django.contrib.sites', 'django.contrib.sites',
# apps
'api', 'api',
'housing', 'housing',
'accounts', 'accounts',
# packages
'crispy_forms', 'crispy_forms',
'django_gravatar', 'django_gravatar',
'allauth', 'allauth',
...@@ -124,6 +126,9 @@ USE_L10N = True ...@@ -124,6 +126,9 @@ USE_L10N = True
USE_TZ = True USE_TZ = True
# set for social auth
#SITE_ID =
# Static files (CSS, JavaScript, Images) # Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.7/howto/static-files/ # https://docs.djangoproject.com/en/1.7/howto/static-files/
......
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