Ejemplo n.º 1
0
 def fields(self):
     fk = getattr(self.formset, "fk", None)
     for i, field in enumerate(flatten_fieldsets(self.fieldsets)):
         if fk and fk.name == field:
             continue
         if field in self.readonly_fields:
             yield {
                 'label': label_for_field(field, self.opts.model, self.opts),
                 'widget': {
                     'is_hidden': False
                 },
                 'required': False
             }
         else:
             yield self.formset.form.base_fields[field]
Ejemplo n.º 2
0
def result_headers(cl):
    """
    Generates the list column headers.
    """
    lookup_opts = cl.lookup_opts

    for i, field_name in enumerate(cl.list_display):
        header, attr = label_for_field(field_name, cl.model,
            model_admin = cl.model_admin,
            return_attr = True
        )
        if attr:
            # if the field is the action checkbox: no sorting and special class
            if field_name == 'action_checkbox':
                yield {
                    "text": header,
                    "class_attrib": mark_safe(' class="action-checkbox-column"')
                }
                continue

            # It is a non-field, but perhaps one that is sortable
            admin_order_field = getattr(attr, "admin_order_field", None)
            if not admin_order_field:
                yield {"text": header}
                continue

            # So this _is_ a sortable non-field.  Go to the yield
            # after the else clause.
        else:
            admin_order_field = None

        th_classes = []
        new_order_type = 'asc'
        if field_name == cl.order_field or admin_order_field == cl.order_field:
            th_classes.append('sorted %sending' % cl.order_type.lower())
            new_order_type = {'asc': 'desc', 'desc': 'asc'}[cl.order_type.lower()]

        yield {
            "text": header,
            "sortable": True,
            "url": cl.get_query_string({ORDER_VAR: i, ORDER_TYPE_VAR: new_order_type}),
            "class_attrib": mark_safe(th_classes and ' class="%s"' % ' '.join(th_classes) or '')
        }
Ejemplo n.º 3
0
 def __init__(self, form, field, is_first, model_admin=None):
     label = label_for_field(field, form._meta.model, model_admin)
     # Make self.field look a little bit like a field. This means that
     # {{ field.name }} must be a useful class name to identify the field.
     # For convenience, store other field-related data here too.
     if callable(field):
         class_name = field.__name__ != '<lambda>' and field.__name__ or ''
     else:
         class_name = field
     self.field = {
         'name': class_name,
         'label': label,
         'field': field,
         'help_text': help_text_for_field(class_name, form._meta.model)
     }
     self.form = form
     self.model_admin = model_admin
     self.is_first = is_first
     self.is_checkbox = False
     self.is_readonly = True