Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
173a844c
Commit
173a844c
authored
Mar 21, 2012
by
Piotr Mitros
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Incorporated Dave's feedback
parent
894ff82f
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
23 deletions
+17
-23
djangoapps/student/models.py
+6
-5
djangoapps/student/views.py
+10
-17
urls.py
+1
-1
No files found.
djangoapps/student/models.py
View file @
173a844c
...
...
@@ -31,10 +31,12 @@ class UserProfile(models.Model):
courseware
=
models
.
CharField
(
blank
=
True
,
max_length
=
255
,
default
=
'course.xml'
)
def
get_meta
(
self
):
try
:
js
=
json
.
reads
(
self
.
meta
)
except
:
js_str
=
self
.
meta
if
not
js
:
js
=
dict
()
else
:
js
=
json
.
reads
(
self
.
meta
)
return
js
def
set_meta
(
self
,
js
):
...
...
@@ -138,10 +140,9 @@ default_groups = {'email_future_courses' : 'Receive e-mails about future MITx co
'6002x_unenroll'
:
'Took and dropped 6002x'
}
def
add_user_to_default_group
(
user
,
group
):
''' Untested '''
try
:
utg
=
UserTestGroup
.
objects
.
get
(
name
=
group
)
except
:
except
UserTestGroup
.
DoesNotExist
:
utg
=
UserTestGroup
()
utg
.
name
=
group
utg
.
description
=
default_groups
[
group
]
...
...
djangoapps/student/views.py
View file @
173a844c
...
...
@@ -2,6 +2,7 @@ import json
import
logging
import
random
import
string
import
sys
import
uuid
from
django.conf
import
settings
...
...
@@ -16,9 +17,10 @@ from django.http import HttpResponse, Http404
from
django.shortcuts
import
redirect
from
mitxmako.shortcuts
import
render_to_response
,
render_to_string
from
models
import
Registration
,
UserProfile
,
PendingNameChange
,
PendingEmailChange
from
django_future.csrf
import
ensure_csrf_cookie
from
models
import
Registration
,
UserProfile
,
PendingNameChange
,
PendingEmailChange
log
=
logging
.
getLogger
(
"mitx.user"
)
def
csrf_token
(
context
):
...
...
@@ -87,7 +89,6 @@ def login_user(request, error=""):
def
logout_user
(
request
):
''' HTTP request to log in the user. Redirects to marketing page'''
logout
(
request
)
# print len(connection.queries), connection.queries
return
redirect
(
'/'
)
@ensure_csrf_cookie
...
...
@@ -98,10 +99,8 @@ def change_setting(request):
return
redirect
(
'/'
)
up
=
UserProfile
.
objects
.
get
(
user
=
request
.
user
)
#request.user.profile_cache
if
'location'
in
request
.
POST
:
# print "loc"
up
.
location
=
request
.
POST
[
'location'
]
if
'language'
in
request
.
POST
:
# print "lang"
up
.
language
=
request
.
POST
[
'language'
]
up
.
save
()
...
...
@@ -199,13 +198,13 @@ def create_account(request, post_override=None):
if
not
settings
.
GENERATE_RANDOM_USER_CREDENTIALS
:
res
=
u
.
email_user
(
subject
,
message
,
settings
.
DEFAULT_FROM_EMAIL
)
except
:
log
.
exception
(
sys
.
exc_info
())
js
[
'value'
]
=
'Could not send activation e-mail.'
return
HttpResponse
(
json
.
dumps
(
js
))
js
=
{
'success'
:
True
,
'value'
:
render_to_string
(
'registration/reg_complete.html'
,
{
'email'
:
post_vars
[
'email'
],
'csrf'
:
csrf
(
request
)[
'csrf_token'
]})}
# print len(connection.queries), connection.queries
return
HttpResponse
(
json
.
dumps
(
js
),
mimetype
=
"application/json"
)
def
create_random_account
(
create_account_function
):
...
...
@@ -223,8 +222,6 @@ def create_random_account(create_account_function):
'honor_code'
:
u'true'
,
'terms_of_service'
:
u'true'
,}
# print "Creating random account: " , post_override
return
create_account_function
(
request
,
post_override
=
post_override
)
return
inner_create_random_account
...
...
@@ -267,11 +264,11 @@ def password_reset(request):
@ensure_csrf_cookie
def
reactivation_email
(
request
):
''' Send an e-mail to reactivate a deactivated account, or to
resend an activation e-mail '''
resend an activation e-mail
. Untested.
'''
email
=
request
.
POST
[
'email'
]
try
:
user
=
User
.
objects
.
get
(
email
=
'email'
)
except
:
# TODO: Type of exception
except
User
.
DoesNotExist
:
return
HttpResponse
(
json
.
dumps
({
'success'
:
False
,
'error'
:
'No inactive user with this e-mail exists'
}))
...
...
@@ -351,7 +348,7 @@ def confirm_email_change(request, key):
'''
try
:
pec
=
PendingEmailChange
.
objects
.
get
(
activation_key
=
key
)
except
:
except
PendingEmailChange
.
DoesNotExist
:
return
render_to_response
(
"invalid_email_key.html"
,
{})
user
=
pec
.
user
...
...
@@ -368,7 +365,6 @@ def confirm_email_change(request, key):
message
=
render_to_string
(
'emails/confirm_email_change.txt'
,
d
)
up
=
UserProfile
.
objects
.
get
(
user
=
user
)
meta
=
up
.
get_meta
()
print
meta
if
'old_emails'
not
in
meta
:
meta
[
'old_emails'
]
=
[]
meta
[
'old_emails'
]
.
append
(
user
.
email
)
...
...
@@ -389,7 +385,7 @@ def change_name_request(request):
try
:
pnc
=
PendingNameChange
.
objects
.
get
(
user
=
request
.
user
)
except
:
except
PendingNameChange
.
DoesNotExist
:
pnc
=
PendingNameChange
()
pnc
.
user
=
request
.
user
pnc
.
new_name
=
request
.
POST
[
'new_name'
]
...
...
@@ -404,9 +400,7 @@ def change_name_request(request):
@ensure_csrf_cookie
def
pending_name_changes
(
request
):
''' Web page which allows staff to approve or reject name changes. '''
print
request
.
user
.
is_staff
,
request
.
user
if
not
request
.
user
.
is_staff
:
print
"AAAA"
raise
Http404
changes
=
list
(
PendingNameChange
.
objects
.
all
())
...
...
@@ -426,7 +420,7 @@ def reject_name_change(request):
try
:
pnc
=
PendingNameChange
.
objects
.
get
(
id
=
int
(
request
.
POST
[
'id'
]))
except
:
except
PendingNameChange
.
DoesNotExist
:
return
HttpResponse
(
json
.
dumps
({
'success'
:
False
,
'error'
:
'Invalid ID'
}))
pnc
.
delete
()
...
...
@@ -440,7 +434,7 @@ def accept_name_change(request):
try
:
pnc
=
PendingNameChange
.
objects
.
get
(
id
=
int
(
request
.
POST
[
'id'
]))
except
:
except
PendingNameChange
.
DoesNotExist
:
return
HttpResponse
(
json
.
dumps
({
'success'
:
False
,
'error'
:
'Invalid ID'
}))
u
=
pnc
.
user
...
...
@@ -448,7 +442,6 @@ def accept_name_change(request):
# Save old name
meta
=
up
.
get_meta
()
print
meta
if
'old_names'
not
in
meta
:
meta
[
'old_names'
]
=
[]
meta
[
'old_names'
]
.
append
(
up
.
name
)
...
...
urls.py
View file @
173a844c
...
...
@@ -23,7 +23,7 @@ urlpatterns = ('',
url
(
r'^logout$'
,
'student.views.logout_user'
),
url
(
r'^create_account$'
,
'student.views.create_account'
),
url
(
r'^activate/(?P<key>[^/]*)$'
,
'student.views.activate_account'
),
url
(
r'^reactivate/(?P<key>[^/]*)$'
,
'student.views.reactivation_email'
),
#
url(r'^reactivate/(?P<key>[^/]*)$', 'student.views.reactivation_email'),
url
(
r'^password_reset/$'
,
'student.views.password_reset'
),
## Obsolete Django views for password resets
## TODO: Replace with Mako-ized views
...
...
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