-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Logging Feature #72
base: master
Are you sure you want to change the base?
Logging Feature #72
Changes from 5 commits
68f4129
fc0e35c
4af0810
2fb72cf
21beeef
0cf3eb2
d66ecbe
d846abb
3134170
1c9ef6c
a949d49
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from django.contrib import admin | ||
from . import models | ||
|
||
# Register your models here. | ||
|
||
@admin.register(models.Data) | ||
class DataAdmin(admin.ModelAdmin): | ||
pass |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class DataCollectionConfig(AppConfig): | ||
name = 'data_collection' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import factory | ||
from . import models | ||
|
||
|
||
class DataFactory(factory.django.DjangoModelFactory): | ||
class Meta: | ||
model = models.Data | ||
|
||
date_created = factory.LazyFunction(datetime.datetime.now) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from django.conf import settings | ||
from django.db.models import Q | ||
from rest_framework.response import Response | ||
from .models import Data | ||
|
||
def logger(cls, data): | ||
new_data = Data(data_type=cls, log=data) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if the field name is |
||
new_data.save() | ||
return new_data |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.11.7 on 2018-03-14 02:32 | ||
from __future__ import unicode_literals | ||
|
||
import django.contrib.postgres.fields.jsonb | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Data', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('data_type', models.CharField(max_length=100)), | ||
('date_created', models.DateTimeField(auto_now_add=True)), | ||
('log', django.contrib.postgres.fields.jsonb.JSONField()), | ||
], | ||
), | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from django.db import models | ||
from django.contrib.postgres.fields import JSONField | ||
|
||
# Create your models here. | ||
|
||
class Data(models.Model): | ||
data_type = models.CharField(max_length=100, null=False) | ||
date_created = models.DateTimeField(auto_now_add=True) | ||
log = JSONField() | ||
|
||
def __str__(self): | ||
return '%s: %s' % (self.data_type, self.log) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you might want to include the time on the str |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from rest_framework import serializers | ||
from drf_writable_nested import WritableNestedModelSerializer | ||
|
||
from .models import Data | ||
|
||
class DataSerializer(WritableNestedModelSerializer): | ||
class Meta: | ||
model = Data | ||
fields = ('data_type', 'date_created', 'log',) | ||
read_only_fields = ('data_ type', 'date_created', 'log',) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from django.conf.urls import url | ||
|
||
from . import views | ||
|
||
|
||
urlpatterns = [ | ||
url(r'^log/$', views.DataLogView.as_view(), name='log_data'), | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from django.conf import settings | ||
from django.db.models import Q | ||
from rest_framework.response import Response | ||
from .models import Data | ||
from .serializers import DataSerializer | ||
from rest_framework import generics | ||
from . import helpers | ||
|
||
# Create your views here. | ||
class DataLogView(generics.CreateAPIView): | ||
serializer_class = DataSerializer | ||
|
||
def post (self,request): | ||
result = helpers.logger(request.data['data_type'], request.data['log']) | ||
|
||
new_data = Data( | ||
data_type = request.data['data_type'], | ||
log = request.data['log'], | ||
) | ||
new_data.save() | ||
|
||
return Response(DataSerializer(result).data) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
""" | ||
Django settings for pickmybruin project. | ||
|
||
For more information on this file, see | ||
https://docs.djangoproject.com/en/1.6/topics/settings/ | ||
|
||
For the full list of settings and their values, see | ||
https://docs.djangoproject.com/en/1.6/ref/settings/ | ||
""" | ||
|
@@ -46,6 +44,7 @@ | |
'users', | ||
'email_requests', | ||
'messaging', | ||
'data_collection', | ||
) | ||
|
||
AUTHENTICATION_BACKENDS = ( | ||
|
@@ -189,4 +188,4 @@ | |
REQUEST_TEMPLATE = '682f1eee-9441-4baf-aa1b-780281f25694' | ||
USER_VERIFICATION_TEMPLATE = 'ddd14008-25ee-46c6-9a55-b6b4d577a54b' | ||
MESSAGING_TEMPLATE = 'ea29ebe3-df27-4383-9234-0d01539980e3' | ||
PASSWORD_RESET_TEMPLATE = '262bdea5-7921-47b1-946d-7438ee7f865b' | ||
PASSWORD_RESET_TEMPLATE = '262bdea5-7921-47b1-946d-7438ee7f865b' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should this change be in this pull request? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you name this
log
so the function is a verb and not a noun?