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
138774cb
Commit
138774cb
authored
Oct 15, 2012
by
Carlos Andrés Rocha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add ajax endpoint to retrieve and assign course software licenses
parent
8a0b4d06
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
2 deletions
+61
-2
lms/djangoapps/licenses/models.py
+1
-1
lms/djangoapps/licenses/views.py
+52
-1
lms/urls.py
+8
-0
No files found.
lms/djangoapps/licenses/models.py
View file @
138774cb
...
...
@@ -65,7 +65,7 @@ def _create_license(user, software):
# table/rows with select_for_update to prevent race conditions
with
transaction
.
commit_on_success
():
selected
=
UserLicense
.
objects
.
select_for_update
()
license
=
selected
.
filter
(
user__isnull
=
True
)[
0
]
license
=
selected
.
filter
(
user__isnull
=
True
,
software
=
software
)[
0
]
license
.
user
=
user
license
.
save
()
except
IndexError
:
...
...
lms/djangoapps/licenses/views.py
View file @
138774cb
import
logging
import
json
import
re
from
urlparse
import
urlparse
from
collections
import
namedtuple
,
defaultdict
from
mitxmako.shortcuts
import
render_to_string
from
models
import
get_courses_licenses
,
get_or_create_license
from
django.contrib.auth.models
import
User
from
django.http
import
HttpResponse
,
Http404
from
django.views.decorators.csrf
import
requires_csrf_token
,
csrf_protect
from
models
import
CourseSoftware
from
models
import
get_courses_licenses
,
get_or_create_license
,
get_license
log
=
logging
.
getLogger
(
"mitx.licenses"
)
...
...
@@ -33,3 +42,45 @@ def get_licenses_by_course(user, courses):
data_by_course
[
course_id
]
=
render_to_string
(
template
,
context
)
return
data_by_course
@requires_csrf_token
def
user_software_license
(
request
):
if
request
.
method
!=
'POST'
or
not
request
.
is_ajax
():
raise
Http404
# get the course id from the referer
url_path
=
urlparse
(
request
.
META
.
get
(
'HTTP_REFERER'
,
''
))
.
path
pattern
=
re
.
compile
(
'^/courses/(?P<id>[^/]+/[^/]+/[^/]+)/.*/?$'
)
match
=
re
.
match
(
pattern
,
url_path
)
if
not
match
:
raise
Http404
course_id
=
match
.
groupdict
()
.
get
(
'id'
,
''
)
user_id
=
request
.
session
.
get
(
'_auth_user_id'
)
software_name
=
request
.
POST
.
get
(
'software'
)
generate
=
request
.
POST
.
get
(
'generate'
,
False
)
==
'true'
print
user_id
,
software_name
,
generate
try
:
software
=
CourseSoftware
.
objects
.
get
(
name
=
software_name
,
course_id
=
course_id
)
print
software
except
CourseSoftware
.
DoesNotExist
:
raise
Http404
user
=
User
.
objects
.
get
(
id
=
user_id
)
if
generate
:
license
=
get_or_create_license
(
user
,
software
)
else
:
license
=
get_license
(
user
,
software
)
if
license
:
response
=
{
'serial'
:
license
.
serial
}
else
:
response
=
{
'error'
:
'No serial number found'
}
return
HttpResponse
(
json
.
dumps
(
response
),
mimetype
=
'application/json'
)
lms/urls.py
View file @
138774cb
...
...
@@ -154,6 +154,14 @@ if settings.COURSEWARE_ENABLED:
url
(
r'^preview/chemcalc'
,
'courseware.module_render.preview_chemcalc'
,
name
=
'preview_chemcalc'
),
# Software Licenses
# TODO: for now, this is the endpoint of an ajax replay
# service that retrieve and assigns license numbers for
# software assigned to a course. The numbers have to be loaded
# into the database.
url
(
r'^software-licenses$'
,
'licenses.views.user_software_license'
,
name
=
"user_software_license"
),
url
(
r'^courses/(?P<course_id>[^/]+/[^/]+/[^/]+)/xqueue/(?P<userid>[^/]*)/(?P<id>.*?)/(?P<dispatch>[^/]*)$'
,
'courseware.module_render.xqueue_callback'
,
name
=
'xqueue_callback'
),
...
...
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