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
665fb707
Commit
665fb707
authored
Jan 23, 2013
by
Vik Paruchuri
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cache notifications for 5 mins so that we don't hit the grading server on every web request
parent
68f563a1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
69 additions
and
7 deletions
+69
-7
lms/djangoapps/courseware/tabs.py
+1
-1
lms/djangoapps/open_ended_grading/open_ended_notifications.py
+68
-6
No files found.
lms/djangoapps/courseware/tabs.py
View file @
665fb707
...
...
@@ -110,7 +110,7 @@ def _staff_grading(tab, user, course, active_page):
tab_name
=
"Staff grading"
notifications
=
open_ended_notifications
.
staff_grading_notifications
(
course
)
notifications
=
open_ended_notifications
.
staff_grading_notifications
(
course
,
user
)
pending_grading
=
notifications
[
'pending_grading'
]
img_path
=
notifications
[
'img_path'
]
...
...
lms/djangoapps/open_ended_grading/open_ended_notifications.py
View file @
665fb707
...
...
@@ -8,20 +8,31 @@ import open_ended_util
from
courseware.models
import
StudentModule
import
logging
from
courseware.access
import
has_access
from
util.cache
import
cache
log
=
logging
.
getLogger
(
__name__
)
NOTIFICATION_CACHE_TIME
=
300
KEY_PREFIX
=
"open_ended_"
NOTIFICATION_TYPES
=
(
(
'student_needs_to_peer_grade'
,
'peer_grading'
,
'Peer Grading'
),
(
'staff_needs_to_grade'
,
'staff_grading'
,
'Staff Grading'
),
(
'new_student_grading_to_view'
,
'open_ended_problems'
,
'Problems you have submitted'
)
)
def
staff_grading_notifications
(
course
):
def
staff_grading_notifications
(
course
,
user
):
staff_gs
=
StaffGradingService
(
settings
.
STAFF_GRADING_INTERFACE
)
pending_grading
=
False
img_path
=
""
course_id
=
course
.
id
student_id
=
unique_id_for_user
(
user
)
notification_type
=
"staff"
success
,
notification_dict
=
get_value_from_cache
(
student_id
,
course_id
,
notification_type
)
if
success
:
return
notification_dict
try
:
notifications
=
json
.
loads
(
staff_gs
.
get_notifications
(
course_id
))
if
notifications
[
'success'
]:
...
...
@@ -35,16 +46,26 @@ def staff_grading_notifications(course):
if
pending_grading
:
img_path
=
"/static/images/slider-handle.png"
return
{
'pending_grading'
:
pending_grading
,
'img_path'
:
img_path
,
'response'
:
notifications
}
notification_dict
=
{
'pending_grading'
:
pending_grading
,
'img_path'
:
img_path
,
'response'
:
notifications
}
set_value_in_cache
(
student_id
,
course_id
,
notification_type
,
notification_dict
)
return
notification_dict
def
peer_grading_notifications
(
course
,
user
):
peer_gs
=
PeerGradingService
(
settings
.
PEER_GRADING_INTERFACE
)
pending_grading
=
False
img_path
=
""
course_id
=
course
.
id
student_id
=
unique_id_for_user
(
user
)
notification_type
=
"peer"
success
,
notification_dict
=
get_value_from_cache
(
student_id
,
course_id
,
notification_type
)
if
success
:
return
notification_dict
try
:
notifications
=
json
.
loads
(
peer_gs
.
get_notifications
(
course_id
,
unique_id_for_user
(
user
)
))
notifications
=
json
.
loads
(
peer_gs
.
get_notifications
(
course_id
,
student_id
))
if
notifications
[
'success'
]:
if
notifications
[
'student_needs_to_peer_grade'
]:
pending_grading
=
True
...
...
@@ -56,7 +77,11 @@ def peer_grading_notifications(course, user):
if
pending_grading
:
img_path
=
"/static/images/slider-handle.png"
return
{
'pending_grading'
:
pending_grading
,
'img_path'
:
img_path
,
'response'
:
notifications
}
notification_dict
=
{
'pending_grading'
:
pending_grading
,
'img_path'
:
img_path
,
'response'
:
notifications
}
set_value_in_cache
(
student_id
,
course_id
,
notification_type
,
notification_dict
)
return
notification_dict
def
combined_notifications
(
course
,
user
):
controller_url
=
open_ended_util
.
get_controller_url
()
...
...
@@ -64,6 +89,11 @@ def combined_notifications(course, user):
student_id
=
unique_id_for_user
(
user
)
user_is_staff
=
has_access
(
user
,
course
,
'staff'
)
course_id
=
course
.
id
notification_type
=
"combined"
success
,
notification_dict
=
get_value_from_cache
(
student_id
,
course_id
,
notification_type
)
if
success
:
return
notification_dict
min_time_to_query
=
user
.
last_login
last_module_seen
=
StudentModule
.
objects
.
filter
(
student
=
user
,
course_id
=
course_id
,
modified__gt
=
min_time_to_query
)
.
values
(
'modified'
)
.
order_by
(
'-modified'
)
...
...
@@ -92,4 +122,36 @@ def combined_notifications(course, user):
if
pending_grading
:
img_path
=
"/static/images/slider-handle.png"
return
{
'pending_grading'
:
pending_grading
,
'img_path'
:
img_path
,
'response'
:
notifications
}
\ No newline at end of file
notification_dict
=
{
'pending_grading'
:
pending_grading
,
'img_path'
:
img_path
,
'response'
:
notifications
}
set_value_in_cache
(
student_id
,
course_id
,
notification_type
,
notification_dict
)
return
notification_dict
def
get_value_from_cache
(
student_id
,
course_id
,
notification_type
):
key_name
=
create_key_name
(
student_id
,
course_id
,
notification_type
)
success
,
value
=
_get_value_from_cache
(
key_name
)
return
success
,
value
def
set_value_in_cache
(
student_id
,
course_id
,
notification_type
,
value
):
key_name
=
create_key_name
(
student_id
,
course_id
,
notification_type
)
_set_value_in_cache
(
key_name
,
value
)
def
create_key_name
(
student_id
,
course_id
,
notification_type
):
key_name
=
"{prefix}{type}_{course}_{student}"
.
format
(
prefix
=
KEY_PREFIX
,
type
=
notification_type
,
course
=
course_id
,
student
=
student_id
)
return
key_name
def
_get_value_from_cache
(
key_name
):
value
=
cache
.
get
(
key_name
)
success
=
False
if
value
is
None
:
return
success
,
value
try
:
value
=
json
.
loads
(
value
)
success
=
True
except
:
pass
return
success
,
value
def
_set_value_in_cache
(
key_name
,
value
):
cache
.
set
(
key_name
,
json
.
dumps
(
value
),
NOTIFICATION_CACHE_TIME
)
\ No newline at end of file
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