Skip to content

Commit

Permalink
Merge branch 'master' of github.com:audaciouscode/PassiveDataKit-Django
Browse files Browse the repository at this point in the history
  • Loading branch information
audaciouscode committed Feb 9, 2017
2 parents ef9bc9b + 9b1eb04 commit 5c2dc98
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 6 deletions.
25 changes: 25 additions & 0 deletions migrations/0013_datafile.py
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.6 on 2016-08-12 02:25
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('passive_data_kit', '0012_auto_20160319_2225'),
]

operations = [
migrations.CreateModel(
name='DataFile',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('content_type', models.CharField(db_index=True, max_length=256)),
('content_file', models.FileField(upload_to='data_files')),
('data_point', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='data_files', to='passive_data_kit.DataPoint')),
],
),
]
26 changes: 26 additions & 0 deletions migrations/0014_auto_20160812_0243.py
@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.6 on 2016-08-12 02:43
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('passive_data_kit', '0013_datafile'),
]

operations = [
migrations.AddField(
model_name='datafile',
name='data_bundle',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='data_files', to='passive_data_kit.DataBundle'),
),
migrations.AlterField(
model_name='datafile',
name='data_point',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='data_files', to='passive_data_kit.DataPoint'),
),
]
21 changes: 21 additions & 0 deletions migrations/0015_datafile_identifier.py
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.6 on 2016-08-12 02:44
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('passive_data_kit', '0014_auto_20160812_0243'),
]

operations = [
migrations.AddField(
model_name='datafile',
name='identifier',
field=models.CharField(db_index=True, default='', max_length=256),
preserve_default=False,
),
]
9 changes: 7 additions & 2 deletions models.py
Expand Up @@ -36,22 +36,27 @@ class DataPoint(models.Model):
recorded = models.DateTimeField(db_index=True)

properties = JSONField()


class DataBundle(models.Model):
recorded = models.DateTimeField(db_index=True)
properties = JSONField()

processed = models.BooleanField(default=False, db_index=True)

class DataFile(models.Model):
data_point = models.ForeignKey(DataPoint, related_name='data_files', null=True, blank=True)
data_bundle = models.ForeignKey(DataBundle, related_name='data_files', null=True, blank=True)

identifier = models.CharField(max_length=256, db_index=True)
content_type = models.CharField(max_length=256, db_index=True)
content_file = models.FileField(upload_to='data_files')

class DataSourceGroup(models.Model):
name = models.CharField(max_length=1024, db_index=True)

def __unicode__(self):
return self.name


class DataSource(models.Model):
identifier = models.CharField(max_length=1024, db_index=True)
name = models.CharField(max_length=1024, db_index=True, unique=True)
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
@@ -1,4 +1,4 @@
Django==1.9.6
Django==1.10.1
argparse==1.2.1
arrow==0.7.0
lockfile==0.12.2
Expand Down
4 changes: 2 additions & 2 deletions static/pdk/css/lib/bootstrap.min.css

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion views.py
Expand Up @@ -12,7 +12,7 @@

from django.contrib.admin.views.decorators import staff_member_required

from .models import DataPoint, DataBundle, DataSourceGroup, DataSource, ReportJob, generator_label
from .models import DataPoint, DataBundle, DataFile, DataSourceGroup, DataSource, ReportJob, generator_label

@csrf_exempt
def add_data_point(request):
Expand Down Expand Up @@ -101,6 +101,13 @@ def add_data_bundle(request):
response = { 'message': 'Unable to parse data bundle.' }
response = HttpResponse(json.dumps(response, indent=2), content_type='application/json', status=201)

for key, value in request.FILES.iteritems():
file = DataFile(data_bundle=bundle)
file.identifier = value.name
file.content_type = value.content_type
file.content_file.save(value.name, value)
file.save()

return response
elif request.method == 'OPTIONS':
response = HttpResponse('', content_type='text/plain', status=200)
Expand Down

0 comments on commit 5c2dc98

Please sign in to comment.