1,801
การแก้ไข
| บรรทัดที่ 814: | บรรทัดที่ 814: | ||
The key player of this pattern is the function '''{{code|gen_dbcommit_resp}}''' that handles the most repeated routines related to form validation and database commit. | The key player of this pattern is the function '''{{code|gen_dbcommit_resp}}''' that handles the most repeated routines related to form validation and database commit. | ||
<syntaxhighlight lang='python'> | '''<syntaxhighlight lang='python'> | ||
gen_dbcommit_resp(dbtype, tbname, model, form, perm_bit=None, allowed_action=None, | gen_dbcommit_resp(dbtype, tbname, model, form, perm_bit=None, allowed_action=None, | ||
suppress_success_msg=False, lock_on_add=True, head_id_col="id", | suppress_success_msg=False, lock_on_add=True, head_id_col="id", | ||
get_dict=None, skip_validation=False, month=None) | get_dict=None, skip_validation=False, month=None) | ||
</syntaxhighlight> | </syntaxhighlight>''' | ||
{| style="margin-left:20px;" | {| style="margin-left:20px;" | ||
|- style="vertical-align:top;" | |- style="vertical-align:top;" | ||
| style="width:120px;" | '''Parameters''' || '''DO NOT''' rely on argument order beyond ''perm_bit''. | | style="width:120px;" | '''Parameters''' || '''DO NOT''' rely on argument order beyond ''perm_bit''. | ||
* ''' | * '''dbtype''' ''(str)'': Pointer to let CuneiFox grab the correct database file. Options include {{code|lang=python|'data'}}, {{code|lang=python|'table'}}, {{code|lang=python|'report'}}, and {{code|lang=python|'temp'}}. | ||
* ''' | * '''tbname''' ''(str)'': The database file name (without file extension). | ||
* ''' | * '''model''' ''(CuneiModel)'': The model to commit to. | ||
* ''' | * '''form''' ''(FlaskForm-CuneiForm)'': The form to read the committing data from. | ||
* '''perm_bit''' ''(int)'': The integer permission bit. This form of permission control is quite rigid and works well with single-table databases. | |||
* '''allowed_action''' ''({{{code|lang=python|{'add':<bool>, 'edit':<bool>, 'delete':<bool>} })'': A more complicated form of permission control. This allows for more precise control. However, it cannot be read directly from a permission database, but must be interpreted from the stored integer value upon use. | |||
* '''suppress_success_msg''' ''(bool)'': Whether to show a message on action success. | |||
* '''lock_on_add''' ''(bool)'': Lock the document upon successful add-type commit. (This works for multi-table databases by putting the current username in the '''editting''' column of the header table.) | |||
* '''head_id_col''' ''(str)'': The name of the field unique to each entry. (The field must be present both in the form and in the database table.) | |||
* '''get_dict''' ''(list)'': If provided, '''{{code|new_entry}}''' is returned as a dict instead of a CuneiModel instance. (Values from field names listed in this argument are returned as their integer references. This is useful for ForeignKeyFields.) | |||
* '''skip_validation''' ''(bool)'': Whether the form validation step is skipped. '''ONLY SET THIS IF THE FORM IS VALIDATED ELSEWHERE.''' | |||
* '''month''' ''(date or datetime)'': (Only applies for dbtype {{code|lang=python|'data'}}) The month sub-directory of the database. If not given, the program infers the month from the session time. | |||
|- | |||
| '''Returns''' || | |||
* '''db_mod_code''' ''(int or {{code|lang=python|None}})'' | |||
* '''new_entry''' ''(CuneiModel instance or dict)'' | |||
* '''resp_dict''' ''(dict)'' | |||
|} | |} | ||