it/itf/boxes/views.py
2011-04-09 01:45:51 +05:30

41 lines
1.1 KiB
Python

# Create your views here.
from api.actions import actions
import ox
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
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