Tracking is partially in place
This commit is contained in:
@@ -103,6 +103,7 @@ INSTALLED_APPS = (
|
||||
'textbook',
|
||||
'staticbook',
|
||||
'simplewiki',
|
||||
'track',
|
||||
# Uncomment the next line to enable the admin:
|
||||
# 'django.contrib.admin',
|
||||
# Uncomment the next line to enable admin documentation:
|
||||
|
||||
0
track/__init__.py
Normal file
0
track/__init__.py
Normal file
3
track/models.py
Normal file
3
track/models.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
16
track/tests.py
Normal file
16
track/tests.py
Normal file
@@ -0,0 +1,16 @@
|
||||
"""
|
||||
This file demonstrates writing tests using the unittest module. These will pass
|
||||
when you run "manage.py test".
|
||||
|
||||
Replace this with more appropriate tests for your application.
|
||||
"""
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
|
||||
class SimpleTest(TestCase):
|
||||
def test_basic_addition(self):
|
||||
"""
|
||||
Tests that 1 + 1 always equals 2.
|
||||
"""
|
||||
self.assertEqual(1 + 1, 2)
|
||||
62
track/views.py
Normal file
62
track/views.py
Normal file
@@ -0,0 +1,62 @@
|
||||
# Create your views here.
|
||||
from django.http import HttpResponse
|
||||
from django.http import Http404
|
||||
from django.conf import settings
|
||||
import json
|
||||
|
||||
import tempfile
|
||||
|
||||
directory = tempfile.mkdtemp(prefix = settings.TRACK_DIR)
|
||||
|
||||
logfile = None
|
||||
file_index = 0
|
||||
log_index = 0
|
||||
MAXLOG = 5
|
||||
|
||||
def make_file():
|
||||
global logfile, log_index, file_index
|
||||
if logfile != None:
|
||||
logfile.close()
|
||||
logfile = open(directory+"/%05i"%(file_index), "w")
|
||||
file_index = file_index + 1
|
||||
log_index = 0
|
||||
|
||||
def log_event(event):
|
||||
global logfile, log_index
|
||||
if settings.TRACK_DIR == None:
|
||||
print event
|
||||
return
|
||||
|
||||
if logfile == None or log_index >= MAXLOG:
|
||||
make_file()
|
||||
|
||||
event_str = json.dumps(event)
|
||||
logfile.write(event_str+'\n')
|
||||
log_index = log_index + 1
|
||||
|
||||
def user_track(request):
|
||||
event = {
|
||||
"username" : request.user.username,
|
||||
"session" : request.META['HTTP_COOKIE'],
|
||||
"ip" : request.META['REMOTE_ADDR'],
|
||||
"event_source" : "browser",
|
||||
"event_type" : request.GET['event_type'],
|
||||
"event" : request.GET['event'],
|
||||
"agent" : request.META['HTTP_USER_AGENT'],
|
||||
"page" : request.GET['page'],
|
||||
}
|
||||
log_event(event)
|
||||
return HttpResponse('success')
|
||||
|
||||
def server_track(request, event_type, event, page=None):
|
||||
event = {
|
||||
"username" : request.user.username,
|
||||
"ip" : request.META['REMOTE_ADDR'],
|
||||
"ip" : request.META['REMOTE_ADDR'],
|
||||
"event_source" : "server",
|
||||
"event_type" : event_type,
|
||||
"event" : event,
|
||||
"agent" : request.META['HTTP_USER_AGENT'],
|
||||
"page" : page,
|
||||
}
|
||||
log_event(event)
|
||||
1
urls.py
1
urls.py
@@ -6,6 +6,7 @@ import django.contrib.auth.views
|
||||
# admin.autodiscover()
|
||||
|
||||
urlpatterns = patterns('',
|
||||
url(r'^event$', 'track.views.user_track'),
|
||||
(r'^wiki/', include('simplewiki.urls')),
|
||||
url(r'^courseware/(?P<course>[^/]*)/(?P<chapter>[^/]*)/(?P<section>[^/]*)/$', 'courseware.views.index'),
|
||||
url(r'^courseware/(?P<course>[^/]*)/(?P<chapter>[^/]*)/$', 'courseware.views.index'),
|
||||
|
||||
Reference in New Issue
Block a user