Fixed functionality and added JSON responses for corresponding views.
This commit is contained in:
parent
c5e7fc879f
commit
5d55d9d66f
5 changed files with 156 additions and 37 deletions
|
@ -1,5 +1,3 @@
|
|||
from django.contrib import admin
|
||||
from .models import BackEnd
|
||||
|
||||
# Register your models here.
|
||||
admin.site.register(BackEnd)
|
||||
|
|
|
@ -2,12 +2,3 @@ from django.db import models
|
|||
|
||||
# Create your models here.
|
||||
|
||||
|
||||
class BackEnd(models.Model):
|
||||
title = models.CharField(max_length=200)
|
||||
description = models.TextField()
|
||||
|
||||
def __str__(self):
|
||||
"""A string representation of the model."""
|
||||
return self.title
|
||||
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
# Rupika Dikkala
|
||||
# January 19, 2019
|
||||
# Add views for each path and
|
||||
# link their appropriate functions
|
||||
# Add urls and link to the
|
||||
# views
|
||||
|
||||
from django.urls import path
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path('', views.create_report),
|
||||
path('', views.delete_report),
|
||||
path('', views.get_report),
|
||||
path('', views.list_report),
|
||||
path('', views.update_report),
|
||||
path('', views.submit_report),
|
||||
path('', views.update_section),
|
||||
path('', views.create_account),
|
||||
path('', views.login),
|
||||
path('', views.logout),
|
||||
path('create_report/', views.create_report),
|
||||
path('delete_report/', views.delete_report),
|
||||
path('get_report/', views.get_report),
|
||||
path('list_report/', views.list_report),
|
||||
path('update_report/', views.update_report),
|
||||
path('submit_report/', views.submit_report),
|
||||
path('update_section/', views.update_section),
|
||||
path('create_account/', views.create_account),
|
||||
path('login/', views.login),
|
||||
path('logout/', views.logout),
|
||||
]
|
||||
|
|
|
@ -10,7 +10,64 @@ from django.http import JsonResponse
|
|||
# Create Report
|
||||
def create_report(request):
|
||||
data = {
|
||||
'name': 'create report',
|
||||
"title": "2018 Portland trip",
|
||||
"date_created": "2018-05-22T14:56:28.000Z",
|
||||
"submitted": False,
|
||||
"date_submitted": "0000-00-00T00:00:00.000Z",
|
||||
"sections": [
|
||||
{
|
||||
"id": 1,
|
||||
"completed": True,
|
||||
"title": "Flight Info",
|
||||
"html_description": "<p>Enter flight details here.</p>",
|
||||
"fields": {
|
||||
"international": {
|
||||
"label": "International flight",
|
||||
"type": "boolean",
|
||||
"value": True
|
||||
},
|
||||
"travel_date": {
|
||||
"label": "Travel start date",
|
||||
"type": "date",
|
||||
"value": "2016-05-22T14:56:28.000Z"
|
||||
},
|
||||
"fare": {
|
||||
"label": "Fare",
|
||||
"type": "decimal",
|
||||
"value": "1024.99"
|
||||
},
|
||||
"lowest_fare_screenshot": {
|
||||
"label": "Lowest fare screenshot",
|
||||
"type": "file",
|
||||
"value": "e92h842jiu49f8..."
|
||||
},
|
||||
"plane_ticket_invoice": {
|
||||
"label": "Plane ticket invoice PDF",
|
||||
"type": "file",
|
||||
"value": ""
|
||||
}
|
||||
},
|
||||
"rule_violations": [
|
||||
{
|
||||
"error_text": "Plane ticket invoice must be submitted."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"completed": False,
|
||||
"title": "Hotel info",
|
||||
"html_description": "<p>If you used a hotel, please enter the details.</p>",
|
||||
"fields": {
|
||||
"total": {
|
||||
"label": "Total cost",
|
||||
"type": "decimal"
|
||||
}
|
||||
},
|
||||
"rule_violations": [
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
return JsonResponse(data)
|
||||
|
||||
|
@ -24,14 +81,90 @@ def delete_report(request):
|
|||
# Get report
|
||||
def get_report(request):
|
||||
data = {
|
||||
'name': 'get report',
|
||||
"title": "2018 Portland trip",
|
||||
"date_created": "2018-05-22T14:56:28.000Z",
|
||||
"submitted": False,
|
||||
"date_submitted": "0000-00-00T00:00:00.000Z",
|
||||
"sections": [
|
||||
{
|
||||
"id": 1,
|
||||
"completed": True,
|
||||
"title": "Flight Info",
|
||||
"html_description": "<p>Enter flight details here.</p>",
|
||||
"fields": {
|
||||
"international": {
|
||||
"label": "International flight",
|
||||
"type": "boolean",
|
||||
"value": True
|
||||
},
|
||||
"travel_date": {
|
||||
"label": "Travel start date",
|
||||
"type": "date",
|
||||
"value": "2016-05-22T14:56:28.000Z"
|
||||
},
|
||||
"fare": {
|
||||
"label": "Fare",
|
||||
"type": "decimal",
|
||||
"value": "1024.99"
|
||||
},
|
||||
"lowest_fare_screenshot": {
|
||||
"label": "Lowest fare screenshot",
|
||||
"type": "file",
|
||||
"value": "e92h842jiu49f8..."
|
||||
},
|
||||
"plane_ticket_invoice": {
|
||||
"label": "Plane ticket invoice PDF",
|
||||
"type": "file",
|
||||
"value": ""
|
||||
}
|
||||
},
|
||||
"rule_violations": [
|
||||
{
|
||||
"error_text": "Plane ticket invoice must be submitted."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"completed": False,
|
||||
"title": "Hotel info",
|
||||
"html_description": "<p>If you used a hotel, please enter the details.</p>",
|
||||
"fields": {
|
||||
"total": {
|
||||
"label": "Total cost",
|
||||
"type": "decimal"
|
||||
}
|
||||
},
|
||||
"rule_violations": [
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
return JsonResponse(data)
|
||||
|
||||
# List Reports
|
||||
def list_report(request):
|
||||
data = {
|
||||
'name': 'list report',
|
||||
"reports": [
|
||||
{
|
||||
"title": "2018 Portland trip",
|
||||
"date_created": "2018-05-22T14:56:28.000Z",
|
||||
"state": "created",
|
||||
"date_submitted": "0000-00-00T00:00:00.000Z"
|
||||
},
|
||||
{
|
||||
"title": "2017 Los Angeles trip",
|
||||
"date_created": "2017-05-22T14:56:28.000Z",
|
||||
"state": "submitted",
|
||||
"date_submitted": "2017-07-22T14:56:28.000Z"
|
||||
},
|
||||
{
|
||||
"title": "2017 Denver trip",
|
||||
"date_created": "2015-04-22T14:56:28.000Z",
|
||||
"state": "accepted",
|
||||
"date_submitted": "2015-06-22T14:56:28.000Z"
|
||||
}
|
||||
]
|
||||
}
|
||||
return JsonResponse(data)
|
||||
|
||||
|
@ -39,6 +172,7 @@ def list_report(request):
|
|||
def update_report(request):
|
||||
data = {
|
||||
'name': 'update report',
|
||||
'state': 'SUBMITTED!',
|
||||
}
|
||||
return JsonResponse(data)
|
||||
|
||||
|
@ -52,7 +186,12 @@ def submit_report(request):
|
|||
# Update section
|
||||
def update_section(request):
|
||||
data = {
|
||||
'name': 'update section',
|
||||
"fields": {
|
||||
"international": True,
|
||||
"travel_date": "2012-04-23T18:25:43.511Z",
|
||||
"fare": "1024.99",
|
||||
"lowest_fare_screenshot": "image",
|
||||
}
|
||||
}
|
||||
return JsonResponse(data)
|
||||
|
||||
|
|
|
@ -23,14 +23,5 @@ from django.urls import path, include
|
|||
# add urls to this array
|
||||
urlpatterns = [
|
||||
path('admin/', admin.site.urls),
|
||||
path('create_report/', include("backend.urls")),
|
||||
path('delete_report/', include("backend.urls")),
|
||||
path('get_report/', include("backend.urls")),
|
||||
path('list_reports/', include("backend.urls")),
|
||||
path('update_report/', include("backend.urls")),
|
||||
path('submit_report/', include("backend.urls")),
|
||||
path('update_section/', include("backend.urls")),
|
||||
path('create_account/', include("backend.urls")),
|
||||
path('login/', include("backend.urls")),
|
||||
path('logout/', include("backend.urls")),
|
||||
path('', include("backend.urls")),
|
||||
]
|
||||
|
|
Loading…
Reference in a new issue