Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
roomlist
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
23
Issues
23
List
Boards
Labels
Service Desk
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
SRCT
roomlist
Commits
bbfd284a
Commit
bbfd284a
authored
Oct 24, 2016
by
Daniel W Bond
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
removed helper functions from views and added them to a new library directory
parent
712c4534
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
101 additions
and
102 deletions
+101
-102
roomlist/accounts/views.py
roomlist/accounts/views.py
+0
-72
roomlist/housing/views.py
roomlist/housing/views.py
+0
-15
roomlist/lib/utils.py
roomlist/lib/utils.py
+101
-0
roomlist/welcome/views.py
roomlist/welcome/views.py
+0
-15
No files found.
roomlist/accounts/views.py
View file @
bbfd284a
...
...
@@ -29,78 +29,6 @@ from housing.models import Room
from
housing.views
import
shadowbanning
def
custom_cas_login
(
request
,
*
args
,
**
kwargs
):
"""If a student has not completed the welcome walkthrough, go there on login."""
response
=
cas_login
(
request
,
*
args
,
**
kwargs
)
# returns HttpResponseRedirect
if
request
.
user
.
is_authenticated
():
if
not
request
.
user
.
student
.
totally_done
():
if
not
request
.
user
.
student
.
completedName
:
return
HttpResponseRedirect
(
reverse
(
'welcomeName'
))
elif
not
request
.
user
.
student
.
completedPrivacy
:
return
HttpResponseRedirect
(
reverse
(
'welcomePrivacy'
))
elif
not
request
.
user
.
student
.
completedMajor
:
return
HttpResponseRedirect
(
reverse
(
'welcomeMajor'
))
elif
not
request
.
user
.
completedSocial
:
return
HttpResponseRedirect
(
reverse
(
'welcomeSocial'
))
else
:
welcome_back
=
random
.
choice
(
return_messages
)
messages
.
add_message
(
request
,
messages
.
INFO
,
mark_safe
(
welcome_back
))
return
response
# only two students on the same floor can confirm one another (crowdsourced verification)
def
on_the_same_floor
(
student
,
confirmer
):
if
student
==
confirmer
:
# Student is confirmer
return
False
student_floor
=
student
.
get_floor
()
confirmer_floor
=
confirmer
.
get_floor
()
# room hasn't been set yet
if
(
student_floor
is
None
)
or
(
confirmer_floor
is
None
):
# one Student is None
return
False
elif
not
(
student_floor
==
confirmer_floor
):
# not the same floor
return
False
else
:
return
True
def
pk_or_none
(
me
,
obj
):
if
obj
is
None
:
return
None
else
:
return
obj
.
pk
def
create_email
(
text_path
,
html_path
,
subject
,
to
,
context
):
text_email
=
get_template
(
text_path
)
html_email
=
get_template
(
html_path
)
email_context
=
Context
(
context
)
from_email
,
cc
=
(
'noreply@srct.gmu.edu'
,
''
)
text_content
=
text_email
.
render
(
email_context
)
html_content
=
html_email
.
render
(
email_context
)
msg
=
EmailMultiAlternatives
(
subject
,
text_content
,
from_email
,
[
to
],
[
cc
])
# mime multipart requires attaching text and html in this order
msg
.
attach_alternative
(
html_content
,
'text/html'
)
return
msg
def
no_nums
(
name
):
no_numbers
=
re
.
sub
(
'[0-9]'
,
''
,
name
)
return
no_numbers
# details about the student
class
DetailStudent
(
LoginRequiredMixin
,
DetailView
):
model
=
Student
...
...
roomlist/housing/views.py
View file @
bbfd284a
...
...
@@ -10,21 +10,6 @@ from .models import Building, Floor, Room
from
accounts.models
import
Student
# this should be written in cache, to be entirely honest
def
shadowbanning
(
me
,
other_people
):
# start with only students who are actually blocking anyone
blockers
=
[
student
for
student
in
Student
.
objects
.
exclude
(
blocked_kids
=
None
)]
# of those students, collect the ones that block *you*
blocks_me
=
[
student
for
student
in
blockers
if
me
in
student
.
blocked_kids
.
all
()]
if
blocks_me
:
# python implicit truth evaluation
student_safety
=
list
(
set
(
other_people
)
-
set
(
blocks_me
))
return
student_safety
else
:
return
other_people
# a list of neighborhoods and their buildings
class
ListBuildings
(
ListView
):
model
=
Building
...
...
roomlist/lib/utils.py
0 → 100644
View file @
bbfd284a
def
custom_cas_login
(
request
,
*
args
,
**
kwargs
):
"""If a student has not completed the welcome walkthrough, go there on login."""
response
=
cas_login
(
request
,
*
args
,
**
kwargs
)
# returns HttpResponseRedirect
if
request
.
user
.
is_authenticated
():
if
not
request
.
user
.
student
.
totally_done
():
if
not
request
.
user
.
student
.
completedName
:
return
HttpResponseRedirect
(
reverse
(
'welcomeName'
))
elif
not
request
.
user
.
student
.
completedPrivacy
:
return
HttpResponseRedirect
(
reverse
(
'welcomePrivacy'
))
elif
not
request
.
user
.
student
.
completedMajor
:
return
HttpResponseRedirect
(
reverse
(
'welcomeMajor'
))
elif
not
request
.
user
.
completedSocial
:
return
HttpResponseRedirect
(
reverse
(
'welcomeSocial'
))
else
:
welcome_back
=
random
.
choice
(
return_messages
)
messages
.
add_message
(
request
,
messages
.
INFO
,
mark_safe
(
welcome_back
))
return
response
# only two students on the same floor can confirm one another (crowdsourced verification)
def
on_the_same_floor
(
student
,
confirmer
):
if
student
==
confirmer
:
# Student is confirmer
return
False
student_floor
=
student
.
get_floor
()
confirmer_floor
=
confirmer
.
get_floor
()
# room hasn't been set yet
if
(
student_floor
is
None
)
or
(
confirmer_floor
is
None
):
# one Student is None
return
False
elif
not
(
student_floor
==
confirmer_floor
):
# not the same floor
return
False
else
:
return
True
def
pk_or_none
(
me
,
obj
):
if
obj
is
None
:
return
None
else
:
return
obj
.
pk
def
create_email
(
text_path
,
html_path
,
subject
,
to
,
context
):
text_email
=
get_template
(
text_path
)
html_email
=
get_template
(
html_path
)
email_context
=
Context
(
context
)
from_email
,
cc
=
(
'noreply@srct.gmu.edu'
,
''
)
text_content
=
text_email
.
render
(
email_context
)
html_content
=
html_email
.
render
(
email_context
)
msg
=
EmailMultiAlternatives
(
subject
,
text_content
,
from_email
,
[
to
],
[
cc
])
# mime multipart requires attaching text and html in this order
msg
.
attach_alternative
(
html_content
,
'text/html'
)
return
msg
def
no_nums
(
name
):
no_numbers
=
re
.
sub
(
'[0-9]'
,
''
,
name
)
return
no_numbers
def
get_semester
(
date
):
# months are between 1 and 12, inclusive
semesters
=
{
'Spring'
:
(
1
,
2
,
3
,
4
,
5
),
'Summer'
:
(
6
,
7
),
'Fall'
:
(
8
,
9
,
10
,
11
,
12
)
}
for
semester
,
months
in
semesters
.
iteritems
():
if
date
.
month
in
months
:
semester_string
=
semester
return
semester_string
# this should be written in cache, to be entirely honest
def
shadowbanning
(
me
,
other_people
):
# start with only students who are actually blocking anyone
blockers
=
[
student
for
student
in
Student
.
objects
.
exclude
(
blocked_kids
=
None
)]
# of those students, collect the ones that block *you*
blocks_me
=
[
student
for
student
in
blockers
if
me
in
student
.
blocked_kids
.
all
()]
if
blocks_me
:
# python implicit truth evaluation
student_safety
=
list
(
set
(
other_people
)
-
set
(
blocks_me
))
return
student_safety
else
:
return
other_people
roomlist/welcome/views.py
View file @
bbfd284a
...
...
@@ -22,21 +22,6 @@ settings_redirect = """You've already finished the welcome walkthrough.
Your user settings can now be changed here on this page."""
def
get_semester
(
date
):
# months are between 1 and 12, inclusive
semesters
=
{
'Spring'
:
(
1
,
2
,
3
,
4
,
5
),
'Summer'
:
(
6
,
7
),
'Fall'
:
(
8
,
9
,
10
,
11
,
12
)
}
for
semester
,
months
in
semesters
.
iteritems
():
if
date
.
month
in
months
:
semester_string
=
semester
return
semester_string
class
WelcomeName
(
LoginRequiredMixin
,
FormView
):
"""Student adds first and last name, and gender and gender display."""
...
...
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