2011-08-22 22:04:40 +00:00
|
|
|
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
|
|
|
|
|
2011-08-25 09:39:15 +00:00
|
|
|
|
2011-08-22 22:04:40 +00:00
|
|
|
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
|
2011-08-27 10:54:45 +00:00
|
|
|
default_tab_list = default_tab.model_class().get_list(list_options)
|
2011-08-22 22:04:40 +00:00
|
|
|
context = RequestContext(request, {
|
|
|
|
'title': m.title,
|
|
|
|
'default_tab': tabs[0],
|
|
|
|
'default_list': default_tab_list,
|
2011-09-10 01:57:41 +00:00
|
|
|
'default_sorts': default_tab.get_dict()['sorts'],
|
2011-08-22 22:04:40 +00:00
|
|
|
'tabs': tabs[1:]
|
|
|
|
})
|
|
|
|
return render_to_response("noel/insidepage.html", context)
|
2011-09-10 01:40:47 +00:00
|
|
|
|
2011-10-03 02:43:28 +00:00
|
|
|
|
2011-09-10 01:40:47 +00:00
|
|
|
def get_tab(request):
|
2011-10-03 02:43:28 +00:00
|
|
|
tab_slug = request.GET.get("tab", "")
|
|
|
|
tab = get_object_or_404(ModuleTab, slug=tab_slug)
|
2011-09-10 01:40:47 +00:00
|
|
|
return render_to_json_response(tab.get_dict())
|
2011-08-22 22:04:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
def get_list(request):
|
2011-10-03 02:43:28 +00:00
|
|
|
tab_slug = request.GET.get("tab", "")
|
|
|
|
tab = get_object_or_404(ModuleTab, slug=tab_slug)
|
2011-10-10 10:30:18 +00:00
|
|
|
object_id = request.GET.get("object_id", False)
|
2011-09-10 01:40:47 +00:00
|
|
|
sortString = request.GET.get("sort", "")
|
2011-09-10 03:09:14 +00:00
|
|
|
if sortString == "" or sortString == 'null':
|
2011-09-10 01:40:47 +00:00
|
|
|
sortArray = []
|
|
|
|
else:
|
|
|
|
sortOperator = sortString[0]
|
|
|
|
sortField = sortString[1:]
|
|
|
|
sortArray = [{
|
|
|
|
'operator': sortOperator,
|
|
|
|
'key': sortField
|
|
|
|
}]
|
|
|
|
|
2011-08-22 22:04:40 +00:00
|
|
|
list_options = {
|
|
|
|
'search': request.GET.get("search", ""),
|
2011-09-10 01:40:47 +00:00
|
|
|
'sort': sortArray,
|
|
|
|
'page': request.GET.get("page", 1),
|
2011-10-10 10:30:18 +00:00
|
|
|
'object_id': object_id,
|
|
|
|
'count': request.GET.get("count", 15) #FIXME: make list_length either in settings.py or config per model
|
2011-08-22 22:04:40 +00:00
|
|
|
}
|
|
|
|
object_list = tab.get_list(list_options)
|
|
|
|
return render_to_json_response(object_list)
|
|
|
|
|
|
|
|
|
|
|
|
def get_details(request):
|
2011-10-03 02:43:28 +00:00
|
|
|
tab_slug = request.GET.get("tab", '')
|
|
|
|
tab = get_object_or_404(ModuleTab, slug=tab_slug)
|
2011-08-27 10:54:45 +00:00
|
|
|
model_class = tab.model_class()
|
2011-08-22 22:04:40 +00:00
|
|
|
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())
|
|
|
|
|
2011-08-25 09:39:15 +00:00
|
|
|
|