From 68f4129de981b6e52fb6fcbcb5367328b3783d0d Mon Sep 17 00:00:00 2001 From: sgrewal12 Date: Sat, 10 Mar 2018 14:31:32 -0800 Subject: [PATCH 1/9] Data Logger App --- src/data_collection/__init__.py | 0 src/data_collection/admin.py | 3 +++ src/data_collection/apps.py | 5 +++++ src/data_collection/factories.py | 9 +++++++++ src/data_collection/helpers.py | 14 ++++++++++++++ src/data_collection/models.py | 12 ++++++++++++ src/data_collection/serializers.py | 10 ++++++++++ src/data_collection/urls.py | 8 ++++++++ src/data_collection/views.py | 15 +++++++++++++++ src/pickmybruin/settings.py | 1 + src/pickmybruin/urls.py | 1 + src/users/views.py | 3 +++ 12 files changed, 81 insertions(+) create mode 100644 src/data_collection/__init__.py create mode 100644 src/data_collection/admin.py create mode 100644 src/data_collection/apps.py create mode 100644 src/data_collection/factories.py create mode 100644 src/data_collection/helpers.py create mode 100644 src/data_collection/models.py create mode 100644 src/data_collection/serializers.py create mode 100644 src/data_collection/urls.py create mode 100644 src/data_collection/views.py diff --git a/src/data_collection/__init__.py b/src/data_collection/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/data_collection/admin.py b/src/data_collection/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/src/data_collection/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/src/data_collection/apps.py b/src/data_collection/apps.py new file mode 100644 index 0000000..638bf5c --- /dev/null +++ b/src/data_collection/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class DataCollectionConfig(AppConfig): + name = 'data_collection' diff --git a/src/data_collection/factories.py b/src/data_collection/factories.py new file mode 100644 index 0000000..d24db16 --- /dev/null +++ b/src/data_collection/factories.py @@ -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) \ No newline at end of file diff --git a/src/data_collection/helpers.py b/src/data_collection/helpers.py new file mode 100644 index 0000000..33aa2c0 --- /dev/null +++ b/src/data_collection/helpers.py @@ -0,0 +1,14 @@ +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 + +#def logger(type='', request): +def logger(self): + new_data = Data( + log = self.request.GET['major'], + ) + new_data.save() + + return Response(DataSerializer(new_data).data) \ No newline at end of file diff --git a/src/data_collection/models.py b/src/data_collection/models.py new file mode 100644 index 0000000..4f8550e --- /dev/null +++ b/src/data_collection/models.py @@ -0,0 +1,12 @@ +from django.db import models +from django.contrib.postgres.fields import JSONField + +# Create your models here. + +class Data(models.Model): + date_created = models.DateTimeField(auto_now_add=True) + #type + log = JSONField() + + def __str__(self): + return '%d: %s' % (self.ID, str(self.log)) \ No newline at end of file diff --git a/src/data_collection/serializers.py b/src/data_collection/serializers.py new file mode 100644 index 0000000..4cd971a --- /dev/null +++ b/src/data_collection/serializers.py @@ -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 = ('ID', 'date_created', 'log',) + read_only_fields = ('ID', 'date_created', 'log',) \ No newline at end of file diff --git a/src/data_collection/urls.py b/src/data_collection/urls.py new file mode 100644 index 0000000..fd2cd86 --- /dev/null +++ b/src/data_collection/urls.py @@ -0,0 +1,8 @@ +from django.conf.urls import url + +from . import views + + +urlpatterns = [ + url(r'^log/$', views.DataLogView.as_view(), name='log_data'), +] diff --git a/src/data_collection/views.py b/src/data_collection/views.py new file mode 100644 index 0000000..ca40ca0 --- /dev/null +++ b/src/data_collection/views.py @@ -0,0 +1,15 @@ +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): + result = helpers.logger(self); + return result \ No newline at end of file diff --git a/src/pickmybruin/settings.py b/src/pickmybruin/settings.py index c3c567f..9bff2b2 100644 --- a/src/pickmybruin/settings.py +++ b/src/pickmybruin/settings.py @@ -45,6 +45,7 @@ # Pick My Bruin Apps 'users', 'email_requests', + 'data_collection', ) AUTHENTICATION_BACKENDS = ( diff --git a/src/pickmybruin/urls.py b/src/pickmybruin/urls.py index 7d0ff2a..59ec954 100644 --- a/src/pickmybruin/urls.py +++ b/src/pickmybruin/urls.py @@ -19,4 +19,5 @@ url(r'', include('users.urls', namespace='users')), url(r'^o/', include('oauth2_provider.urls', namespace='oauth2_provider')), url(r'^requests/', include('email_requests.urls', namespace='email_requests')), + url(r'^data/', include('data_collection.urls', namespace='data_collection')), ] diff --git a/src/users/views.py b/src/users/views.py index 6c39897..76fff5c 100644 --- a/src/users/views.py +++ b/src/users/views.py @@ -26,6 +26,7 @@ import sendgrid from sendgrid.helpers.mail import Email, Content, Substitution, Mail from pickmybruin.settings import USER_VERIFICATION_TEMPLATE +from data_collection.views import DataLogView class UserViewSet(viewsets.ModelViewSet): """ @@ -185,6 +186,8 @@ def filter_queryset(self, queryset): if 'year' in self.request.GET: year = self.request.GET['year'] + #DataLogView(self) + q = Q() if major != 'all': q &= Q(major__name=major) From 4af0810d200523e32a5794dfff65f3254d71cf50 Mon Sep 17 00:00:00 2001 From: sgrewal12 Date: Mon, 30 Apr 2018 20:43:16 -0700 Subject: [PATCH 2/9] Final Logging Changes --- src/data_collection/admin.py | 5 ++++ src/data_collection/helpers.py | 12 +++------ .../migrations/0001_initial.py | 26 +++++++++++++++++++ src/data_collection/migrations/__init__.py | 0 src/data_collection/models.py | 4 +-- src/data_collection/serializers.py | 8 +++--- src/data_collection/views.py | 15 ++++++++--- src/users/views.py | 3 +++ 8 files changed, 55 insertions(+), 18 deletions(-) create mode 100644 src/data_collection/migrations/0001_initial.py create mode 100644 src/data_collection/migrations/__init__.py diff --git a/src/data_collection/admin.py b/src/data_collection/admin.py index 8c38f3f..a9bf649 100644 --- a/src/data_collection/admin.py +++ b/src/data_collection/admin.py @@ -1,3 +1,8 @@ from django.contrib import admin +from . import models # Register your models here. + +@admin.register(models.Data) +class DataAdmin(admin.ModelAdmin): + pass \ No newline at end of file diff --git a/src/data_collection/helpers.py b/src/data_collection/helpers.py index 33aa2c0..63cb401 100644 --- a/src/data_collection/helpers.py +++ b/src/data_collection/helpers.py @@ -2,13 +2,9 @@ from django.db.models import Q from rest_framework.response import Response from .models import Data -from .serializers import DataSerializer -#def logger(type='', request): -def logger(self): - new_data = Data( - log = self.request.GET['major'], - ) +#Master +def logger(cls, data): + new_data = Data(data_type=cls, log=data) new_data.save() - - return Response(DataSerializer(new_data).data) \ No newline at end of file + return new_data \ No newline at end of file diff --git a/src/data_collection/migrations/0001_initial.py b/src/data_collection/migrations/0001_initial.py new file mode 100644 index 0000000..c693893 --- /dev/null +++ b/src/data_collection/migrations/0001_initial.py @@ -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()), + ], + ), + ] diff --git a/src/data_collection/migrations/__init__.py b/src/data_collection/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/data_collection/models.py b/src/data_collection/models.py index 4f8550e..1d3e6ee 100644 --- a/src/data_collection/models.py +++ b/src/data_collection/models.py @@ -4,9 +4,9 @@ # 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) - #type log = JSONField() def __str__(self): - return '%d: %s' % (self.ID, str(self.log)) \ No newline at end of file + return '%s: %s' % (self.data_type, self.log) \ No newline at end of file diff --git a/src/data_collection/serializers.py b/src/data_collection/serializers.py index 4cd971a..855450b 100644 --- a/src/data_collection/serializers.py +++ b/src/data_collection/serializers.py @@ -4,7 +4,7 @@ from .models import Data class DataSerializer(WritableNestedModelSerializer): - class Meta: - model = Data - fields = ('ID', 'date_created', 'log',) - read_only_fields = ('ID', 'date_created', 'log',) \ No newline at end of file + class Meta: + model = Data + fields = ('data_type', 'date_created', 'log',) + read_only_fields = ('data_ type', 'date_created', 'log',) \ No newline at end of file diff --git a/src/data_collection/views.py b/src/data_collection/views.py index ca40ca0..8a67b9e 100644 --- a/src/data_collection/views.py +++ b/src/data_collection/views.py @@ -8,8 +8,15 @@ # Create your views here. class DataLogView(generics.CreateAPIView): - serializer_class = DataSerializer + serializer_class = DataSerializer - def post(self): - result = helpers.logger(self); - return result \ No newline at end of file + 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) \ No newline at end of file diff --git a/src/users/views.py b/src/users/views.py index f48995e..5701ff1 100644 --- a/src/users/views.py +++ b/src/users/views.py @@ -27,6 +27,7 @@ import sendgrid from sendgrid.helpers.mail import Email, Content, Substitution, Mail from pickmybruin.settings import USER_VERIFICATION_TEMPLATE, PASSWORD_RESET_TEMPLATE +from data_collection.helpers import logger class UserViewSet(viewsets.ModelViewSet): """ @@ -236,6 +237,8 @@ def filter_queryset(self, queryset): if 'year' in self.request.GET: year = self.request.GET['year'] + logger('Majors', {'major': major}) + q = Q() if major != 'all': q &= Q(major__name=major) From 2fb72cf18b15c79b6960c37d0443e75840b29070 Mon Sep 17 00:00:00 2001 From: sgrewal12 Date: Mon, 30 Apr 2018 21:15:02 -0700 Subject: [PATCH 3/9] Removed Unnecessary Comment --- src/data_collection/helpers.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/data_collection/helpers.py b/src/data_collection/helpers.py index 63cb401..5efc9c8 100644 --- a/src/data_collection/helpers.py +++ b/src/data_collection/helpers.py @@ -3,7 +3,6 @@ from rest_framework.response import Response from .models import Data -#Master def logger(cls, data): new_data = Data(data_type=cls, log=data) new_data.save() From 21beeefa359440e8026b9baa9726a7a19173e279 Mon Sep 17 00:00:00 2001 From: sgrewal12 Date: Mon, 30 Apr 2018 21:39:37 -0700 Subject: [PATCH 4/9] Added App to settings --- src/pickmybruin/settings.py | 1 + src/pickmybruin/urls.py | 1 + 2 files changed, 2 insertions(+) diff --git a/src/pickmybruin/settings.py b/src/pickmybruin/settings.py index 6e53c2e..47c1aed 100644 --- a/src/pickmybruin/settings.py +++ b/src/pickmybruin/settings.py @@ -44,6 +44,7 @@ 'users', 'email_requests', 'messaging', + 'data_collection', ) AUTHENTICATION_BACKENDS = ( diff --git a/src/pickmybruin/urls.py b/src/pickmybruin/urls.py index 361a77e..df9aca9 100644 --- a/src/pickmybruin/urls.py +++ b/src/pickmybruin/urls.py @@ -20,4 +20,5 @@ url(r'^o/', include('oauth2_provider.urls', namespace='oauth2_provider')), url(r'^requests/', include('email_requests.urls', namespace='email_requests')), url(r'^messaging/', include('messaging.urls', namespace='messaging')), + url(r'^data/', include('data_collection.urls', namespace='data_collection')), ] \ No newline at end of file From 0cf3eb25c33845e815605c6a72b25861e03b5a0e Mon Sep 17 00:00:00 2001 From: sgrewal12 Date: Wed, 9 May 2018 17:40:40 -0700 Subject: [PATCH 5/9] Changed helper function details --- src/data_collection/helpers.py | 4 ++-- src/data_collection/models.py | 4 +++- src/data_collection/views.py | 2 +- src/pickmybruin/settings.py | 2 +- src/users/views.py | 4 ++-- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/data_collection/helpers.py b/src/data_collection/helpers.py index 5efc9c8..01b17e8 100644 --- a/src/data_collection/helpers.py +++ b/src/data_collection/helpers.py @@ -3,7 +3,7 @@ from rest_framework.response import Response from .models import Data -def logger(cls, data): - new_data = Data(data_type=cls, log=data) +def log(data_type, data): + new_data = Data(data_type=data_type, log=data) new_data.save() return new_data \ No newline at end of file diff --git a/src/data_collection/models.py b/src/data_collection/models.py index 1d3e6ee..4e7edfa 100644 --- a/src/data_collection/models.py +++ b/src/data_collection/models.py @@ -1,5 +1,7 @@ from django.db import models from django.contrib.postgres.fields import JSONField +from datetime import datetime +import pytz # Create your models here. @@ -9,4 +11,4 @@ class Data(models.Model): log = JSONField() def __str__(self): - return '%s: %s' % (self.data_type, self.log) \ No newline at end of file + return '%s: %s %s' % (self.data_type, self.log, datetime.now(pytz.timezone('US/Pacific'))) diff --git a/src/data_collection/views.py b/src/data_collection/views.py index 8a67b9e..415ece7 100644 --- a/src/data_collection/views.py +++ b/src/data_collection/views.py @@ -11,7 +11,7 @@ class DataLogView(generics.CreateAPIView): serializer_class = DataSerializer def post (self,request): - result = helpers.logger(request.data['data_type'], request.data['log']) + result = helpers.log(request.data['data_type'], request.data['log']) new_data = Data( data_type = request.data['data_type'], diff --git a/src/pickmybruin/settings.py b/src/pickmybruin/settings.py index 47c1aed..1e7cb3e 100644 --- a/src/pickmybruin/settings.py +++ b/src/pickmybruin/settings.py @@ -188,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' \ No newline at end of file +PASSWORD_RESET_TEMPLATE = '262bdea5-7921-47b1-946d-7438ee7f865b' diff --git a/src/users/views.py b/src/users/views.py index 5701ff1..88bca4f 100644 --- a/src/users/views.py +++ b/src/users/views.py @@ -27,7 +27,7 @@ import sendgrid from sendgrid.helpers.mail import Email, Content, Substitution, Mail from pickmybruin.settings import USER_VERIFICATION_TEMPLATE, PASSWORD_RESET_TEMPLATE -from data_collection.helpers import logger +from data_collection.helpers import log class UserViewSet(viewsets.ModelViewSet): """ @@ -237,7 +237,7 @@ def filter_queryset(self, queryset): if 'year' in self.request.GET: year = self.request.GET['year'] - logger('Majors', {'major': major}) + log('Majors', {'major': major}) q = Q() if major != 'all': From d66ecbe5642a04eef638e3bfe51ce2e131dc8d0c Mon Sep 17 00:00:00 2001 From: sgrewal12 Date: Wed, 9 May 2018 17:52:27 -0700 Subject: [PATCH 6/9] Updated Time Log --- src/data_collection/models.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/data_collection/models.py b/src/data_collection/models.py index 4e7edfa..8e4302a 100644 --- a/src/data_collection/models.py +++ b/src/data_collection/models.py @@ -1,7 +1,5 @@ from django.db import models from django.contrib.postgres.fields import JSONField -from datetime import datetime -import pytz # Create your models here. @@ -11,4 +9,4 @@ class Data(models.Model): log = JSONField() def __str__(self): - return '%s: %s %s' % (self.data_type, self.log, datetime.now(pytz.timezone('US/Pacific'))) + return '%s: %s %s' % (self.data_type, self.log, self.date_created) From 31341700223285d10dac928fe89d6f3a3f823caa Mon Sep 17 00:00:00 2001 From: Craig Scott Date: Wed, 27 Feb 2019 19:06:43 -0800 Subject: [PATCH 7/9] Merged master --- src/users/views.py | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/src/users/views.py b/src/users/views.py index 2422623..fcfabd9 100644 --- a/src/users/views.py +++ b/src/users/views.py @@ -237,27 +237,6 @@ class MentorsSearchView(generics.ListAPIView): def filter_queryset(self, queryset): queryset = queryset.exclude(profile__user=self.request.user) -<<<<<<< HEAD - major = 'all' - year = 'all' - - if 'major' in self.request.GET: - major = self.request.GET['major'] - if 'year' in self.request.GET: - year = self.request.GET['year'] - - log('Majors', {'major': major}) - - q = Q() - if major != 'all': - q &= Q(major__name=major) - if year != 'all': - q &= Q(profile__year=year) - - queryset = queryset.filter(q) - - -======= trans_dict = { 'first' : '1st', 'second' : '2nd', From 1c9ef6cd9478f667c3a262bb51c03df32750e750 Mon Sep 17 00:00:00 2001 From: Craig Scott Date: Wed, 27 Feb 2019 19:08:20 -0800 Subject: [PATCH 8/9] Removed hanging merge text --- src/users/views.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/users/views.py b/src/users/views.py index fcfabd9..11c160b 100644 --- a/src/users/views.py +++ b/src/users/views.py @@ -283,9 +283,7 @@ def filter_queryset(self, queryset): ) ).filter(similarity__gte=0.10).order_by('-similarity') - ->>>>>>> origin/master if 'random' in self.request.GET: num_random = self.request.GET['random'] if num_random.isdigit(): @@ -293,9 +291,7 @@ def filter_queryset(self, queryset): else: num_random = queryset.count() queryset = queryset.order_by('?')[:num_random] - return queryset - class MentorView(generics.RetrieveAPIView): """ From a949d49a106c2e2cf76bee3e9f7b40073d60f674 Mon Sep 17 00:00:00 2001 From: Craig Scott Date: Wed, 27 Feb 2019 19:09:32 -0800 Subject: [PATCH 9/9] Deleting extra text --- src/users/views.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/users/views.py b/src/users/views.py index 11c160b..9af90c6 100644 --- a/src/users/views.py +++ b/src/users/views.py @@ -322,9 +322,6 @@ def post (self,request): mentor.active = True mentor.save() -<<<<<<< HEAD - return Response(MentorSerializer(mentor).data) -======= return Response(MentorSerializer(mentor).data) class ReportUser(APIView): @@ -355,4 +352,3 @@ def post (self, request): raise ValidationError({'sendgrid_status_code': response.status_code}) return HttpResponse(status=200) ->>>>>>> origin/master