Skip to content
Snippets Groups Projects
Commit 4355de79 authored by Piotr Mitros's avatar Piotr Mitros
Browse files

Tracking is partially in place

parent 55f8c587
No related branches found
No related tags found
No related merge requests found
......@@ -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:
......
from django.db import models
# Create your models here.
"""
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)
# 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)
......@@ -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'),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment