Commit 0ad576c5 authored by Daniel W Bond's avatar Daniel W Bond

PEP8 compliance

parent 516e8072
# standard library imports
from datetime import datetime, timedelta
# core django imports
from django.conf import settings
# core django imports
from django.shortcuts import resolve_url
# third party imports
from allauth.account.adapter import DefaultAccountAdapter
......@@ -10,10 +9,10 @@ from allauth.account.adapter import DefaultAccountAdapter
class AccountAdapter(DefaultAccountAdapter):
def get_login_redirect_url(self, request):
threshold = 90 #seconds
threshold = 90 # seconds
assert request.user.is_authenticated()
if (request.user.last_login - request.user.date_joined).seconds < threshold:
if ((request.user.last_login - request.user.date_joined).seconds < threshold):
url = '/accounts/student/'
else:
url = '/accounts/student/'
......
......@@ -20,6 +20,7 @@ def pfinfo(uname):
name = pfjson['results'][0]['name']
return name.split(',')
def create_user(tree):
username = tree[0][0].text
......
......@@ -2,13 +2,14 @@
from django import forms
# third party imports
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Submit, Layout, Field, HTML
from crispy_forms.bootstrap import PrependedText, AppendedText, FormActions
from crispy_forms.layout import Submit, Layout
from crispy_forms.bootstrap import PrependedText, AppendedText
# imports from your apps
from .models import Student
# form to create student
class StudentForm( forms.ModelForm ):
class StudentForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
......@@ -28,7 +29,7 @@ class StudentForm( forms.ModelForm ):
model = Student
class UserSettingsForm( forms.ModelForm ):
class UserSettingsForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
......
......@@ -9,21 +9,23 @@ from django.core.urlresolvers import reverse
from autoslug import AutoSlugField
from allauth.socialaccount.models import SocialAccount
# imports from your apps
from housing.models import Building, Room, Class
from housing.models import Room, Class
class Major(TimeStampedModel):
name = models.CharField(max_length = 50)
name = models.CharField(max_length=50)
# I believe the longest is "Government and International Politics"
def __str__(self):
return self.name
def __unicode__(self):
return unicode(self.name)
class Meta:
ordering = ['name']
class StudentQuerySet(models.query.QuerySet):
def floor(self):
return self.filter(privacy='floor')
......@@ -47,11 +49,11 @@ class StudentQuerySet(models.query.QuerySet):
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
......@@ -70,10 +72,11 @@ class StudentManager(models.Manager):
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
......@@ -118,19 +121,19 @@ class Student(TimeStampedModel):
fb_uid = SocialAccount.objects.filter(user=self.user.id, provider='facebook')
print("profile_image")
if len(fb_uid)>0:
if len(fb_uid) > 0:
return "http://graph.facebook.com/{}/picture?width=175&height=175".format(fb_uid[0].uid)
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})
return reverse('detail_student', kwargs={'slug': self.slug})
class Meta:
ordering = ['user']
def __str__(self): # __unicode__ on Python 2
return self.user.username
def __unicode__(self):
return unicode(self.user.username)
# standard libary imports
import datetime
# third party imports
from haystack import indexes
# imports from your apps
......@@ -15,11 +13,11 @@ class StudentIndex(indexes.SearchIndex, indexes.Indexable):
# with the fields that we want to display when returning results
# search filtering
user = indexes.CharField( model_attr = 'user' )
user = indexes.CharField(model_attr='user')
def get_model(self):
return Student
def index_queryset(self, using=None):
"""When the entire index for model is updated."""
return self.get_model().objects.all()
return self.get_model().objects.all()
......@@ -2,7 +2,7 @@
from django.conf.urls import patterns, include, url
# imports from your apps
from .views import DetailStudent, UpdateStudent, DetailStudentSettings,\
DetailCurrentStudent, DetailCurrentStudentSettings, UpdateStudentMajor
DetailCurrentStudent, DetailCurrentStudentSettings, UpdateStudentMajor
urlpatterns = patterns('',
......
# core django imports
from django.shortcuts import render, get_object_or_404
from django.shortcuts import get_object_or_404
from django.http import HttpResponseForbidden
from django.views.generic import DetailView, ListView, UpdateView, UpdateView, DeleteView
from django.views.generic import DetailView, UpdateView
# third party imports
from braces.views import LoginRequiredMixin
# imports from your apps
......@@ -11,7 +11,7 @@ from .models import Student
# update a student (students are *created* on first login via CAS)
class UpdateStudent(LoginRequiredMixin, UpdateView):
model = Student
fields = ['room', 'privacy',]
fields = ['room', 'privacy', ]
context_object_name = 'student'
template_name = 'updateStudent.html'
......@@ -30,9 +30,10 @@ class UpdateStudent(LoginRequiredMixin, UpdateView):
else:
return super(UpdateStudent, self).get(request, *args, **kwargs)
class UpdateStudentMajor(LoginRequiredMixin, UpdateView):
models = Student
fields = ['major',]
fields = ['major', ]
template_name = 'updateStudentMajor.html'
login_url = 'login'
......@@ -41,6 +42,7 @@ class UpdateStudentMajor(LoginRequiredMixin, UpdateView):
# def get_object(self):
# return get_object_or_404(Student, pk=self.request.session['_auth_user_id'])
# details about the student
class DetailStudent(LoginRequiredMixin, DetailView):
model = Student
......@@ -73,17 +75,19 @@ class DetailStudent(LoginRequiredMixin, DetailView):
# 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
# 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
class DetailCurrentStudent(LoginRequiredMixin, DetailView):
model = Student
context_object_name = 'student'
......@@ -94,6 +98,7 @@ class DetailCurrentStudent(LoginRequiredMixin, DetailView):
def get_object(self):
return get_object_or_404(Student, pk=self.request.session['_auth_user_id'])
# changeable student settings
class DetailStudentSettings(LoginRequiredMixin, DetailView):
model = Student
......@@ -102,6 +107,7 @@ class DetailStudentSettings(LoginRequiredMixin, DetailView):
login_url = 'login'
class DetailCurrentStudentSettings(LoginRequiredMixin, DetailView):
model = Student
context_object_name = 'student'
......
# core django imports
from django.http import HttpResponse
# third party imports
import json
# imports from your apps
from housing.models import Building, Room
# Create your views here.
def index(request):
return HttpResponse("Hello, world. You're at the RoomList index.")
def buildings_list(request):
building_list = Building.objects.order_by('name')[:5]
jsons = '{"buildings":['
......@@ -16,6 +18,7 @@ def buildings_list(request):
jsons = jsons[:-1]+']}'
return HttpResponse(jsons)
def building(request, buildingName):
room_list = Room.objects.filter(building__name=''+buildingName).order_by('number')
jsons = 'Building does not exist'
......@@ -34,6 +37,7 @@ def building(request, buildingName):
jsons = jsons[:-1] + ']}'
return HttpResponse(jsons)
def room(request, building, room_number):
room_obj = Room.objects.filter(building__name=''+building, number=room_number)
......@@ -52,6 +56,7 @@ def room(request, building, room_number):
jsons += ']}'
return HttpResponse(jsons)
###################JASON trying to JSON in python, so confuzed:
# if room_obj:
# jsons = {'building':building, 'number':room_number, 'residents': []}
......@@ -65,6 +70,7 @@ def room(request, building, room_number):
# jsons.residents[3] = 'bedD':p.bedD.__str__()
# return HttpResponse(json.dumps(jsons))
def neighbourhood(request, nhood):
building_list = Building.objects.filter(neighbourhood=''+nhood).order_by('name')
jsons = 'That neighbourhood has no buildings or does not exist'
......
......@@ -22,8 +22,9 @@ class Building(TimeStampedModel):
)
neighbourhood = models.CharField(max_length=100, choices=NEIGHBOURHOOD_CHOICES,
default=NONE)
#address = models.ForeignKey('Address')
default=NONE)
# address = models.ForeignKey('Address')
PRINCE_WILLIAM = 'pw'
MASONVALE = 'mv'
......@@ -42,77 +43,80 @@ class Building(TimeStampedModel):
def get_absolute_url(self):
return reverse('detail_building', kwargs={
'building':self.building_name,
'slug':self.slug,
'building': self.building_name,
'slug': self.slug,
})
def __str__(self): # __unicode__ on Python 2
def __str__(self): # __unicode__ on Python 2
return self.name
def __unicode__(self): # __unicode__ on Python 2
def __unicode__(self): # __unicode__ on Python 2
return unicode(self.name)
class Meta:
ordering = ['name']
class Floor(TimeStampedModel):
building = models.ForeignKey('Building')
number = models.IntegerField()
slug = RandomSlugField(length=6)
floor_num = AutoSlugField(populate_from='number',# unique_with='building')
)
floor_num = AutoSlugField(populate_from='number',) # unique_with='building')
def get_absolute_url(self):
return reverse('detail_floor', kwargs={
'building':self.building.building_name,
'floor':self.floor_num,
'slug':self.slug,
'building': self.building.building_name,
'floor': self.floor_num,
'slug': self.slug,
})
def __str__(self): # __unicode__ on Python 2
def __str__(self): # __unicode__ on Python 2
return self.building.__str__()+" "+self.number.__str__()
class Meta:
ordering = ['building', 'number']
class Room(TimeStampedModel):
number = models.IntegerField()
floor = models.ForeignKey('Floor')
slug = RandomSlugField(length=6)
room_num = AutoSlugField(populate_from='number',# unique_with='floor')
)
room_num = AutoSlugField(populate_from='number',) # unique_with='floor')
def get_absolute_url(self):
return reverse('detail_room', kwargs={
'floor':self.floor.floor_num,
'building':self.floor.building.building_name,
'room':self.room_num,
'slug':self.slug,
'floor': self.floor.floor_num,
'building': self.floor.building.building_name,
'room': self.room_num,
'slug': self.slug,
})
def __str__(self): # __unicode__ on Python 2
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):
# street = models.CharField(max_length=120)
# city = models.CharField(max_length=120)
# state = USStateField()
# zip_code = models.IntegerField(max_length=5)
# class Meta:
# class Meta:
# verbose_name_plural = 'addresses'
# def __str__(self): # __unicode__ on Python 2
# return self.street
class Class(TimeStampedModel):
grad_year = models.PositiveIntegerField()
FRESHMAN = 'FR'
......@@ -130,7 +134,8 @@ class Class(TimeStampedModel):
year_in_school = models.CharField(max_length=2,
choices=YEAR_IN_SCHOOL_CHOICES,
default=FRESHMAN)
class Meta:
class Meta:
verbose_name_plural = 'classes'
def __str__(self): # __unicode__ on Python 2
......
# standard library imports
import io
import string
import random
import re
# from stackoverflow https://stackoverflow.com/questions/2257441/
def slug_generator(size=6, chars=string.ascii_letters + string.digits):
return ''.join(random.choice(chars) for _ in range(size))
# regex to separate out building names and room numbers
def building_or_room(line):
return False
def get_floor_num(line):
return line[0]
......@@ -28,7 +29,7 @@ curFloorInBuilding = 1
for line in roomNumbers:
line = line.rstrip('\n')
if re.match('[a-zA-Z]',line):
if re.match('[a-zA-Z]', line):
curFloor += 1
curFloorInBuilding = 1
else:
......
# core django imports
from django.conf.urls import patterns, include, url
from django.conf.urls import patterns, url
# imports from your apps
from .views import ListBuildings, DetailBuilding, DetailFloor, DetailRoom
from .models import Building, Floor, Room
urlpatterns = patterns('',
......
# core django imports
from django.views.generic import DetailView, ListView, CreateView, UpdateView,\
DeleteView
from django.views.generic import DetailView, ListView
# third party imports
from braces.views import LoginRequiredMixin
# imports from your apps
# imports from your apps
from .models import Building, Floor, Room
from accounts.models import Student
......@@ -12,7 +11,7 @@ from accounts.models import Student
class ListBuildings(LoginRequiredMixin, ListView):
model = Building
queryset = Building.objects.all()
# paginate_by =
# paginate_by
context_object_name = 'buildings'
template_name = 'list_buildings.html'
......@@ -25,12 +24,13 @@ class ListBuildings(LoginRequiredMixin, ListView):
context['aquia'] = Building.objects.filter(neighbourhood='aq').order_by('name')
return context
# building floors, other information
class DetailBuilding(LoginRequiredMixin, DetailView):
model = Building
slug_field = 'slug__iexact'
context_object_name = 'building'
template_name='detail_building.html'
template_name = 'detail_building.html'
login_url = 'login'
......@@ -39,16 +39,17 @@ class DetailBuilding(LoginRequiredMixin, DetailView):
context['floors'] = Floor.objects.filter(building__name=''+self.get_object().name).order_by('number')
return context
# this lists the rooms on the floor
class DetailFloor(LoginRequiredMixin, DetailView):
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 = Student.objects.get(user=self.request.user)
requesting_student_filter = Student.objects.filter(user=self.request.user)
requesting_student = requesting_student_filter[0]
......@@ -81,15 +82,16 @@ class DetailFloor(LoginRequiredMixin, DetailView):
context['notInBuilding'] = not inBuilding()
return context
class DetailRoom(LoginRequiredMixin, DetailView):
model = Room
context_object_name = 'room'
template_name='detail_room.html'
template_name = 'detail_room.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 = Student.objects.get(user=self.request.user)
requesting_student_filter = Student.objects.filter(user=self.request.user)
requesting_student = requesting_student_filter[0]
......@@ -108,11 +110,11 @@ class DetailRoom(LoginRequiredMixin, DetailView):
return building_status
if onFloor():
students = Student.objects.filter(room=self.get_object()).floor_building_students()
students = Student.objects.filter(room=self.get_object()).floor_building_students()
elif inBuilding():
students = Student.objects.filter(room=self.get_object()).building_students()
students = Student.objects.filter(room=self.get_object()).building_students()
else:
students = Student.objects.filter(room=self.get_object()).students()
students = Student.objects.filter(room=self.get_object()).students()
context['students'] = students
context['notOnFloor'] = not onFloor()
......@@ -122,4 +124,5 @@ class DetailRoom(LoginRequiredMixin, DetailView):
login_url = '/'
# deleted 'UpdateRoom' view-- that will be handled on the user's page
......@@ -14,7 +14,7 @@ handle500 = TemplateView.as_view(template_name="500.html")
urlpatterns = patterns('',
# project-level urls
url(r'^$', TemplateView.as_view( template_name="index.html" ), name='index'),
url(r'^$', TemplateView.as_view(template_name="index.html"), name='index'),
url(r'^about/$', TemplateView.as_view(template_name='about.html'), name='about'),
url(r'^privacy/$', TemplateView.as_view(template_name='privacy.html'), name='privacy'),
......@@ -26,8 +26,8 @@ urlpatterns = patterns('',
url(r'^search/', include('haystack.urls'), name='search'),
# login and logout
#url(r'^login/', 'cas.views.login', name='login'),
#url(r'^logout/', 'cas.views.logout', name='logout'),
# url(r'^login/', 'cas.views.login', name='login'),
# url(r'^logout/', 'cas.views.logout', name='logout'),
url(r'^login/$', 'django.contrib.auth.views.login', name='login'),
url(r'^logout/$', 'django.contrib.auth.views.logout', name='logout'),
......
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