Skip to content

Commit

Permalink
adding new users numbers and filters
Browse files Browse the repository at this point in the history
  • Loading branch information
CelineBoudier committed Mar 1, 2016
1 parent c3f6ed6 commit 9f06f5d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
14 changes: 13 additions & 1 deletion portal/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
# program; modified versions of the program must be marked as such and not
# identified as the original program.
from django.contrib import admin
from django.contrib.auth.models import User
from django.contrib.auth.admin import UserAdmin


from portal.models import Class, Student, Guardian, Teacher, School, UserProfile, FrontPageNews


Expand All @@ -54,13 +58,21 @@ class TeacherAdmin(admin.ModelAdmin):


class UserProfileAdmin(admin.ModelAdmin):
search_fields = ['user__first_name', 'user__last_name', 'user__username']
search_fields = ['user__first_name', 'user__last_name', 'user__username', 'user__date_joined']
list_filter = ['user__date_joined']
list_display = ['user', 'joined_recently']


UserAdmin.list_display += ('date_joined',)
UserAdmin.list_filter += ('date_joined',)


admin.site.register(Class, ClassAdmin)
admin.site.register(Student, StudentAdmin)
admin.site.register(Guardian)
admin.site.register(Teacher, TeacherAdmin)
admin.site.register(School)
admin.site.unregister(User)
admin.site.register(User, UserAdmin)
admin.site.register(UserProfile, UserProfileAdmin)
admin.site.register(FrontPageNews)
6 changes: 6 additions & 0 deletions portal/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@
from __future__ import absolute_import

import re
import datetime

from django.contrib.auth.models import User
from django.db import models
from django_countries.fields import CountryField
from django.core.cache import cache
from django.utils import timezone

from online_status.status import CACHE_USERS

Expand All @@ -55,6 +57,10 @@ class UserProfile(models.Model):
def __unicode__(self):
return self.user.username

def joined_recently(self):
now = timezone.now()
return now - datetime.timedelta(days=7) <= self.user.date_joined


class School(models.Model):
name = models.CharField(max_length=200)
Expand Down
2 changes: 2 additions & 0 deletions portal/views/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ def aggregated_data(request):

teacher_count = Teacher.objects.count()
student_count = Student.objects.count()
new_profiles = len([user for user in UserProfile.objects.all() if user.joined_recently()])

table_data.append(["Number of users", teacher_count+student_count, "Number of teachers + Number of students"])
table_data.append(["Number of new users (past week)", new_profiles, "Number of teachers + Number of students"])

tables.append({'title': "Overall Statistics", 'description': "CFL site overall statistics", 'header': table_head, 'data': table_data})

Expand Down

0 comments on commit 9f06f5d

Please sign in to comment.