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
0c41576e
Commit
0c41576e
authored
Jul 16, 2012
by
Bridger Maxwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Some changes from code review.
parent
264e324c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
3 deletions
+21
-3
lms/djangoapps/courseware/decorators.py
+20
-2
lms/djangoapps/courseware/views.py
+1
-1
No files found.
lms/djangoapps/courseware/decorators.py
View file @
0c41576e
from
functools
import
wraps
from
django.http
import
Http404
from
django.http
import
Http404
from
xmodule.course_module
import
CourseDescriptor
from
xmodule.course_module
import
CourseDescriptor
from
xmodule.modulestore.django
import
modulestore
from
xmodule.modulestore.django
import
modulestore
def
check_course
(
course_must_be_open
=
True
,
course_required
=
True
):
def
check_course
(
course_must_be_open
=
True
,
course_required
=
True
):
"""
"""
This is a decorator for views that are within a course.
This is a decorator for views that are within a course.
...
@@ -14,11 +17,26 @@ def check_course(course_must_be_open=True, course_required=True):
...
@@ -14,11 +17,26 @@ def check_course(course_must_be_open=True, course_required=True):
If the course has not started, it raises a 404. This check
If the course has not started, it raises a 404. This check
can be skipped by setting course_must_be_open to False.
can be skipped by setting course_must_be_open to False.
If course_required is False, course_id is not required. If
Usually, a 404 will be raised if a course is not found. This
behavior can be overrided by setting course_required to false.
When course_required is False, course_id is not required. If
course_id is still provided, but is None, course will be
course_id is still provided, but is None, course will be
set to None.
set to None.
Usage
This wrapper would be used on a function that has the following
entry in urls.py:
url(r'^courses/(?P<course_id>[^/]+/[^/]+/[^/]+)/book$', 'staticbook.views.index'),
Where staticbook.views.index has the following parameters:
@check_course
def index(request, course):
# Notice that the parameter is course, not course_id
"""
"""
def
inner_check_course
(
function
):
def
inner_check_course
(
function
):
@wraps
(
function
)
def
wrapped_function
(
*
args
,
**
kwargs
):
def
wrapped_function
(
*
args
,
**
kwargs
):
if
course_required
or
'course_id'
in
kwargs
:
if
course_required
or
'course_id'
in
kwargs
:
course_id
=
kwargs
[
'course_id'
]
course_id
=
kwargs
[
'course_id'
]
...
@@ -42,7 +60,7 @@ def check_course(course_must_be_open=True, course_required=True):
...
@@ -42,7 +60,7 @@ def check_course(course_must_be_open=True, course_required=True):
# If no arguments were passed to the decorator, the function itself
# If no arguments were passed to the decorator, the function itself
# will be in course_must_be_open
# will be in course_must_be_open
if
hasattr
(
course_must_be_open
,
'__call__'
):
if
callable
(
course_must_be_open
):
function
=
course_must_be_open
function
=
course_must_be_open
course_must_be_open
=
True
course_must_be_open
=
True
return
inner_check_course
(
function
)
return
inner_check_course
(
function
)
...
...
lms/djangoapps/courseware/views.py
View file @
0c41576e
...
@@ -17,7 +17,7 @@ from models import StudentModuleCache
...
@@ -17,7 +17,7 @@ from models import StudentModuleCache
from
student.models
import
UserProfile
from
student.models
import
UserProfile
from
multicourse
import
multicourse_settings
from
multicourse
import
multicourse_settings
#from util.cache import cache #TODO: Where did this go? lib/util/cache no longer exists
from
util.cache
import
cache
from
student.models
import
UserTestGroup
from
student.models
import
UserTestGroup
from
courseware
import
grades
from
courseware
import
grades
from
courseware.decorators
import
check_course
from
courseware.decorators
import
check_course
...
...
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