示例#1
0
def make_select_dialog(model):
    form_class = make_select_form(model)
    model_name = model.__name__
    dialog_class = type('M2MSelectDialog%s'%model_name, (Dialog,), {
        'name': model_name,
        'select': Pane(
            'dialogs/select/many_to_many_select.html',
            buttons=(
                SubmitButton('Select', 'CLOSE'),
                CancelButton('Cancel', 'CLOSE'),
            ),
        ),
        'form_class': form_class,
    })

    # In constructing the view function, we have to use the "called" decorator instead of
    # "is_dialog" because of a cyclic dependency issue.
    view = staticmethod(called(('cancel',), use_background=True)(lambda x,*y,**z: many_to_many_select(x, dialog_class, form_class, *y, **z)))

    # In order to use Django's "reverse" function I need to make sure the static view
    # method is only attached to one class (the dialog).
    dialog_class.view = view
    dialog_class.base_panes['select'].view = dialog_class.view

    return dialog_class
示例#2
0
def is_dialog(dialog):
    if isclass(dialog):
        dialog = dialog()
    return called(dialog.cancel_trigger_names, use_background=True)