Forms#

The transactions app ships two forms: the main transaction create / edit TransactionForm and the secondary PostClosedOrClosingTransactionForm shown when closing a transaction implicitly closes parent transactions or stakings.

TransactionForm#

ModelForm for Transaction. Constructed with the current user: the item queryset is limited to that user’s items, the parents queryset to that user’s transactions (newest first), and most fields receive either a validator (currency must be 3 alpha chars, price and fee must be >= 0) or help text.

Two extras layered on top of the model:

  • An attachments field (MultipleFileField) that lets the user attach / remove files alongside the transaction record. save() materializes each uploaded file as an Attachment row.

  • The target field accepts either a plain numeric price or a percentage with a trailing %; clean_target() enforces that regex.

The form-level clean() performs the cross-field validation:

  • Coin transactions must have an exchange selected.

  • A transaction marked is_deposit cannot also be is_closing.

  • Only negative-amount transactions can be is_closing.

  • Marking is_closed or is_closing requires a closed_on date.

  • Sell (negative-amount) transactions must have at least one parents entry.

class richy.transactions.forms.TransactionForm(user, *args, **kwargs)[source]#

Bases: ModelForm

TransactionForm.clean()[source]#

Validates: * if exchange is filled for coins * echanging is forbidden for shares (not possbible)

TransactionForm.clean_target()[source]#
TransactionForm.save(*args, **kwargs)[source]#

Save this form’s self.instance object if commit=True. Otherwise, add a save_m2m() method to the form which can be called after the instance is saved manually at a later time. Return the model instance.

PostClosedOrClosingTransactionForm#

Secondary follow-up form rendered by PostClosedOrClosingTransactionUpdateFormView after a user closes a transaction whose chain of parent transactions and / or related stakings can be closed in the same gesture. It carries two optional fields:

  • parents – the parent transactions to mark as closed.

  • stakings – the related staking records to mark as sold.

Both querysets are passed in from the view.

class richy.transactions.forms.PostClosedOrClosingTransactionForm(parents, stakings, *args, **kwargs)[source]#

Bases: Form