Files
web2.0-backend/infoscreen/views.py
T
2016-09-14 20:43:05 +03:00

37 lines
1.2 KiB
Python

from django.shortcuts import render
from django.http import HttpResponse
from django.views.decorators.http import require_http_methods
from infoscreen.models import ABBJob, Rotation
from django.utils import timezone
from datetime import datetime, timedelta
import json
def index(request,idx, *args, **kwargs):
return render(request, 'infoscreen_index.html',{'rotation':idx})
def default(request,*args,**kwargs):
try:
first = Rotation.objects.all()[0].id
except:
first = 0
return index(request,first ,*args, **kwargs)
# send abb jobs which have been created less than month ago
@require_http_methods(["GET"])
def abb_job_list(request, *args, **kwargs):
limit = timezone.now() - timedelta(days=30)
jobs = ABBJob.objects.filter(created__gt=limit)
joblist = list(map(lambda j:j.get_dict(), jobs))
return HttpResponse(json.dumps(joblist))
@require_http_methods(["GET"])
def rotation(request, idx, *args, **kwargs):
try:
rotation = Rotation.objects.get(pk=idx)
except Rotation.DoesNotExist:
resp = HttpResponse('{"error": "Rotation not found"}')
resp.status_code = 404
return resp
return HttpResponse(json.dumps(rotation.get_dict()))