• 2251 views
  • 1 comments
  • loading...

CRUD incorporates the creation of the form, the processing of the form, the notification, and the redirection

CRUD creates an SQLFORM, but it simplifies the coding because it incorporates the creation of the form, the processing of the form, the notification, and the redirection, all in one single function.

CRUD is not exposed and it must be imported, also it also must be linked to a specific database. 

from gluon.tools import Crud
crud = Crud(db)











def data(): return dict(form=crud())


# Expose the following URLs:

http://.../[app]/[controller]/data/tables
http://.../[app]/[controller]/data/create/[tablename]
http://.../[app]/[controller]/data/read/[tablename]/[id]
http://.../[app]/[controller]/data/update/[tablename]/[id]
http://.../[app]/[controller]/data/delete/[tablename]/[id]
http://.../[app]/[controller]/data/select/[tablename]
http://.../[app]/[controller]/data/search/[tablename]

Attributes / Arguments

Enforce authentication on all crud forms

crud.settings.auth = auth

Specify the controller that defines the data function which returns the crud object

crud.settings.controller = 'default'

Specify the URL to redirect to after a successful "create" record.

crud.settings.create_next = URL('index')

Specify the URL to redirect to after a successful "update" record:

crud.settings.update_next = URL('index')

Specify the URL to redirect to after a successful "delete" record.

crud.settings.delete_next = URL('index')

To specify the URL to be used for linking uploaded files.

crud.settings.download_url = URL('download')

To specify extra functions to be executed after standard validation procedures for crud.create forms

crud.settings.create_onvalidation = StorageList() #StorageList is the same as a Storage object, they are both defined in the file "gluon/storage.py", but it defaults to [] as opposed to None. It allows the following syntax:

crud.settings.create_onvalidation.mytablename.append(lambda form:....)

To specify extra functions to be executed after standard validation procedures for crud.update forms.

crud.settings.update_onvalidation = StorageList()

To specify extra functions to be executed after completion of crud.create forms: .

crud.settings.create_onaccept = StorageList()

To specify extra functions to be executed after completion of crud.update forms.

crud.settings.update_onaccept = StorageList()

To specify extra functions to be executed after completion of crud.update i. record is deleted:

crud.settings.update_ondelete = StorageList()

To specify extra functions to be executed after completion of crud.delete:

crud.settings.delete_onaccept = StorageList()

To determine whether the "update" forms should have a "delete" button.

crud.settings.update_deletable = True

To determine whether the "update" forms should show the id of the edited record.

crud.settings.showid = False

To determine whether forms should keep the previously inserted values or reset to default after successful submission.

crud.settings.keepvalues = False

Crud always detects whether a record being edited has been modified by a third party in the time between the time when the form is displayed and the time when it is submitted. This behavior is equivalent to form.process(detect_record_change=True)

crud.settings.detect_record_change = True

Change form style: 'table3cols' or 'table2cols' or 'divs' or 'ul'

crud.settings.formstyle = 'table3cols' or 'table2cols' or 'divs' or 'ul'

You can set the separator in all crud forms.

crud.settings.label_separator = ':'

crud.settings.captcha = None
crud.settings.create_captcha = None
crud.settings.update_captcha = None

Related References


Examples

loading...

Sources / Reference

" web2py Book Chapter 7: Forms and Validatators" is licensed under Creative Common License BY-NC-ND 3.0


Comments

loading...

Powered by
Web2py

Hosted on
www.pythonanywhere.com
(affiliated link)