Package s3 :: Module s3crud :: Class S3CRUD
[frames] | no frames]

Class S3CRUD

source code

     object --+    
              |    
s3rest.S3Method --+
                  |
                 S3CRUD

Interactive CRUD Method Handler

Instance Methods
 
apply_method(self, r, **attr)
Apply CRUD methods
source code
 
widget(self, r, method=None, widget_id=None, visible=True, **attr)
Entry point for other method handlers to embed this method as widget
source code
 
create(self, r, **attr)
Create new records
source code
 
read(self, r, **attr)
Read a single record
source code
 
update(self, r, **attr)
Update a record
source code
 
delete(self, r, **attr)
Delete record(s)
source code
 
select(self, r, **attr)
Filterable datatable/datalist
source code
 
unapproved(self, r, **attr)
Get a list of unapproved records in this resource
source code
 
review(self, r, **attr)
Review/approve/reject an unapproved record.
source code
 
validate(self, r, **attr)
Validate records (AJAX).
source code
 
last_update(self)
Get the last update meta-data of the current record
source code
 
render_buttons(self, r, buttons, record_id=None, **attr)
Render CRUD buttons
source code
 
import_csv(self, stream, table=None)
Import CSV file into database
source code

Inherited from s3rest.S3Method: __call__

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __init__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Methods
 
action_buttons(cls, r, deletable=True, editable=None, copyable=False, read_url=None, delete_url=None, update_url=None, copy_url=None)
Provide the usual action buttons in list views.
source code
Static Methods
 
crud_button(label=None, tablename=None, name=None, icon=None, _href=None, _id=None, _class=None, _title=None, _target=None, **attr)
Generate a CRUD action button
source code
 
action_button(label, url, icon=None, **attr)
Add a link to response.s3.actions
source code
 
import_url(r)
Import data from vars in URL query
source code

Inherited from s3rest.S3Method: crud_string

Properties

Inherited from object: __class__

Method Details

apply_method(self, r, **attr)

source code 

Apply CRUD methods

Parameters:
  • r - the S3Request
  • attr - dictionary of parameters for the method handler
Returns:
output object to send to the view
Overrides: s3rest.S3Method.apply_method

widget(self, r, method=None, widget_id=None, visible=True, **attr)

source code 

Entry point for other method handlers to embed this method as widget

Parameters:
  • r - the S3Request
  • method - the widget method
  • widget_id - the widget ID
  • visible - whether the widget is initially visible
  • attr - controller attributes
Returns:
output
Overrides: s3rest.S3Method.widget

create(self, r, **attr)

source code 

Create new records

Parameters:
  • r - the S3Request
  • attr - dictionary of parameters for the method handler

read(self, r, **attr)

source code 

Read a single record

Parameters:
  • r - the S3Request
  • attr - dictionary of parameters for the method handler

update(self, r, **attr)

source code 

Update a record

Parameters:
  • r - the S3Request
  • attr - dictionary of parameters for the method handler

delete(self, r, **attr)

source code 

Delete record(s)

Parameters:
  • r - the S3Request
  • attr - dictionary of parameters for the method handler

To Do: update for link table components

select(self, r, **attr)

source code 

Filterable datatable/datalist

Parameters:
  • r - the S3Request
  • attr - dictionary of parameters for the method handler

unapproved(self, r, **attr)

source code 

Get a list of unapproved records in this resource

Parameters:
  • r - the S3Request
  • attr - dictionary of parameters for the method handler

review(self, r, **attr)

source code 

Review/approve/reject an unapproved record.

Parameters:
  • r - the S3Request
  • attr - dictionary of parameters for the method handler

validate(self, r, **attr)

source code 

Validate records (AJAX). This method reads a JSON object from
the request body, validates it against the current resource,
and returns a JSON object with either the validation errors or
the text representations of the data.

@param r: the S3Request
@param attr: dictionary of parameters for the method handler

Input JSON format:

{"<fieldname>":"<value>", "<fieldname>":"<value>"}

Output JSON format:

{"<fieldname>": {"value":"<value>",
                 "text":"<representation>",
                 "_error":"<error message>"}}

The input JSON can also be a list of multiple records. This
will return a list of results accordingly. Note that "text"
is not provided if there was a validation error, and vice
versa.

The record ID should always be present in the JSON to
avoid false duplicate errors.

Non-existent fields will return "invalid field" as _error.

Representations will be URL-escaped and any markup stripped.

The ?component=<alias> URL query can be used to specify a
component of the current resource rather than the main table.

This method does only accept .json format.

crud_button(label=None, tablename=None, name=None, icon=None, _href=None, _id=None, _class=None, _title=None, _target=None, **attr)
Static Method

source code 

Generate a CRUD action button

Parameters:
  • label - the link label (None if using CRUD string)
  • tablename - the name of table for CRUD string selection
  • name - name of CRUD string for the button label
  • icon - name of the icon (e.g. "add")
  • _href - the target URL
  • _id - the HTML id of the link
  • _class - the HTML class of the link
  • _title - the HTML title of the link
  • _target - the HTML target of the link
  • custom - custom CRUD button (just add classes)

last_update(self)

source code 

Get the last update meta-data of the current record

Returns:
a dict {modified_by: <user>, modified_on: <datestr>}, depending on which of these attributes are available in the current record

render_buttons(self, r, buttons, record_id=None, **attr)

source code 

Render CRUD buttons

Parameters:
  • r - the S3Request
  • buttons - list of button names, any of: "add", "edit", "delete", "list", "summary"
  • record_id - the record ID
  • attr - the controller attributes
Returns:
a dict of buttons for the view

action_button(label, url, icon=None, **attr)
Static Method

source code 

Add a link to response.s3.actions

Parameters:
  • label - the link label
  • url - the target URL
  • attr - attributes for the link (default: {"_class":"action-btn"})

action_buttons(cls, r, deletable=True, editable=None, copyable=False, read_url=None, delete_url=None, update_url=None, copy_url=None)
Class Method

source code 

Provide the usual action buttons in list views. Allow customizing the urls, since this overwrites anything that would be inserted by CRUD/select via linkto. The resource id should be represented by "[id]".

Parameters:
  • r - the S3Request
  • deletable - records can be deleted
  • editable - records can be modified
  • copyable - record data can be copied into new record
  • read_url - URL to read a record
  • delete_url - URL to delete a record
  • update_url - URL to update a record
  • copy_url - URL to copy record data

Note: If custom actions are already configured at this point, they will appear AFTER the standard action buttons

import_csv(self, stream, table=None)

source code 

Import CSV file into database

Parameters:
  • stream - file handle
  • table - the table to import to

import_url(r)
Static Method

source code 

Import data from vars in URL query

Parameters:
  • r - the S3Request

Note: can only update single records (no mass-update)

To Do:
  • update for link table components
  • re-integrate into S3Importer