Commit c986a2e9e0d1d7051a48f27f54ded722e73ba171

Authored by ailsoncgt
2 parents 44984d78 038e9d21

Merge

@@ -80,6 +80,40 @@ Para Classes que envolvem formulários: @@ -80,6 +80,40 @@ Para Classes que envolvem formulários:
80 * `CreateCourseForm` 80 * `CreateCourseForm`
81 * `UpdateCourseForm()` 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 ## Link's úteis 117 ## Link's úteis
84 [Git - Introdução e comandos básicos(PT-BR)](https://github.com/fernandomayer/git-rautu/blob/master/0_configuracao-inicial.md) 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 = &#39;&#39;, log_action = &#39;&#39;, log_resource = &#39;&#39;): @@ -38,7 +38,8 @@ def log_decorator(log_component = &#39;&#39;, log_action = &#39;&#39;, log_resource = &#39;&#39;):
38 log = Log() 38 log = Log()
39 log.user = request.user 39 log.user = request.user
40 log.component = log_component 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 log.action_resource = action_resource 43 log.action_resource = action_resource
43 44
44 log.save() 45 log.save()
core/middleware.py
@@ -26,13 +26,16 @@ class TimeSpentMiddleware(object): @@ -26,13 +26,16 @@ class TimeSpentMiddleware(object):
26 secs = secs % 60 26 secs = secs % 60
27 27
28 log_context = json.loads(log.context) 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 log.save() 40 log.save()
38 41
core/mixins.py
@@ -36,7 +36,8 @@ class LogMixin(object): @@ -36,7 +36,8 @@ class LogMixin(object):
36 36
37 log = Log() 37 log = Log()
38 log.user = actor 38 log.user = actor
39 - log.context = json.dumps(context) 39 + #log.context = json.dumps(context)
  40 + log.context = context
40 log.component = component 41 log.component = component
41 log.action_resource = action_resource 42 log.action_resource = action_resource
42 43
core/models.py
@@ -2,6 +2,7 @@ from django.db import models @@ -2,6 +2,7 @@ from django.db import models
2 from django.utils.translation import ugettext_lazy as _ 2 from django.utils.translation import ugettext_lazy as _
3 from users.models import User 3 from users.models import User
4 from autoslug.fields import AutoSlugField 4 from autoslug.fields import AutoSlugField
  5 +from django.contrib.postgres.fields import JSONField
5 # Create your models here. 6 # Create your models here.
6 7
7 class MimeType(models.Model): 8 class MimeType(models.Model):
@@ -102,7 +103,7 @@ class Notification(models.Model): @@ -102,7 +103,7 @@ class Notification(models.Model):
102 103
103 class Log(models.Model): 104 class Log(models.Model):
104 component = models.TextField(_('Component (Module / App)')) 105 component = models.TextField(_('Component (Module / App)'))
105 - context = models.TextField(_('Context'), blank = True) 106 + context = JSONField(_('Context'), blank = True)
106 action_resource = models.ForeignKey(Action_Resource, verbose_name = _('Action_Resource')) 107 action_resource = models.ForeignKey(Action_Resource, verbose_name = _('Action_Resource'))
107 user = models.ForeignKey(User, verbose_name = _('Actor')) 108 user = models.ForeignKey(User, verbose_name = _('Actor'))
108 datetime = models.DateTimeField(_("Date and Time of action"), auto_now_add = True) 109 datetime = models.DateTimeField(_("Date and Time of action"), auto_now_add = True)
@@ -20,7 +20,6 @@ from rest_framework import status, serializers, permissions, viewsets @@ -20,7 +20,6 @@ from rest_framework import status, serializers, permissions, viewsets
20 from rest_framework.response import Response 20 from rest_framework.response import Response
21 from rest_framework.decorators import api_view 21 from rest_framework.decorators import api_view
22 22
23 -  
24 from .forms import RegisterUserForm 23 from .forms import RegisterUserForm
25 from .decorators import log_decorator, notification_decorator 24 from .decorators import log_decorator, notification_decorator
26 25