-
Notifications
You must be signed in to change notification settings - Fork 1
/
views.py
90 lines (72 loc) · 2.6 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
"""
GAVIP Example AVIS: Simple AVI
@req: SOW-FUN-010
@req: SOW-FUN-040
@req: SOW-FUN-046
@req: SOW-INT-001
@comp: AVI Web System
This is a simple example AVI which demonstrates usage of the GAVIP AVI framework
Here in views.py, you can define any type of functions to handle
HTTP requests. Any of these functions can be used to create an
AVI query from your AVI interface.
"""
import os
import time
import json
import logging
from django.conf import settings
from django.http import JsonResponse
from django.shortcuts import redirect, get_object_or_404
from django.shortcuts import render
from django.core import serializers
from django.utils import formats
from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import reverse
from django.views.decorators.http import require_http_methods
from avi.models import DemoModel
from gavip_avi.decorators import require_gavip_role # use this to restrict access to views in an AVI
ROLES = settings.GAVIP_ROLES
logger = logging.getLogger(__name__)
@require_http_methods(["GET"])
def index(request):
"""
This view is the first view that the user sees
We send a dictionary called a context, which contains
'millis' and 'standalone' variables.
"""
context = {
"millis": int(round(time.time() * 1000)),
"show_welcome": request.session.get('show_welcome', True)
}
request.session['show_welcome'] = False
return render(request, 'avi/index.html', context)
@require_http_methods(["POST"])
def run_query(request):
"""
This is called when the user submits their job parameters in
their interface.
We pull the parameters from the request POST parameters.
We create an avi_job_request, which must be used to create
the DemoModel instance, so that the pipeline can excercise
the pipeline correctly.
We attach the job_request instance to th DemoModel; this
extends the AviJob class, which is required for pipeline
processing.
We start the job using the job_request ID, and return the
ID to the user so they can view progress.
"""
outfile = request.POST.get("outfile")
adql_query = request.POST.get("query")
job = DemoModel.objects.create(
query=adql_query,
outputFile=outfile
)
return JsonResponse({})
@require_http_methods(["GET"])
def job_result(request, job_id):
job = get_object_or_404(DemoModel, request_id=job_id)
file_path = job.request.result_path
context = {'job_id': job.id}
with open(file_path, 'r') as out_file:
context.update(json.load(out_file))
return render(request, 'avi/job_result.html', context=context)