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
f430c633
Commit
f430c633
authored
Sep 07, 2015
by
Daniel W Bond
Browse files
minor reordering, added welcome views
parent
d8ae30f0
Changes
1
Hide whitespace changes
Inline
Side-by-side
roomlist/accounts/views.py
View file @
f430c633
# core django imports
from
django.shortcuts
import
get_object_or_404
from
django.http
import
HttpResponseForbidden
from
django.views.generic
import
ListView
,
DetailView
,
UpdateView
from
django.views.generic
import
ListView
,
DetailView
,
UpdateView
,
FormView
# third party imports
from
braces.views
import
LoginRequiredMixin
# imports from your apps
from
.models
import
Student
,
Major
# update a student (students are *created* on first login via CAS)
class
UpdateStudent
(
LoginRequiredMixin
,
UpdateView
):
model
=
Student
fields
=
[
'room'
,
'privacy'
,
]
context_object_name
=
'student'
template_name
=
'updateStudent.html'
login_url
=
'login'
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
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
):
print
"I'm sorry, what now?"
return
HttpResponseForbidden
()
else
:
return
super
(
UpdateStudent
,
self
).
get
(
request
,
*
args
,
**
kwargs
)
class
UpdateStudentMajor
(
LoginRequiredMixin
,
UpdateView
):
models
=
Student
fields
=
[
'major'
,
]
template_name
=
'updateStudentMajor.html'
login_url
=
'login'
# copied from below
# def get_object(self):
# return get_object_or_404(Student, pk=self.request.session['_auth_user_id'])
from
.forms
import
WelcomeNameForm
# details about the student
...
...
@@ -118,6 +84,67 @@ class DetailCurrentStudentSettings(LoginRequiredMixin, DetailView):
def
get_object
(
self
):
return
get_object_or_404
(
Student
,
pk
=
self
.
request
.
session
[
'_auth_user_id'
])
# update a student (students are *created* on first login via CAS)
class
UpdateStudent
(
LoginRequiredMixin
,
UpdateView
):
model
=
Student
fields
=
[
'room'
,
'privacy'
,
'major'
,
'gender'
,
]
context_object_name
=
'student'
template_name
=
'updateStudent.html'
login_url
=
'login'
# change to formview to support changing name
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
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
):
print
"I'm sorry, what now?"
return
HttpResponseForbidden
()
else
:
return
super
(
UpdateStudent
,
self
).
get
(
request
,
*
args
,
**
kwargs
)
# use the same forms with different templates, views, and urls
# welcome pages
class
WelcomeName
(
LoginRequiredMixin
,
FormView
):
template_name
=
'welcomeName.html'
form_class
=
WelcomeNameForm
login_url
=
'login'
class
WelcomePrivacy
(
LoginRequiredMixin
,
UpdateView
):
model
=
Student
fields
=
[
'room'
,
'privacy'
,
]
context_object_name
=
'student'
template_name
=
'welcomePrivacy.html'
login_url
=
'login'
class
WelcomeMajor
(
LoginRequiredMixin
,
UpdateView
):
model
=
Student
fields
=
[
'major'
,
]
context_object_name
=
'student'
template_name
=
'welcomeMajor.html'
login_url
=
'login'
class
WelcomeSocial
(
LoginRequiredMixin
,
DetailView
):
model
=
Student
context_object_name
=
'student'
template_name
=
'welcomeSocial.html'
login_url
=
'login'
# majors pages
class
ListMajors
(
LoginRequiredMixin
,
ListView
):
model
=
Major
queryset
=
Major
.
objects
.
all
().
order_by
(
'name'
)
...
...
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