# Create your views here.
from api.actions import actions
import ox
from django.shortcuts import render_to_response
from ox.django.decorators import login_required_json
from ox.django.shortcuts import render_to_json_response, get_object_or_404_json, json_response
from models import Panel
import json
from django.template import RequestContext

def mainPage(request):
	d = {'title': 'India Theatre Forum'}
	return render_to_response("noel/index.html", d)

def innerPage(request):
	return render_to_response("noel/bestpractices.html", RequestContext(request, {}))

def getPage(request):
  '''
  returns displayed panels as displayed; hidden panels as hidden.
  each panel is:
  title
  boxes:
    type
    title
    default_model
    etc
  '''
#  data = json.loads(request.POST['data'])
  panels = _getPageData(request)
  response = json_response({})
  response['data'] = panels
  response['status'] = {'code': 200}
  return render_to_json_response(response)
actions.register(getPage)

def _getPageData(request):
  data = json.loads(request.POST['data'])
  displayedPanels = Panel.objects.filter(enabled=True).filter(displayed=True)
  hiddenPanels = Panel.objects.filter(enabled=True).filter(displayed=False)
  panels = {}
  panels['displayed'] = []
  for d in displayedPanels:
    panels['displayed'].append(d.get_dict())
  panels['hidden'] = []
  for h in hiddenPanels:
    panels['hidden'].append(h.get_dict())
  return panels
