Forms, fields and widgets ========================= The ``core`` app ships a handful of forms reused across the project, plus the supporting custom field and widgets they rely on. Forms ----- SearchForm ~~~~~~~~~~ The form behind the top-bar / sidebar search. A single ``query`` text field with autocomplete disabled (so the browser doesn't shadow the in-app suggestion UI). .. autoclass:: richy.core.forms.SearchForm :show-inheritance: BaseUserItemForm ~~~~~~~~~~~~~~~~ Base ``ModelForm`` for editing a :class:`~richy.core.models.UserItem`. Each per-app item edit form (shares, etfs, indexes, coins) inherits from this base and supplies its own ``item_model`` -- the form drives the symbol input, custom-index assignment, archive flag and free-form note. Constructor takes the current ``user``: the ``indexes`` queryset is scoped to that user's indexes, and form-level validation enforces: * For **new** items, the symbol cannot collide with an item the user already has. * For **existing** items, the symbol field becomes read-only. * Symbols are stored uppercase regardless of input casing. * An item with an open :class:`~richy.transactions.models.Transaction` cannot be archived. .. autoclass:: richy.core.forms.BaseUserItemForm :show-inheritance: .. automethod:: richy.core.forms.BaseUserItemForm.clean_symbol .. automethod:: richy.core.forms.BaseUserItemForm.clean_is_archived SplitterForm ~~~~~~~~~~~~ The form behind the *splitter* tool: applies a stock split (or reverse split) retroactively to historical prices of an item. Takes the concrete item model class at construction time (so the ``item`` queryset can be narrowed to the right asset type). Fields: ``item``, ``date`` (the split date), ``ratio``. .. autoclass:: richy.core.forms.SplitterForm :show-inheritance: SplitterPreviewForm ~~~~~~~~~~~~~~~~~~~ Intentionally empty -- the splitter preview view uses this only to mark its second step in the flow (the actual data comes from the preceding ``SplitterForm`` submission). .. autoclass:: richy.core.forms.SplitterPreviewForm :show-inheritance: Fields ------ MultipleFileField ~~~~~~~~~~~~~~~~~ A file field with multiple upload turned on (the user can pick several files from disk). Once uploaded, files can be removed and more files added. The initial data is a list of model instances representing the file records in the database. The model **must** expose a ``file`` property (either a real model field or a ``@property``-aliased method). The widget uses the model PK in URLs for deletion. The field extends from ``FileField`` and is paired with :class:`~richy.core.widgets.MultipleFileInput`. Special properties: * ``delete_url_pattern`` -- URL pattern where the deletion URL points to; must contain an ``id`` URL parameter. .. autoclass:: richy.core.fields.MultipleFileField :show-inheritance: Widgets ------- MultipleFileInput ~~~~~~~~~~~~~~~~~ The widget paired with :class:`~richy.core.fields.MultipleFileField`. Extends Django's ``ClearableFileInput`` with ``allow_multiple_selected = True`` and renders through the custom template ``widgets/clearable_multiple_file.html`` so the existing attachments and the delete links are visible alongside the file picker. .. autoclass:: richy.core.widgets.MultipleFileInput :show-inheritance: NoLabelCheckboxSelectMultiple ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Variant of Django's ``CheckboxSelectMultiple`` that swaps the option template from ``django/forms/widgets/input_option.html`` to ``django/forms/widgets/input.html`` -- effectively skipping the per-option ``