it/itf/insidepages/views.py
2011-08-23 03:34:40 +05:30

41 lines
1.4 KiB
Python

from models import Module, ModuleTab
from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext
from ox.django.shortcuts import render_to_json_response
def main(request, module_slug):
m = get_object_or_404(Module, slug=module_slug)
tabs = m.moduletab_set.all()
default_tab = tabs[0]
list_options = {} #get some options as GET params, etc. to potentially pass to get_list
default_tab_list = default_tab.model.model_class().get_list(list_options)
context = RequestContext(request, {
'title': m.title,
'default_tab': tabs[0],
'default_list': default_tab_list,
'tabs': tabs[1:]
})
return render_to_response("noel/insidepage.html", context)
def get_list(request):
tab_id = request.GET.get("tab", 0)
tab = get_object_or_404(ModuleTab, pk=tab_id)
list_options = {
'search': request.GET.get("search", ""),
'sort': request.GET.get("sort", ""),
'page': request.GET.get("page_no", 1)
}
object_list = tab.get_list(list_options)
return render_to_json_response(object_list)
def get_details(request):
tab_id = request.GET.get("tab_id", 0)
tab = get_object_or_404(ModuleTab, pk=tab_id)
model_class = tab.model.model_class()
object_id = request.GET.get("object_id", 0)
obj = get_object_or_404(model_class, pk=object_id)
return render_to_json_response(obj.insidepage_dict())