ajax.py 1.09 KB
# -*- coding: utf-8 -*-

from django.template import RequestContext
from django.template.loader import get_template
from common.decorators import ajax, render
from paginer import types, PaginationList

@ajax(method='post')
def get_page_content(request, id, type, params, action, page_nr,
                     group_actions=None):
  c = RequestContext(request)
  c['paginer'] = PaginationList()
  c['paginer'].add(id, type, params, action=action, group_actions=group_actions)
  c['id'] = id
  c['page_nr'] = page_nr
  t = get_template('ajax_paginer.html')
  html = t.render(c)
  return {'html': html}

@render()
@ajax(method='get', encode_result=False)
def new_filter_row(request, list_type):
  filter_field_form_class = types[list_type].filter_field_form
  form = filter_field_form_class(prefix='field_NUM')
  return {'form': form}

@render()
@ajax(method='get', encode_result=False)
def field_form(request, list_type, field_name):
  filter_data = types[list_type].filters[field_name]
  lookup_choices = filter_data[1]
  form = filter_data[2](prefix='value_NUM')
  return {'lookup_choices': lookup_choices, 'form': form}