ข้ามไปเนื้อหา

ผลต่างระหว่างรุ่นของ "CuneiForm"

เพิ่มขึ้น 1,673 ไบต์ ,  16 เมษายน 2567
บรรทัดที่ 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''.
* '''form_name''' ''(str)'': The '''id''' attribute of the {{code|form_obj}}.
* '''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'}}.
* '''fname''' ''(str)'': The field name to be bound to the proxy.
* '''tbname''' ''(str)'': The database file name (without file extension).
* '''proxy_ele''' ''(HTML element)'': The proxy element.
* '''model''' ''(CuneiModel)'': The model to commit to.
* '''proxy_func''' ''(JavaScript function)'': The function to run when the form is triggered (a usual routine on a [[Multi-component Page]]). This function should accept ''1 boolean argument and returns nothing''.
* '''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)''
|}
|}