Package web2py :: Package gluon :: Module tools :: Class Crud |
[hide private]
[frames] | no frames]

# Class Crud

source code

    object --+
             |
            Crud

Instance Methods | [hide private]
url(self, f=1, args=`[``]`, vars=`{``}`) this should point to the controller that exposes download and crud | source code
__init__(self, environment, db=1, controller=`'``default``'`) x.__init__(...) initializes x; see x.__class__.__doc__ for signature | source code
__call__(self) | source code
log_event(self, message) | source code
has_permission(self, name, table, record=0) | source code
tables(self) | source code
update(self, table, record, next=<function <lambda> at 0x26ba500>, onvalidation=<function <lambda> at 0x26ba500>, onaccept=<function <lambda> at 0x26ba500>, ondelete=<function <lambda> at 0x26ba500>, log=<function <lambda> at 0x26ba500>, message=<function <lambda> at 0x26ba500>, deletable=<function <lambda> at 0x26ba500>, formname=<function <lambda> at 0x26ba500>) .. | source code
create(self, table, next=<function <lambda> at 0x26ba500>, onvalidation=<function <lambda> at 0x26ba500>, onaccept=<function <lambda> at 0x26ba500>, log=<function <lambda> at 0x26ba500>, message=<function <lambda> at 0x26ba500>, formname=<function <lambda> at 0x26ba500>) .. | source code
read(self, table, record) | source code
delete(self, table, record_id, next=<function <lambda> at 0x26ba500>, message=<function <lambda> at 0x26ba500>) .. | source code
rows(self, table, query=1, fields=1, orderby=1, limitby=1) | source code
select(self, table, query=1, fields=1, orderby=1, limitby=1, headers=`{``}`, **attr) | source code
get_format(self, field) | source code
get_query(self, field, op, value, refsearch=True) | source code
search(self, *tables, **args) Creates a search form and its results for a table... | source code
Inherited from `object`: `__delattr__`, `__getattribute__`, `__hash__`, `__new__`, `__reduce__`, `__reduce_ex__`, `__repr__`, `__setattr__`, `__str__`

Static Methods | [hide private]
archive(form, archive_table=1, current_record=`'``current_record``'`) If you have a table (db.mytable) that needs full revision history you can just do: | source code

Properties | [hide private]
Inherited from `object`: `__class__`

Method Details | [hide private]

### __init__(self, environment, db=1, controller=`'``default``'`) (Constructor) | source code
x.__init__(...) initializes x; see x.__class__.__doc__ for signature Overrides: object.__init__ (inherited documentation)

### archive(form, archive_table=1, current_record=`'``current_record``'`) Static Method | source code
If you have a table (db.mytable) that needs full revision history you can just do:
       form=crud.update(db.mytable,myrecord,onaccept=crud.archive)
crud.archive will define a new table "mytable_archive" and store the previous record in the newly created table including a reference to the current record. If you want to access such table you need to define it yourself in a model:
       db.define_table('mytable_archive',
           Field('current_record',db.mytable),
           db.mytable)
Notice such table includes all fields of db.mytable plus one: current_record. crud.archive does not timestamp the stored record unless your original table has a fields like:
       db.define_table(...,
           Field('saved_on','datetime',
                default=request.now,update=request.now,writable=False),
           Field('saved_by',auth.user,
                default=auth.user_id,update=auth.user_id,writable=False),
there is nothing special about these fields since they are filled before the record is archived. If you want to change the archive table name and the name of the reference field you can do, for example:
       db.define_table('myhistory',
           Field('parent_record',db.mytable),
           db.mytable)
and use it as:
       form=crud.update(db.mytable,myrecord,
                        onaccept=lambda form:crud.archive(form,
                        archive_table=db.myhistory,
                        current_record='parent_record'))

### update(self, table, record, next=<function <lambda> at 0x26ba500>, onvalidation=<function <lambda> at 0x26ba500>, onaccept=<function <lambda> at 0x26ba500>, ondelete=<function <lambda> at 0x26ba500>, log=<function <lambda> at 0x26ba500>, message=<function <lambda> at 0x26ba500>, deletable=<function <lambda> at 0x26ba500>, formname=<function <lambda> at 0x26ba500>) | source code
    .. method:: Crud.update(table, record, [next=DEFAULT
        [, onvalidation=DEFAULT [, onaccept=DEFAULT [, log=DEFAULT
        [, message=DEFAULT[, deletable=DEFAULT]]]]]])

### create(self, table, next=<function <lambda> at 0x26ba500>, onvalidation=<function <lambda> at 0x26ba500>, onaccept=<function <lambda> at 0x26ba500>, log=<function <lambda> at 0x26ba500>, message=<function <lambda> at 0x26ba500>, formname=<function <lambda> at 0x26ba500>) | source code
    .. method:: Crud.create(table, [next=DEFAULT [, onvalidation=DEFAULT
        [, onaccept=DEFAULT [, log=DEFAULT[, message=DEFAULT]]]]])

### delete(self, table, record_id, next=<function <lambda> at 0x26ba500>, message=<function <lambda> at 0x26ba500>) | source code
    .. method:: Crud.delete(table, record_id, [next=DEFAULT
        [, message=DEFAULT]])

### search(self, *tables, **args) | source code
    Creates a search form and its results for a table
    Example usage:
    form, results = crud.search(db.test,
                           queries = ['equals', 'not equal', 'contains'],
                           query_labels={'equals':'Equals',
                                         'not equal':'Not equal'},
                           fields = ['id','children'],
                           field_labels = {'id':'ID','children':'Children'},
                           zero='Please choose',
                           query = (db.test.id > 0)&(db.test.id != 3) )