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/
target/
# Vim files
*.sw*
# config, secret settings
config.py
secret.py
......@@ -9,23 +9,97 @@ from housing.models import Building, Room, Class
from allauth.socialaccount.models import SocialAccount
import hashlib
# Create your models here.
class Major(TimeStampedModel):
name = models.CharField(max_length = 50)
# 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):
user = models.OneToOneField(User)
# 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)
clas = models.OneToOneField(Class)
major = models.OneToOneField(Major)
# major = models.
# social media accounts
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):
fb_uid = SocialAccount.objects.filter(user=self.user.id, provider='facebook')
print("profile_image")
......
from django.contrib import admin
from housing.models import Class, Building, Room
from housing.models import Class, Building, Floor, Room
# Register your models here.
admin.site.register(Class)
admin.site.register(Building)
admin.site.register(Floor)
admin.site.register(Room)
......@@ -2,7 +2,7 @@ from django.db import models
from autoslug import AutoSlugField
from model_utils.models import TimeStampedModel
from localflavor.us.models import USStateField
#from localflavor.us.models import USStateField
class Building(TimeStampedModel):
name = models.CharField(max_length=100)
......@@ -28,7 +28,7 @@ class Building(TimeStampedModel):
CAMPUS_CHOICES = (
(NONE, 'None'),
(PRINCE_WILLIAM, 'Prince William'),
(MASONVALE, 'mv'),
(MASONVALE, 'MasonVale'),
(FAIRFAX, 'Fairfax'),
)
......@@ -41,16 +41,24 @@ class Building(TimeStampedModel):
def __unicode__(self): # __unicode__ on Python 2
return unicode(self.name)
class Room(TimeStampedModel):
number = models.IntegerField()
floor = models.IntegerField()
class Floor(TimeStampedModel):
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
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
#class Address(TimeStampedModel):
......
......@@ -6,39 +6,17 @@
<div class="row">
<div class="col-lg-12 text-center">
<h1><strong>GMU</strong>ROOMLIST</h1>
<p class="lead">{{ building.name }}</p>
<p class="lead"><strong>{{ building.name }}</strong></p>
</div>
</div>
</div>
<ul style="list-style-type: none">
{% for room in room_list %}
<li>
{{ room.number }}
</li>
<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>
<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>
</div>
{% endfor %}
</ul>
</div>
{% 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 housing.views import ListBuildings, DetailBuilding, ListRooms, DetailRoom
from housing.models import Building, Room
from housing.views import ListBuildings, DetailBuilding, DetailFloor, DetailRoom
from housing.models import Building, Floor, Room
urlpatterns = patterns('',
......@@ -11,15 +11,28 @@ urlpatterns = patterns('',
#paginate_by='10',
queryset=Building.objects.all(),
context_object_name='buildings',
template_name='listBuildings.html'),
name='listBuildings'),
template_name='list_buildings.html'),
name='list_buildings'),
url(r'^buildings/(?P<slug>[\w-]+)/$',
DetailBuilding.as_view(
model=Building,
slug_field='slug__iexact',
context_object_name='building',
template_name='detailBuilding.html'),
name='detailBuilding'),
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/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 housing.models import Building, Room
from housing.models import Building, Floor, Room
from accounts.models import Student
from braces.views import LoginRequiredMixin
......@@ -25,32 +25,87 @@ class DetailBuilding(LoginRequiredMixin, DetailView):
def get_context_data(self, **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
login_url = '/'
# this lists the rooms on the floor
class ListRooms(LoginRequiredMixin, ListView):
model = Room
login_url = '/'
class DetailFloor(LoginRequiredMixin, DetailView):
model = Floor
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, ListView):
class DetailRoom(LoginRequiredMixin, DetailView):
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
#class UpdateStudent(LoginRequiredMixin, UpdateView):
# model = Student
# form_class = '/'
# success_url = '/' # change the success url to something more interesting
# if self.request.user is on the floor
def onFloor():
floor_status = False
if requesting_student.get_floor == self.get_object().floor:
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
#class updateroom(loginrequiredmixin, updateview):
# model = room
# form_class =
# success_url = '/' # change the success url to something more interesting
if onFloor():
students = Student.objects.filter(room=self.get_object()).floor_building_students()
elif inBuilding():
students = Student.objects.filter(room=self.get_object()).building_students()
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 = (
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
# apps
'api',
'housing',
'accounts',
# packages
'crispy_forms',
'django_gravatar',
'allauth',
......@@ -124,6 +126,9 @@ USE_L10N = True
USE_TZ = True
# set for social auth
#SITE_ID =
# Static files (CSS, JavaScript, Images)
# 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