Commit 60d308d7d60762a034fc8ba6c3f42ba8f986903c
1 parent
a53fdfc8
Exists in
master
and in
3 other branches
whole report url is set up for GET parameters and it's answer is comming as a JS…
…ON data into a template, not showing the data yet.
Showing
4 changed files
with
60 additions
and
2 deletions
Show diff stats
amadeus/urls.py
@@ -25,7 +25,7 @@ urlpatterns = [ | @@ -25,7 +25,7 @@ urlpatterns = [ | ||
25 | url(r'^users/', include('users.urls', namespace = 'users')), | 25 | url(r'^users/', include('users.urls', namespace = 'users')), |
26 | url(r'^admin/', admin.site.urls), | 26 | url(r'^admin/', admin.site.urls), |
27 | url(r'^$', index, name = 'home'), | 27 | url(r'^$', index, name = 'home'), |
28 | - url(r'api/', include('api.urls', namespace = 'api')), | 28 | + url(r'^api/', include('api.urls', namespace = 'api')), |
29 | url(r'^categories/', include('categories.urls', namespace = 'categories')), | 29 | url(r'^categories/', include('categories.urls', namespace = 'categories')), |
30 | url(r'^subjects/', include('subjects.urls', namespace = 'subjects')), | 30 | url(r'^subjects/', include('subjects.urls', namespace = 'subjects')), |
31 | url(r'^groups/', include('students_group.urls', namespace = 'groups')), | 31 | url(r'^groups/', include('students_group.urls', namespace = 'groups')), |
@@ -0,0 +1,16 @@ | @@ -0,0 +1,16 @@ | ||
1 | +{% extends 'base.html' %} | ||
2 | + | ||
3 | +{% load static i18n pagination %} | ||
4 | +{% load django_bootstrap_breadcrumbs %} | ||
5 | + | ||
6 | +{% block breadcrumbs %} | ||
7 | + {{ block.super }} | ||
8 | + | ||
9 | + {% trans 'Mural: General' as general %} | ||
10 | + | ||
11 | + {% breadcrumb general 'mural:manage_general' %} | ||
12 | +{% endblock %} | ||
13 | + | ||
14 | +{% block content %} | ||
15 | + | ||
16 | +{% endblock content %} | ||
0 | \ No newline at end of file | 17 | \ No newline at end of file |
api/urls.py
@@ -6,6 +6,7 @@ from rest_framework import routers | @@ -6,6 +6,7 @@ from rest_framework import routers | ||
6 | 6 | ||
7 | from users.views import UserViewSet | 7 | from users.views import UserViewSet |
8 | from log.views import LogViewSet | 8 | from log.views import LogViewSet |
9 | +from . import views | ||
9 | 10 | ||
10 | router = routers.DefaultRouter() | 11 | router = routers.DefaultRouter() |
11 | router.register(r'logs', LogViewSet) | 12 | router.register(r'logs', LogViewSet) |
@@ -13,5 +14,7 @@ router.register(r'usersapi', UserViewSet) | @@ -13,5 +14,7 @@ router.register(r'usersapi', UserViewSet) | ||
13 | 14 | ||
14 | urlpatterns = [ | 15 | urlpatterns = [ |
15 | #API REST | 16 | #API REST |
17 | + url(r'^report/$', views.ReportView.as_view(), name='report'), | ||
18 | + | ||
16 | url(r'^', include(router.urls)), | 19 | url(r'^', include(router.urls)), |
17 | ] | 20 | ] |
18 | \ No newline at end of file | 21 | \ No newline at end of file |
api/views.py
1 | from django.shortcuts import render | 1 | from django.shortcuts import render |
2 | +from django.http import HttpResponse, JsonResponse | ||
2 | 3 | ||
3 | -# Create your views here. | 4 | + |
5 | +import django.views.generic as generic | ||
6 | +from mural.models import SubjectPost | ||
7 | +from django.db.models import Q | ||
8 | +from django.contrib.auth.mixins import LoginRequiredMixin | ||
9 | +from datetime import datetime, date | ||
10 | +from subjects.models import Subject | ||
11 | + | ||
12 | +class ReportView(LoginRequiredMixin, generic.TemplateView): | ||
13 | + template_name = "api/report.html" | ||
14 | + | ||
15 | + def get_context_data(self, **kwargs): | ||
16 | + context = {} | ||
17 | + params = self.request.GET | ||
18 | + | ||
19 | + if params['subject_id'] and params['init_date'] and params['end_date']: | ||
20 | + subject_id = params['subject_id'] | ||
21 | + subject = Subject.objects.get(id=subject_id) | ||
22 | + data = {} | ||
23 | + students = subject.students.all() | ||
24 | + formats = ["%d/%m/%Y", "%m/%d/%Y"] #so it accepts english and portuguese date formats | ||
25 | + for fmt in formats: | ||
26 | + try: | ||
27 | + init_date = datetime.strptime(params['init_date'], fmt) | ||
28 | + end_date = datetime.strptime(params['end_date'], fmt) | ||
29 | + except ValueError: | ||
30 | + pass | ||
31 | + | ||
32 | + for student in students: | ||
33 | + interactions = {} | ||
34 | + | ||
35 | + interactions['doubts'] = SubjectPost.objects.filter(action="help", create_date__range=(init_date, end_date), | ||
36 | + space__id=subject_id, user=student).count() | ||
37 | + data[student] = interactions | ||
38 | + | ||
39 | + print(data) | ||
40 | + | ||
41 | + | ||
42 | + return context |