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