conjunto.forms

conjunto.forms.DynamicHtmxFormMixin

Bases: DynamicFormMixin

Mixin class for creating dynamic forms with HTMX.

This mixin extends the functionality of the DynamicFormMixin by adding htmx attributes to the form fields that can be used for triggering dynamic updates.

Attributes:
  • context (dict[str, Any]) –

    The context passed to the form from the view. This variable can be accessed within the form via self.context.

  • form_id (str) –

    The id of the form. This is used to generate the id of the form, which is needed as HTMX target

  • Meta.trigger_fields (str) –

    A dict with field names as keys that will trigger a dynamic update on a list of fields (the dict values) on a "change" event.

  • Meta.update_url (str) –

    The URL to send the dynamic update request to. Defaults to current URL if not provided.

  • Meta.trigger (str) –

    the event that triggers the update. Defaults to "change".

Raises:
  • AttributeError

    If the trigger_fields attribute is not defined in Meta.

fields_required(fields, msg=None)

Helper method used for conditionally marking fields as required.

Parameters:
  • fields (str | list[str]) –

    A list of field names, or single field name.

  • msg (str, default: None ) –

    A custom error message. Defaults to "This field is required.".

Example usage:

def clean(self):
    is_person = self.cleaned_data.get("is_person")

    if is_person:
        self.field_required(["first_name", "last_name"])
        self.field_required("title", "A title is definitely required here.")
        self.field_required(["age", "size"], "You forgot this field.")
    else:
        self.cleaned_data["first_name"] = ""
        self.cleaned_data["last_name"] = ""
        self.cleaned_data["title"] = ""

    return self.cleaned_data

Credits go to https://www.fusionbox.com/blog/detail/creating-conditionally-required-fields-in-django-forms/577/

conjunto.forms.ErrorLogMixin

A mixin that can be added to a Form during development/debugging, so that it logs all form errors.

conjunto.forms.MyDynamicFormMixin

A mixin class for Django forms that allows dynamic fields to be included or excluded based on certain conditions.

Attributes:
  • context (dict[str, Any]) –

    The context passed to the form from the view. This variable can be accessed within the form via self.context.

  • Meta.excluded_fields_method (ExcludeMethod) –

    The method to use to if a field is excluded. The default is to hide the field (HIDE). DELETE removes the excluded field entirely from the form, and DISABLE disables the field.

conjunto.forms.widgets

DatePickerInput

Bases: DateInput

A DateInput that uses a date picker.

It adds Litepicker.js for that input field. Additionally, you can specify another field with "end_field_name" that is used for date ranges by Litepicker then.