Commit 252e7ebb59aa0ab8e065f81b106976261f02d28d
1 parent
3f007a5f
Exists in
master
and in
5 other branches
added api log list call
Showing
3 changed files
with
35 additions
and
2 deletions
Show diff stats
core/urls.py
@@ -13,6 +13,9 @@ urlpatterns = [ | @@ -13,6 +13,9 @@ urlpatterns = [ | ||
13 | url(r'^getNotifications/$', views.getNotifications, name='getNotifications'), | 13 | url(r'^getNotifications/$', views.getNotifications, name='getNotifications'), |
14 | url(r'^guest/$', views.GuestView.as_view(), name='guest'), | 14 | url(r'^guest/$', views.GuestView.as_view(), name='guest'), |
15 | 15 | ||
16 | + #API REST | ||
17 | + url(r'^logs/$', views.get_log), | ||
18 | + | ||
16 | #Reset Password | 19 | #Reset Password |
17 | 20 | ||
18 | url(r'^reset/$', password_reset, {'template_name':'registration/passwor_reset_form.html', | 21 | url(r'^reset/$', password_reset, {'template_name':'registration/passwor_reset_form.html', |
@@ -25,4 +28,5 @@ urlpatterns = [ | @@ -25,4 +28,5 @@ urlpatterns = [ | ||
25 | 'post_reset_redirect' : '/done/'}, | 28 | 'post_reset_redirect' : '/done/'}, |
26 | name='password_reset_confirm'), | 29 | name='password_reset_confirm'), |
27 | url(r'^done/$', password_reset_complete,{'template_name':'registration/passwor_reset_complete.html'}), | 30 | url(r'^done/$', password_reset_complete,{'template_name':'registration/passwor_reset_complete.html'}), |
31 | + | ||
28 | ] | 32 | ] |
core/views.py
@@ -11,8 +11,13 @@ from django.http import HttpResponse, JsonResponse | @@ -11,8 +11,13 @@ from django.http import HttpResponse, JsonResponse | ||
11 | from django.core.mail import send_mail,BadHeaderError | 11 | from django.core.mail import send_mail,BadHeaderError |
12 | from django.conf import settings | 12 | from django.conf import settings |
13 | from core.mixins import NotificationMixin | 13 | from core.mixins import NotificationMixin |
14 | -from .models import Notification | 14 | +from .models import Notification, Log |
15 | from rolepermissions.shortcuts import assign_role | 15 | from rolepermissions.shortcuts import assign_role |
16 | +from django.contrib.auth.decorators import login_required | ||
17 | +#API REST IMPORTS | ||
18 | +from .serializers import LogSerializer | ||
19 | +from rest_framework.renderers import JSONRenderer | ||
20 | +from rest_framework.parsers import JSONParser | ||
16 | 21 | ||
17 | from .forms import RegisterUserForm | 22 | from .forms import RegisterUserForm |
18 | from .decorators import log_decorator, notification_decorator | 23 | from .decorators import log_decorator, notification_decorator |
@@ -128,4 +133,21 @@ class GuestView (ListView): | @@ -128,4 +133,21 @@ class GuestView (ListView): | ||
128 | def get_context_data (self, **kwargs): | 133 | def get_context_data (self, **kwargs): |
129 | context = super(GuestView, self).get_context_data(**kwargs) | 134 | context = super(GuestView, self).get_context_data(**kwargs) |
130 | context['categorys_courses'] = CourseCategory.objects.all() | 135 | context['categorys_courses'] = CourseCategory.objects.all() |
131 | - return context | ||
132 | \ No newline at end of file | 136 | \ No newline at end of file |
137 | + return context | ||
138 | + | ||
139 | +class JSONResponse(HttpResponse): | ||
140 | + """ | ||
141 | + An HttpResponse that renders its content into JSON. | ||
142 | + """ | ||
143 | + def __init__(self, data, **kwargs): | ||
144 | + content = JSONRenderer().render(data) | ||
145 | + kwargs['content_type'] = 'application/json' | ||
146 | + super(JSONResponse, self).__init__(content, **kwargs) | ||
147 | + | ||
148 | +#REST API VIEWS | ||
149 | +@login_required | ||
150 | +def get_log(request): | ||
151 | + if request.method == 'GET': | ||
152 | + logs = Log.objects.all() | ||
153 | + serializer = LogSerializer(logs, many=True) | ||
154 | + return JSONResponse(serializer.data) |