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

from common.decorators import ajax, render, render_template
from paginer import types, PaginationList


@render_template('ajax_paginer.html')
@ajax(method='post', template='ajax_paginer.html')
def get_page_content(request, paginer_id, paginer_type, params, action, page_nr,
                     group_actions=None):
    paginer = PaginationList()
    paginer.add(
        paginer_id, paginer_type, params, action=action,
        group_actions=group_actions)
    return {
        'paginer': paginer,
        'id': paginer_id,
        'page_nr': page_nr,
    }


@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}