Commit c986a2e9e0d1d7051a48f27f54ded722e73ba171
Exists in
master
and in
5 other branches
Merge
Showing
6 changed files
with
48 additions
and
9 deletions
Show diff stats
README.md
... | ... | @@ -80,6 +80,40 @@ Para Classes que envolvem formulários: |
80 | 80 | * `CreateCourseForm` |
81 | 81 | * `UpdateCourseForm()` |
82 | 82 | |
83 | + | |
84 | +##API Description | |
85 | +We are using mostly viewsets ( http://www.django-rest-framework.org/api-guide/viewsets/) to build our API endpoints now, so all default methods and API points were kept. | |
86 | + | |
87 | +* model list(GET) = list all objects from that mode in pagination mode, each page has 10 | |
88 | +* model detail(GET) = give the details of the objects and most important fields of the ones objects its has relationships. | |
89 | +* model create | |
90 | + | |
91 | +**Courses (URL: coursesapi)** | |
92 | +* course list ("/coursesapi/") | |
93 | +* course detail ("/coursesapi/id") (id is a parameter) | |
94 | + | |
95 | +**Subject (URL: subjectapi)** | |
96 | +* subject list ("/subjectapi/") | |
97 | +* subject detail ("/subjectapi/id") (id is a parameter) | |
98 | + | |
99 | +**Topic (URL: topicsapi)** | |
100 | +* topics list ("/topicsapi/") | |
101 | +* topic detail ("/topicsapi/id") (id is a parameter) | |
102 | + | |
103 | +**logs (URL: logs)** | |
104 | +* logs list ("/logs/") | |
105 | +* log detail ("/logs/id") (id is a parameter) | |
106 | + | |
107 | +#Obtaining an Access Token | |
108 | +* First build an application o "amadeus/o/applications" following this tutorial: http://django-oauth-toolkit.readthedocs.io/en/latest/tutorial/tutorial_01.html#create-an-oauth2-client-application | |
109 | + | |
110 | +* Then request, using a valid user, an access token using the following template (you'll have to know how to translate a GET Method into a POST one) | |
111 | +curl -X POST -d "grant_type=password&username=<user_name>&password=<password>" -u"<client_id>:<client_secret>" http://amadeus/o/token/ | |
112 | + | |
113 | +* finally, with your access token you can use test using | |
114 | +curl -H "Authorization: Bearer <your_access_token>" -X POST -d"username=foo&password=bar" http://localhost:8000/users/ (inserting a new user) | |
115 | + | |
116 | + | |
83 | 117 | ## Link's úteis |
84 | 118 | [Git - Introdução e comandos básicos(PT-BR)](https://github.com/fernandomayer/git-rautu/blob/master/0_configuracao-inicial.md) |
85 | 119 | ... | ... |
core/decorators.py
... | ... | @@ -38,7 +38,8 @@ def log_decorator(log_component = '', log_action = '', log_resource = ''): |
38 | 38 | log = Log() |
39 | 39 | log.user = request.user |
40 | 40 | log.component = log_component |
41 | - log.context = json.dumps(request.log_context) | |
41 | + #log.context = json.dumps(request.log_context) | |
42 | + log.context = request.log_context | |
42 | 43 | log.action_resource = action_resource |
43 | 44 | |
44 | 45 | log.save() | ... | ... |
core/middleware.py
... | ... | @@ -26,13 +26,16 @@ class TimeSpentMiddleware(object): |
26 | 26 | secs = secs % 60 |
27 | 27 | |
28 | 28 | log_context = json.loads(log.context) |
29 | + print(log.context) | |
29 | 30 | |
30 | - log_context['time_spent'] = {} | |
31 | - log_context['time_spent']['hours'] = hours | |
32 | - log_context['time_spent']['minutes'] = minutes | |
33 | - log_context['time_spent']['seconds'] = secs | |
31 | + time = {} | |
32 | + time['hours'] = hours | |
33 | + time['minutes'] = minutes | |
34 | + time['seconds'] = secs | |
34 | 35 | |
35 | - log.context = json.dumps(log_context) | |
36 | + log_context['time_spent'] = time | |
37 | + | |
38 | + log.context = log_context | |
36 | 39 | |
37 | 40 | log.save() |
38 | 41 | ... | ... |
core/mixins.py
core/models.py
... | ... | @@ -2,6 +2,7 @@ from django.db import models |
2 | 2 | from django.utils.translation import ugettext_lazy as _ |
3 | 3 | from users.models import User |
4 | 4 | from autoslug.fields import AutoSlugField |
5 | +from django.contrib.postgres.fields import JSONField | |
5 | 6 | # Create your models here. |
6 | 7 | |
7 | 8 | class MimeType(models.Model): |
... | ... | @@ -102,7 +103,7 @@ class Notification(models.Model): |
102 | 103 | |
103 | 104 | class Log(models.Model): |
104 | 105 | component = models.TextField(_('Component (Module / App)')) |
105 | - context = models.TextField(_('Context'), blank = True) | |
106 | + context = JSONField(_('Context'), blank = True) | |
106 | 107 | action_resource = models.ForeignKey(Action_Resource, verbose_name = _('Action_Resource')) |
107 | 108 | user = models.ForeignKey(User, verbose_name = _('Actor')) |
108 | 109 | datetime = models.DateTimeField(_("Date and Time of action"), auto_now_add = True) | ... | ... |
core/views.py
... | ... | @@ -20,7 +20,6 @@ from rest_framework import status, serializers, permissions, viewsets |
20 | 20 | from rest_framework.response import Response |
21 | 21 | from rest_framework.decorators import api_view |
22 | 22 | |
23 | - | |
24 | 23 | from .forms import RegisterUserForm |
25 | 24 | from .decorators import log_decorator, notification_decorator |
26 | 25 | ... | ... |