Commit 518bc02b authored by Daniel W Bond's avatar Daniel W Bond
Browse files

began python3 transition: print_function and absolute_import added universally

parent 66af290f
# standard library imports # standard library imports
from __future__ import absolute_import, print_function
from datetime import datetime, timedelta from datetime import datetime, timedelta
# core django imports # core django imports
from django.shortcuts import resolve_url from django.shortcuts import resolve_url
......
# standard library imports
from __future__ import absolute_import, print_function
# core django imports # core django imports
from django.contrib import admin from django.contrib import admin
# imports from your apps # imports from your apps
......
# standard library imports
from __future__ import absolute_import, print_function
# core django imports # core django imports
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.core.exceptions import ObjectDoesNotExist from django.core.exceptions import ObjectDoesNotExist
...@@ -30,10 +32,10 @@ def pfinfo(uname): ...@@ -30,10 +32,10 @@ def pfinfo(uname):
url = base_url + "basic/all/" + str(uname) url = base_url + "basic/all/" + str(uname)
try: try:
metadata = requests.get(url) metadata = requests.get(url)
print "Retrieving information from the peoplefinder api." print("Retrieving information from the peoplefinder api.")
metadata.raise_for_status() metadata.raise_for_status()
except requests.exceptions.RequestException as e: except requests.exceptions.RequestException as e:
print "Cannot resolve to peoplefinder api:", e print("Cannot resolve to peoplefinder api:", e)
else: else:
pfjson = metadata.json() pfjson = metadata.json()
try: try:
...@@ -53,36 +55,36 @@ def pfinfo(uname): ...@@ -53,36 +55,36 @@ def pfinfo(uname):
return final_tuple return final_tuple
# if the name is not in peoplefinder, return empty first and last name # if the name is not in peoplefinder, return empty first and last name
except IndexError: except IndexError:
print "Name not found in peoplefinder." print("Name not found in peoplefinder.")
name = [u'', u''] name = [u'', u'']
major = u'' major = u''
final_tuple = (name, major) final_tuple = (name, major)
return final_tuple return final_tuple
# if there's no major, just return that as an empty string # if there's no major, just return that as an empty string
except KeyError: except KeyError:
print "Major not found in peoplefinder." print("Major not found in peoplefinder.")
final_tuple = (name, u'') final_tuple = (name, u'')
return final_tuple return final_tuple
except Exception as e: except Exception as e:
print "Unknown peoplefinder error:", e print("Unknown peoplefinder error:", e)
def create_user(tree): def create_user(tree):
print "Parsing CAS information." print("Parsing CAS information.")
try: try:
username = tree[0][0].text username = tree[0][0].text
user, user_created = User.objects.get_or_create(username=username) user, user_created = User.objects.get_or_create(username=username)
info_tuple = pfinfo(username) info_tuple = pfinfo(username)
if user_created: if user_created:
print "Created user object %s." % username print("Created user object %s." % username)
# set and save the user's email # set and save the user's email
email_str = "%s@%s" % (username, settings.ORGANIZATION_EMAIL_DOMAIN) email_str = "%s@%s" % (username, settings.ORGANIZATION_EMAIL_DOMAIN)
user.email = email_str user.email = email_str
user.save() user.save()
print "Added user's email, %s." % email_str print("Added user's email, %s." % email_str)
info_name = info_tuple[0] info_name = info_tuple[0]
# a list of empty strings is False # a list of empty strings is False
...@@ -90,39 +92,39 @@ def create_user(tree): ...@@ -90,39 +92,39 @@ def create_user(tree):
user.first_name = info_name[0] user.first_name = info_name[0]
user.last_name = info_name[1] user.last_name = info_name[1]
user.save() user.save()
print "Added user's name, %s %s." % (info_name[0], info_name[1]) print("Added user's name, %s %s." % (info_name[0], info_name[1]))
else: else:
print "Unable to add user's name." print("Unable to add user's name.")
print "User object creation process completed." print("User object creation process completed.")
else: else:
print "User object already exists." print("User object already exists.")
try: try:
Student.objects.get(user=user) Student.objects.get(user=user)
print "Student object already exists." print("Student object already exists.")
except ObjectDoesNotExist: except ObjectDoesNotExist:
new_student = Student.objects.create(user=user) new_student = Student.objects.create(user=user)
new_student.save() new_student.save()
print "Created student object." print("Created student object.")
major_name = info_tuple[1] major_name = info_tuple[1]
try: try:
major_obj = Major.objects.get(name__contains=major_name) major_obj = Major.objects.get(name__contains=major_name)
new_student.major = major_obj new_student.major = major_obj
new_student.save() new_student.save()
print "Added student's major, %s." % major_name print("Added student's major, %s." % major_name)
# ironically, 'Computer Science' returns a MultipleObjectsReturned exception # ironically, 'Computer Science' returns a MultipleObjectsReturned exception
# also Major.DoesNotExist Error, but the handling for both is the same... # also Major.DoesNotExist Error, but the handling for both is the same...
except: except:
print "Unable to add student's major." print("Unable to add student's major.")
print "Student object creation process completed." print("Student object creation process completed.")
print "CAS callback successful." print("CAS callback successful.")
# if all else fails... # if all else fails...
except Exception as e: except Exception as e:
print "CAS callback unsuccessful:", e print("CAS callback unsuccessful:", e)
# standard library imports
from __future__ import absolute_import, print_function
# core django imports # core django imports
from django import forms from django import forms
# third party imports # third party imports
......
# standard library imports # standard library imports
from __future__ import absolute_import, print_function
import re import re
import random import random
import string import string
...@@ -15,7 +16,7 @@ try: ...@@ -15,7 +16,7 @@ try:
page.raise_for_status() page.raise_for_status()
except requests.exceptions.RequestException as e: except requests.exceptions.RequestException as e:
print e print(e)
else: else:
programs = BeautifulSoup(page.content) programs = BeautifulSoup(page.content)
......
# standard library imports # standard library imports
from __future__ import absolute_import, print_function
import hashlib import hashlib
from datetime import date from datetime import date
# core django imports # core django imports
......
# standard library imports
from __future__ import absolute_import, print_function
# third party imports # third party imports
from haystack import indexes from haystack import indexes
# imports from your apps # imports from your apps
......
# standard library imports
from __future__ import absolute_import, print_function
# core django imports # core django imports
from django.test import TestCase from django.test import TestCase
......
# standard library imports
from __future__ import absolute_import, print_function
# core django imports # core django imports
from django.conf.urls import patterns, include, url from django.conf.urls import patterns, include, url
from django.views.decorators.cache import cache_page from django.views.decorators.cache import cache_page
# imports from your apps # imports from your apps
from .views import DetailStudent, UpdateStudent, DetailStudentSettings,\ from .views import (DetailStudent, UpdateStudent, DetailStudentSettings,
DetailCurrentStudent, DetailCurrentStudentSettings, ListMajors,\ DetailCurrentStudent, DetailCurrentStudentSettings, ListMajors,
DetailMajor, WelcomeName, WelcomePrivacy, WelcomeMajor, WelcomeSocial,\ DetailMajor, WelcomeName, WelcomePrivacy, WelcomeMajor,
CreateConfirmation, DeleteConfirmation WelcomeSocial, CreateConfirmation, DeleteConfirmation)
urlpatterns = patterns('', urlpatterns = patterns('',
......
# standard library imports
from __future__ import absolute_import, print_function
# core django imports # core django imports
from django.shortcuts import get_object_or_404 from django.shortcuts import get_object_or_404
from django.http import HttpResponseForbidden from django.http import HttpResponseForbidden
from django.views.generic import CreateView, ListView, DetailView, UpdateView, FormView, DeleteView from django.views.generic import (CreateView, ListView, DetailView, UpdateView,
FormView, DeleteView)
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.contrib import messages from django.contrib import messages
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
...@@ -69,17 +72,16 @@ def custom_cas_login(request, *args, **kwargs): ...@@ -69,17 +72,16 @@ def custom_cas_login(request, *args, **kwargs):
def on_the_same_floor(student, confirmer): def on_the_same_floor(student, confirmer):
if student == confirmer: if student == confirmer:
print "Student is confirmer" # Student is confirmer
return False return False
student_floor = student.get_floor() student_floor = student.get_floor()
confirmer_floor = confirmer.get_floor() confirmer_floor = confirmer.get_floor()
print student_floor, confirmer_floor
# room hasn't been set yet # room hasn't been set yet
if (student_floor is None) or (confirmer_floor is None): if (student_floor is None) or (confirmer_floor is None):
print "One student is None" # one Student is None
return False return False
elif not(student_floor == confirmer_floor): elif not(student_floor == confirmer_floor):
print "not the same floor" # not the same floor
return False return False
else: else:
return True return True
...@@ -110,8 +112,8 @@ class DetailStudent(LoginRequiredMixin, DetailView): ...@@ -110,8 +112,8 @@ class DetailStudent(LoginRequiredMixin, DetailView):
my_flag = Confirmation.objects.get(confirmer=requesting_student, my_flag = Confirmation.objects.get(confirmer=requesting_student,
student=self.get_object()) student=self.get_object())
except Exception as e: except Exception as e:
print "Students are not supposed to be able to make more than one flag per student." print("Students are not supposed to be able to make more than one flag per student.")
print e print(e)
def onFloor(): def onFloor():
floor_status = False floor_status = False
...@@ -189,8 +191,6 @@ class UpdateStudent(LoginRequiredMixin, FormView): ...@@ -189,8 +191,6 @@ class UpdateStudent(LoginRequiredMixin, FormView):
current_url = self.request.get_full_path() current_url = self.request.get_full_path()
url_uname = current_url.split('/')[3] url_uname = current_url.split('/')[3]
print url_uname, self.request.user.username
if not(url_uname == self.request.user.username): if not(url_uname == self.request.user.username):
return HttpResponseForbidden() return HttpResponseForbidden()
else: else:
...@@ -220,9 +220,6 @@ class UpdateStudent(LoginRequiredMixin, FormView): ...@@ -220,9 +220,6 @@ class UpdateStudent(LoginRequiredMixin, FormView):
def form_valid(self, form): def form_valid(self, form):
me = Student.objects.get(user=self.request.user) me = Student.objects.get(user=self.request.user)
print form.data['room']
print form.data['major']
me.user.first_name = form.data['first_name'] me.user.first_name = form.data['first_name']
me.user.last_name = form.data['last_name'] me.user.last_name = form.data['last_name']
me.gender = form.data.getlist('gender') me.gender = form.data.getlist('gender')
...@@ -252,8 +249,6 @@ class WelcomeName(LoginRequiredMixin, FormView): ...@@ -252,8 +249,6 @@ class WelcomeName(LoginRequiredMixin, FormView):
current_url = self.request.get_full_path() current_url = self.request.get_full_path()
url_uname = current_url.split('/')[3] url_uname = current_url.split('/')[3]
print url_uname, self.request.user.username
if not(url_uname == self.request.user.username): if not(url_uname == self.request.user.username):
return HttpResponseForbidden() return HttpResponseForbidden()
else: else:
...@@ -303,8 +298,6 @@ class WelcomePrivacy(LoginRequiredMixin, UpdateView): ...@@ -303,8 +298,6 @@ class WelcomePrivacy(LoginRequiredMixin, UpdateView):
current_url = self.request.get_full_path() current_url = self.request.get_full_path()
url_uname = current_url.split('/')[3] url_uname = current_url.split('/')[3]
print url_uname, self.request.user.username
if not(url_uname == self.request.user.username): if not(url_uname == self.request.user.username):
return HttpResponseForbidden() return HttpResponseForbidden()
else: else:
...@@ -336,8 +329,6 @@ class WelcomeMajor(LoginRequiredMixin, UpdateView): ...@@ -336,8 +329,6 @@ class WelcomeMajor(LoginRequiredMixin, UpdateView):
current_url = self.request.get_full_path() current_url = self.request.get_full_path()
url_uname = current_url.split('/')[3] url_uname = current_url.split('/')[3]
print url_uname, self.request.user.username
if not(url_uname == self.request.user.username): if not(url_uname == self.request.user.username):
return HttpResponseForbidden() return HttpResponseForbidden()
else: else:
...@@ -370,8 +361,6 @@ class WelcomeSocial(LoginRequiredMixin, DetailView): ...@@ -370,8 +361,6 @@ class WelcomeSocial(LoginRequiredMixin, DetailView):
current_url = self.request.get_full_path() current_url = self.request.get_full_path()
url_uname = current_url.split('/')[3] url_uname = current_url.split('/')[3]
print url_uname, self.request.user.username
if not(url_uname == self.request.user.username): if not(url_uname == self.request.user.username):
return HttpResponseForbidden() return HttpResponseForbidden()
else: else:
......
# standard library imports
from __future__ import absolute_import, print_function
# core django imports
from django.test import TestCase from django.test import TestCase
# Create your tests here. # Create your tests here.
# standard library imports
from __future__ import absolute_import, print_function
# core django imports # core django imports
from django.http import HttpResponse from django.http import HttpResponse
# third party imports # third party imports
......
# standard library imports
from __future__ import absolute_import, print_function
# core django imports # core django imports
from django.contrib import admin from django.contrib import admin
# imports from your apps # imports from your apps
......
# standard library imports
from __future__ import absolute_import, print_function
# core django imports # core django imports
from django.db import models from django.db import models
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
......
# standard library imports # standard library imports
from __future__ import absolute_import, print_function
import string import string
import random import random
import re import re
......
# standard library imports
from __future__ import absolute_import, print_function
# core django imports # core django imports
from django.test import TestCase from django.test import TestCase
......
# standard library imports
from __future__ import absolute_import, print_function
# core django imports # core django imports
from django.conf.urls import patterns, url from django.conf.urls import patterns, url
from django.views.decorators.cache import cache_page from django.views.decorators.cache import cache_page
......
# standard library imports
from __future__ import absolute_import, print_function
# core django imports # core django imports
from django.views.generic import DetailView, ListView from django.views.generic import DetailView, ListView
# third party imports # third party imports
......
...@@ -8,6 +8,8 @@ For the full list of settings and their values, see ...@@ -8,6 +8,8 @@ For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.7/ref/settings/ https://docs.djangoproject.com/en/1.7/ref/settings/
""" """
from __future__ import absolute_import, print_function
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__)) BASE_DIR = os.path.dirname(os.path.dirname(__file__))
...@@ -24,7 +26,7 @@ STATICFILES_DIRS = ( ...@@ -24,7 +26,7 @@ STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'), os.path.join(BASE_DIR, 'static'),
) )
print TEMPLATE_DIRS print(TEMPLATE_DIRS)
TEMPLATE_LOADERS = ( TEMPLATE_LOADERS = (
......
# standard library imports
from __future__ import absolute_import, print_function
# core django imports # core django imports
from django.conf.urls import patterns, include, url from django.conf.urls import patterns, include, url
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
......
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