biweeklybudget.flaskapp.views.formhandlerview module

class biweeklybudget.flaskapp.views.formhandlerview.FormHandlerView[source]

Bases: flask.views.MethodView

_validate_date_ymd(key, data, errors)[source]

Validate a YYYY-mm-dd date field.

Parameters:
  • key (str) – the key in data to look at
  • data (dict) – the form data
  • err_list (dict) – list of error messages for the field
Returns:

updated err_list

Return type:

dict

_validate_decimal(key, data, errors)[source]

Validate a Decimal field.

Parameters:
  • key (str) – the key in data to look at
  • data (dict) – the form data
  • err_list (dict) – list of error messages for the field
Returns:

updated err_list

Return type:

dict

_validate_float(key, data, errors)[source]

Validate a float field.

Parameters:
  • key (str) – the key in data to look at
  • data (dict) – the form data
  • err_list (dict) – list of error messages for the field
Returns:

updated err_list

Return type:

dict

_validate_int(key, data, errors)[source]

Validate an integer field.

Parameters:
  • key (str) – the key in data to look at
  • data (dict) – the form data
  • err_list (dict) – list of error messages for the field
Returns:

updated err_list

Return type:

dict

_validate_not_empty(key, data, errors)[source]

Validate that a string is not empty.

Parameters:
  • key (str) – the key in data to look at
  • data (dict) – the form data
  • err_list (dict) – list of error messages for the field
Returns:

updated err_list

Return type:

dict

fix_string(s)[source]

Strip a string. If the result is empty, return None. Otherwise return the result.

Parameters:s (str) – form data value
Returns:stripped string or None
methods = {'POST'}
post()[source]

Handle a POST request for a form. Validate it, if valid update the DB.

Returns a JSON hash with the following structure:

‘errors’ -> hash of field names to list of error strings ‘error_message’ -> string error message ‘success’ -> boolean ‘success_message’ -> string success message

submit(data)[source]

Handle form submission; create or update models in the DB.

Parameters:data (dict) – submitted form data
Returns:message describing changes to DB
Return type:str
validate(data)[source]

Validate the form data. Return None if it is valid, or else a hash of field names to list of error strings for each field.

Parameters:data (dict) – submitted form data
Returns:None if no errors, or hash of field name to errors for that field