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
0d994498
Commit
0d994498
authored
Sep 16, 2015
by
cahrens
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Emit event when last_activity_at is updated.
TNL-3303
parent
305f88f6
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
34 additions
and
21 deletions
+34
-21
lms/djangoapps/teams/models.py
+4
-0
lms/djangoapps/teams/tests/test_models.py
+9
-3
lms/djangoapps/teams/tests/test_views.py
+6
-6
lms/djangoapps/teams/utils.py
+14
-0
lms/djangoapps/teams/views.py
+1
-12
No files found.
lms/djangoapps/teams/models.py
View file @
0d994498
...
...
@@ -28,6 +28,7 @@ from xmodule_django.models import CourseKeyField
from
util.model_utils
import
slugify
from
student.models
import
LanguageField
,
CourseEnrollment
from
.errors
import
AlreadyOnTeamInCourse
,
NotEnrolledInCourseForTeam
,
ImmutableMembershipFieldException
from
teams.utils
import
emit_team_event
from
teams
import
TEAM_DISCUSSION_CONTEXT
...
...
@@ -247,3 +248,6 @@ class CourseTeamMembership(models.Model):
membership
.
team
.
last_activity_at
=
now
membership
.
team
.
save
()
membership
.
save
()
emit_team_event
(
'edx.team.activity_updated'
,
membership
.
team
.
course_id
,
{
'team_id'
:
membership
.
team_id
,
})
lms/djangoapps/teams/tests/test_models.py
View file @
0d994498
...
...
@@ -24,8 +24,9 @@ from opaque_keys.edx.keys import CourseKey
from
student.tests.factories
import
CourseEnrollmentFactory
,
UserFactory
from
.factories
import
CourseTeamFactory
,
CourseTeamMembershipFactory
from
.
.models
import
CourseTeam
,
CourseTeamMembership
from
teams
.models
import
CourseTeam
,
CourseTeamMembership
from
teams
import
TEAM_DISCUSSION_CONTEXT
from
util.testing
import
EventTestMixin
COURSE_KEY1
=
CourseKey
.
from_string
(
'edx/history/1'
)
COURSE_KEY2
=
CourseKey
.
from_string
(
'edx/history/2'
)
...
...
@@ -114,7 +115,7 @@ class TeamMembershipTest(SharedModuleStoreTestCase):
@ddt.ddt
class
TeamSignalsTest
(
SharedModuleStoreTestCase
):
class
TeamSignalsTest
(
EventTestMixin
,
SharedModuleStoreTestCase
):
"""Tests for handling of team-related signals."""
SIGNALS_LIST
=
(
...
...
@@ -133,7 +134,7 @@ class TeamSignalsTest(SharedModuleStoreTestCase):
def
setUp
(
self
):
"""Create a user with a team to test signals."""
super
(
TeamSignalsTest
,
self
)
.
setUp
()
super
(
TeamSignalsTest
,
self
)
.
setUp
(
'teams.utils.tracker'
)
self
.
user
=
UserFactory
.
create
(
username
=
"user"
)
self
.
moderator
=
UserFactory
.
create
(
username
=
"moderator"
)
self
.
team
=
CourseTeamFactory
(
discussion_topic_id
=
self
.
DISCUSSION_TOPIC_ID
)
...
...
@@ -168,9 +169,14 @@ class TeamSignalsTest(SharedModuleStoreTestCase):
now
=
datetime
.
utcnow
()
.
replace
(
tzinfo
=
pytz
.
utc
)
self
.
assertGreater
(
now
,
team
.
last_activity_at
)
self
.
assertGreater
(
now
,
team_membership
.
last_activity_at
)
self
.
assert_event_emitted
(
'edx.team.activity_updated'
,
team_id
=
team
.
id
,
)
else
:
self
.
assertEqual
(
team
.
last_activity_at
,
team_last_activity
)
self
.
assertEqual
(
team_membership
.
last_activity_at
,
team_membership_last_activity
)
self
.
assert_no_events_were_emitted
()
@ddt.data
(
*
itertools
.
product
(
...
...
lms/djangoapps/teams/tests/test_views.py
View file @
0d994498
...
...
@@ -418,7 +418,7 @@ class TestListTeamsAPI(EventTestMixin, TeamAPITestCase):
"""Test cases for the team listing API endpoint."""
def
setUp
(
self
):
# pylint: disable=arguments-differ
super
(
TestListTeamsAPI
,
self
)
.
setUp
(
'teams.
view
s.tracker'
)
super
(
TestListTeamsAPI
,
self
)
.
setUp
(
'teams.
util
s.tracker'
)
@ddt.data
(
(
None
,
401
),
...
...
@@ -592,7 +592,7 @@ class TestCreateTeamAPI(EventTestMixin, TeamAPITestCase):
"""Test cases for the team creation endpoint."""
def
setUp
(
self
):
# pylint: disable=arguments-differ
super
(
TestCreateTeamAPI
,
self
)
.
setUp
(
'teams.
view
s.tracker'
)
super
(
TestCreateTeamAPI
,
self
)
.
setUp
(
'teams.
util
s.tracker'
)
@ddt.data
(
(
None
,
401
),
...
...
@@ -803,7 +803,7 @@ class TestDeleteTeamAPI(EventTestMixin, TeamAPITestCase):
"""Test cases for the team delete endpoint."""
def
setUp
(
self
):
# pylint: disable=arguments-differ
super
(
TestDeleteTeamAPI
,
self
)
.
setUp
(
'teams.
view
s.tracker'
)
super
(
TestDeleteTeamAPI
,
self
)
.
setUp
(
'teams.
util
s.tracker'
)
@ddt.data
(
(
None
,
401
),
...
...
@@ -853,7 +853,7 @@ class TestUpdateTeamAPI(EventTestMixin, TeamAPITestCase):
"""Test cases for the team update endpoint."""
def
setUp
(
self
):
# pylint: disable=arguments-differ
super
(
TestUpdateTeamAPI
,
self
)
.
setUp
(
'teams.
view
s.tracker'
)
super
(
TestUpdateTeamAPI
,
self
)
.
setUp
(
'teams.
util
s.tracker'
)
@ddt.data
(
(
None
,
401
),
...
...
@@ -1182,7 +1182,7 @@ class TestCreateMembershipAPI(EventTestMixin, TeamAPITestCase):
"""Test cases for the membership creation endpoint."""
def
setUp
(
self
):
# pylint: disable=arguments-differ
super
(
TestCreateMembershipAPI
,
self
)
.
setUp
(
'teams.
view
s.tracker'
)
super
(
TestCreateMembershipAPI
,
self
)
.
setUp
(
'teams.
util
s.tracker'
)
@ddt.data
(
(
None
,
401
),
...
...
@@ -1346,7 +1346,7 @@ class TestDeleteMembershipAPI(EventTestMixin, TeamAPITestCase):
"""Test cases for the membership deletion endpoint."""
def
setUp
(
self
):
# pylint: disable=arguments-differ
super
(
TestDeleteMembershipAPI
,
self
)
.
setUp
(
'teams.
view
s.tracker'
)
super
(
TestDeleteMembershipAPI
,
self
)
.
setUp
(
'teams.
util
s.tracker'
)
@ddt.data
(
(
None
,
401
),
...
...
lms/djangoapps/teams/utils.py
0 → 100644
View file @
0d994498
"""Utility methods related to teams."""
from
eventtracking
import
tracker
from
track
import
contexts
def
emit_team_event
(
event_name
,
course_key
,
event_data
):
"""
Emit team events with the correct course id context.
"""
context
=
contexts
.
course_context_from_course_id
(
course_key
)
with
tracker
.
get_tracker
()
.
context
(
event_name
,
context
):
tracker
.
emit
(
event_name
,
event_data
)
lms/djangoapps/teams/views.py
View file @
0d994498
...
...
@@ -39,8 +39,6 @@ from opaque_keys import InvalidKeyError
from
opaque_keys.edx.keys
import
CourseKey
from
courseware.courses
import
get_course_with_access
,
has_access
from
eventtracking
import
tracker
from
track
import
contexts
from
student.models
import
CourseEnrollment
,
CourseAccessRole
from
student.roles
import
CourseStaffRole
from
django_comment_client.utils
import
has_discussion_privileges
...
...
@@ -59,6 +57,7 @@ from .serializers import (
)
from
.search_indexes
import
CourseTeamIndexer
from
.errors
import
AlreadyOnTeamInCourse
,
ElasticSearchConnectionError
,
NotEnrolledInCourseForTeam
from
.utils
import
emit_team_event
TEAM_MEMBERSHIPS_PER_PAGE
=
2
TOPICS_PER_PAGE
=
12
...
...
@@ -67,16 +66,6 @@ MAXIMUM_SEARCH_SIZE = 100000
log
=
logging
.
getLogger
(
__name__
)
def
emit_team_event
(
event_name
,
course_key
,
event_data
):
"""
Emit team events with the correct course id context.
"""
context
=
contexts
.
course_context_from_course_id
(
course_key
)
with
tracker
.
get_tracker
()
.
context
(
event_name
,
context
):
tracker
.
emit
(
event_name
,
event_data
)
@receiver
(
post_save
,
sender
=
CourseTeam
)
def
team_post_save_callback
(
sender
,
instance
,
**
kwargs
):
# pylint: disable=unused-argument
""" Emits signal after the team is saved. """
...
...
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