Merge pull request #318 from MITx/pmitros/minidash
Miniature staff dashboard. Not really tested, but should be safe to merge
This commit is contained in:
0
lms/djangoapps/dashboard/__init__.py
Normal file
0
lms/djangoapps/dashboard/__init__.py
Normal file
3
lms/djangoapps/dashboard/models.py
Normal file
3
lms/djangoapps/dashboard/models.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
16
lms/djangoapps/dashboard/tests.py
Normal file
16
lms/djangoapps/dashboard/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)
|
||||
31
lms/djangoapps/dashboard/views.py
Normal file
31
lms/djangoapps/dashboard/views.py
Normal file
@@ -0,0 +1,31 @@
|
||||
# Create your views here.
|
||||
import json
|
||||
from datetime import datetime
|
||||
from django.http import HttpResponse, Http404
|
||||
|
||||
def dictfetchall(cursor):
|
||||
'''Returns all rows from a cursor as a dict.
|
||||
Borrowed from Django documentation'''
|
||||
desc = cursor.description
|
||||
return [
|
||||
dict(zip([col[0] for col in desc], row))
|
||||
for row in cursor.fetchall()
|
||||
]
|
||||
|
||||
def dashboard(request):
|
||||
"""
|
||||
Quick hack to show staff enrollment numbers. This should be
|
||||
replaced with a real dashboard later. This version is a short-term
|
||||
bandaid for the next couple weeks.
|
||||
"""
|
||||
if not request.user.is_staff:
|
||||
raise Http404
|
||||
|
||||
query = "select count(user_id) as students, course_id from student_courseenrollment group by course_id order by students desc"
|
||||
|
||||
from django.db import connection
|
||||
cursor = connection.cursor()
|
||||
results = dictfetchall(cursor.execute(query))
|
||||
|
||||
|
||||
return HttpResponse(json.dumps(results, indent=4))
|
||||
@@ -13,6 +13,7 @@ if settings.DEBUG:
|
||||
urlpatterns = ('',
|
||||
url(r'^$', 'student.views.index', name="root"), # Main marketing page, or redirect to courseware
|
||||
url(r'^dashboard$', 'student.views.dashboard', name="dashboard"),
|
||||
url(r'^admin_dashboard$', 'dashboard.views.dashboard'),
|
||||
|
||||
url(r'^change_email$', 'student.views.change_email_request'),
|
||||
url(r'^email_confirm/(?P<key>[^/]*)$', 'student.views.confirm_email_change'),
|
||||
|
||||
Reference in New Issue
Block a user