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
c42960c1
Commit
c42960c1
authored
Aug 05, 2012
by
ichuang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add feature ENABLE_SQL_TRACKING_LOGS and url view /event_logs
parent
3c232358
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
3 deletions
+52
-3
common/djangoapps/track/models.py
+19
-1
common/djangoapps/track/views.py
+27
-2
lms/envs/dev.py
+1
-0
lms/urls.py
+5
-0
No files found.
common/djangoapps/track/models.py
View file @
c42960c1
from
django.db
import
models
# Create your models here.
from
django.db
import
models
class
TrackingLog
(
models
.
Model
):
dtcreated
=
models
.
DateTimeField
(
'creation date'
,
auto_now_add
=
True
)
username
=
models
.
CharField
(
max_length
=
32
,
blank
=
True
)
ip
=
models
.
CharField
(
max_length
=
32
,
blank
=
True
)
event_source
=
models
.
CharField
(
max_length
=
32
)
event_type
=
models
.
CharField
(
max_length
=
32
,
blank
=
True
)
event
=
models
.
TextField
(
blank
=
True
)
agent
=
models
.
CharField
(
max_length
=
256
,
blank
=
True
)
page
=
models
.
CharField
(
max_length
=
32
,
blank
=
True
,
null
=
True
)
time
=
models
.
DateTimeField
(
'event time'
)
def
__unicode__
(
self
):
s
=
"[
%
s]
%
s@
%
s:
%
s |
%
s |
%
s |
%
s"
%
(
self
.
time
,
self
.
username
,
self
.
ip
,
self
.
event_source
,
self
.
event_type
,
self
.
page
,
self
.
event
)
return
s
common/djangoapps/track/views.py
View file @
c42960c1
...
...
@@ -2,19 +2,32 @@ import json
import
logging
import
os
import
datetime
import
dateutil.parser
# Create your views here.
from
django.contrib.auth.decorators
import
login_required
from
django.http
import
HttpResponse
from
django.http
import
Http404
from
django.shortcuts
import
redirect
from
django.conf
import
settings
from
mitxmako.shortcuts
import
render_to_response
from
django_future.csrf
import
ensure_csrf_cookie
from
track.models
import
TrackingLog
log
=
logging
.
getLogger
(
"tracking"
)
LOGFIELDS
=
[
'username'
,
'ip'
,
'event_source'
,
'event_type'
,
'event'
,
'agent'
,
'page'
,
'time'
]
def
log_event
(
event
):
event_str
=
json
.
dumps
(
event
)
log
.
info
(
event_str
[:
settings
.
TRACK_MAX_EVENT
])
if
settings
.
MITX_FEATURES
.
get
(
'ENABLE_SQL_TRACKING_LOGS'
):
event
[
'time'
]
=
dateutil
.
parser
.
parse
(
event
[
'time'
])
tldat
=
TrackingLog
(
**
dict
([(
x
,
event
[
x
])
for
x
in
LOGFIELDS
]))
try
:
tldat
.
save
()
except
Exception
as
err
:
log
.
debug
(
err
)
def
user_track
(
request
):
try
:
# TODO: Do the same for many of the optional META parameters
...
...
@@ -70,4 +83,16 @@ def server_track(request, event_type, event, page=None):
"page"
:
page
,
"time"
:
datetime
.
datetime
.
utcnow
()
.
isoformat
(),
}
if
event_type
==
"/event_logs"
and
request
.
user
.
is_staff
:
# don't log
return
log_event
(
event
)
@login_required
@ensure_csrf_cookie
def
view_tracking_log
(
request
):
if
not
request
.
user
.
is_staff
:
return
redirect
(
'/'
)
record_instances
=
TrackingLog
.
objects
.
all
()
.
order_by
(
'-time'
)[
0
:
100
]
return
render_to_response
(
'tracking_log.html'
,{
'records'
:
record_instances
})
lms/envs/dev.py
View file @
c42960c1
...
...
@@ -14,6 +14,7 @@ DEBUG = True
TEMPLATE_DEBUG
=
True
MITX_FEATURES
[
'DISABLE_START_DATES'
]
=
True
MITX_FEATURES
[
'ENABLE_SQL_TRACKING_LOGS'
]
=
True
WIKI_ENABLED
=
True
...
...
lms/urls.py
View file @
c42960c1
...
...
@@ -175,6 +175,11 @@ if settings.MITX_FEATURES.get('ENABLE_LMS_MIGRATION'):
url
(
r'^migrate/reload/(?P<reload_dir>[^/]+)$'
,
'lms_migration.migrate.manage_modulestores'
),
)
if
settings
.
MITX_FEATURES
.
get
(
'ENABLE_SQL_TRACKING_LOGS'
):
urlpatterns
+=
(
url
(
r'^event_logs$'
,
'track.views.view_tracking_log'
),
)
urlpatterns
=
patterns
(
*
urlpatterns
)
if
settings
.
DEBUG
:
...
...
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