Commit ba096dea authored by Yori Fournier's avatar Yori Fournier
Browse files

Added DownloadFile Action

parent 858dc4f9
......@@ -3,7 +3,8 @@ from django.db import models
# Create your models here.
INTERFACES = [('tap', 'TAP'), ]
ACTIONS = [('save_to_file', 'save to file'), ]
ACTIONS = [('save_to_file', 'save to file'),
('download_file', 'download file')]
class ArchiveDescriber(models.Model):
......@@ -19,17 +20,33 @@ class ArchiveDescriber(models.Model):
# this wont' create a table
class TapArchiveDescriber_MixIn(models.Model):
interface_url = models.CharField(max_length=256, default='https://your-service.org/tap')
interface_username = models.CharField(max_length=256, default='<tap-service-username>')
interface_token = models.CharField(max_length=256, default='<tap-service-token>') # will become ref to the token as secret
interface_sql_lang = models.CharField(max_length=256, default="PostgreSQL")
interface_sql_queue = models.CharField(max_length=256, default="30s")
interface_sql_query = models.TextField(blank=True, default="SQL Query")
class Meta:
abstract = True
# this wont' create a table
class SaveToFileArchiveDescriber_MixIn(models.Model):
action_fileformat = models.CharField(max_length=10, default='.csv')
action_filename = models.CharField(max_length=256, default='table')
class Meta:
abstract = True
class DownloadFileArchiveDescriber_MixIn(models.Model):
action_url_column = models.CharField(max_length=256, default='')
action_base_url_file_server = models.CharField(max_length=256, default='')
class Meta:
abstract = True
# the instance of this will be in both tables: ArchiveDescriber and in TapSaveToFileArchiveDescriber
class TapSaveToFileArchiveDescriber(ArchiveDescriber, TapArchiveDescriber_MixIn, SaveToFileArchiveDescriber_MixIn):
pass
class TapDownloadFileArchiveDescriber(ArchiveDescriber, TapArchiveDescriber_MixIn, DownloadFileArchiveDescriber_MixIn):
pass
from rest_framework import serializers
from arch_gen.models import ArchiveDescriber, TapSaveToFileArchiveDescriber
from arch_gen.models import ArchiveDescriber, TapSaveToFileArchiveDescriber, TapDownloadFileArchiveDescriber
from django.contrib.auth.models import User
......@@ -33,5 +33,14 @@ class TapSaveToFileArchiveDescriberSerializer(serializers.ModelSerializer):
model = TapSaveToFileArchiveDescriber
fields = ['id', 'owner', 'title',
'interface_type', 'interface_url',
'action_type', 'action_fileformat']
'interface_type', 'interface_url', 'interface_username', 'interface_token', 'interface_sql_lang', 'interface_sql_queue', 'interface_sql_query',
'action_type', 'action_fileformat', 'action_filename']
class TapDownloadFileArchiveDescriberSerializer(serializers.ModelSerializer):
class Meta:
model = TapDownloadFileArchiveDescriber
fields = ['id', 'owner', 'title',
'interface_type', 'interface_url', 'interface_username', 'interface_token', 'interface_sql_lang', 'interface_sql_queue', 'interface_sql_query',
'action_type', 'action_url_column', 'action_base_url_file_server']
......@@ -2,8 +2,8 @@ from rest_framework import status
from rest_framework.decorators import api_view, permission_classes
from rest_framework.response import Response
from rest_framework.parsers import JSONParser
from arch_gen.models import ArchiveDescriber, TapSaveToFileArchiveDescriber
from arch_gen.serializers import ArchiveDescriberSerializer, TapSaveToFileArchiveDescriberSerializer
from arch_gen.models import ArchiveDescriber, TapSaveToFileArchiveDescriber, TapDownloadFileArchiveDescriber
from arch_gen.serializers import ArchiveDescriberSerializer, TapSaveToFileArchiveDescriberSerializer, TapDownloadFileArchiveDescriberSerializer
from arch_gen.permissions import IsOwnerOrReadOnly
......@@ -56,8 +56,12 @@ def archive_describer_list(request, format=None):
elif request.method == 'POST':
# print(request.data) # THIS IS HOW TO ACCESS THE DATA (prevent request.body at all costs)
print(request.data['interface_type'], request.data['action_type'])
serializer_class = get_archive_describer_serializer_class(request.data['interface_type'], request.data['action_type'])
print(serializer_class)
# add the user to the data (Hacky... need a better way)
data = request.data.copy()
user = User.objects.filter(username=request.user.username)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment