Changes between Version 42 and Version 43 of RESTController


Ignore:
Timestamp:
05/27/10 22:15:56 (12 years ago)
Author:
Fran Boon
Comment:

Syntax of examples: " vs '

Legend:

Unmodified
Added
Removed
Modified
  • RESTController

    v42 v43  
    55Available since: [https://code.launchpad.net/sahana-eden Main Trunk] Revision 358+
    66
    7 The so called '''REST Controller''' (function ''shn_rest_controller()'') is a wrapper function for [wiki:S3REST], which provides generic CRUD method handlers. These method handlers as well as the REST controller itself are implemented in models/01_crud.py.
     7The so called '''REST Controller''' (function ''shn_rest_controller()'') is a wrapper function for [wiki:S3REST], which provides generic CRUD method handlers. These method handlers as well as the REST controller itself are implemented in {{{models/01_crud.py}}}.
    88
    99'''[wiki:S3REST]''' provides a generic '''RESTful API''' ([http://en.wikipedia.org/wiki/Representational_State_Transfer Representational State Transfer]) for Sahana Eden database resources, i.e. it can map HTTP requests to data resources and function calls. In particular, it maps resource addresses (=URL's) and HTTP methods (=GET, PUT, DELETE etc.) to CRUD actions, and then invokes so called ''method handlers'' (provided by the calling controller via hooks) to execute those actions (important: S3REST itself does not manipulate any data!).
     
    6363
    6464{{{
    65 resource = 'image'
    66 table = module + '_' + resource
     65resource = "image"
     66table = module + "_" + resource
    6767db.define_table(table, timestamp, uuidstamp, deletion_status,
    6868                pr_pe_id,
    6969                opt_pr_image_type,
    70                 Field('title'),
    71                 Field('image', 'upload', autodelete=True),
    72                 Field('description'),
    73                 Field('comment'),
     70                Field("title"),
     71                Field("image", "upload", autodelete=True),
     72                Field("description"),
     73                Field("comment"),
    7474                migrate=migrate)
    7575
     
    7777s3xrc.model.add_component(module, resource,
    7878    multiple=True,
    79     joinby='pr_pe_id',
     79    joinby="pr_pe_id",
    8080    deletable=True,
    8181    editable=True,
    82     list_fields = ['id', 'opt_pr_image_type', 'image', 'title', 'description'])
     82    list_fields = ["id", "opt_pr_image_type", "image", "title", "description"])
    8383}}}
    8484
     
    9393      - ''tablename'' is the name of the respective primary table
    9494      - ''fieldname'' the name of the foreign key in the component table that points to the ''id'' field in the primary table
    95       - e.g. {{{joinby = dict(pr_person='person_id')}}}
     95      - e.g. {{{joinby = dict(pr_person="person_id")}}}
    9696  - '''fields''' is a list of the fields in the component that shall appear in list views:
    9797    - if omitted or set to None, all readable fields will be included
     
    106106def person():
    107107    crud.settings.delete_onvalidation = shn_pentity_ondelete
    108     return shn_rest_controller(module, 'person', main='first_name', extra='last_name',
     108    return shn_rest_controller(module, "person", main="first_name", extra="last_name",
    109109        pheader=shn_pr_pheader,
    110         onvalidation=lambda form: shn_pentity_onvalidation(form, table='pr_person', entity_class=1),
     110        onvalidation=lambda form: shn_pentity_onvalidation(form, table="pr_person", entity_class=1),
    111111        onaccept=None)
    112112}}}
     
    130130def kit():
    131131    "REST CRUD controller"
    132     response.s3.formats.pdf = URL(r=request, f='kit_export_pdf')
    133     response.s3.formats.xls = URL(r=request, f='kit_export_xls')
     132    response.s3.formats.pdf = URL(r=request, f="kit_export_pdf")
     133    response.s3.formats.xls = URL(r=request, f="kit_export_xls")
    134134    if len(request.args) == 2:
    135         crud.settings.update_next = URL(r=request, f='kit_item', args=request.args[1])
    136     return shn_rest_controller(module, 'kit', main='code', onaccept=lambda form: kit_total(form))
     135        crud.settings.update_next = URL(r=request, f="kit_item", args=request.args[1])
     136    return shn_rest_controller(module, "kit", main="code", onaccept=lambda form: kit_total(form))
    137137}}}
    138138
     
    142142def report_overdue():
    143143    "Report on Overdue Invoices - those unpaid 30 days after receipt"
    144     response.title = T('Overdue Invoices')
     144    response.title = T("Overdue Invoices")
    145145    overdue = datetime.date.today() - timedelta(days=30)
    146146    response.s3.filter = (db.fin_invoice.date_out==None) & (db.fin_invoice.date_in < overdue)
    147147    s3.crud_strings.fin_invoice.title_list = response.title
    148     s3.crud_strings.fin_invoice.msg_list_empty = T('No Invoices currently overdue')
    149     return shn_rest_controller(module, 'invoice', deletable=False, listadd=False)
     148    s3.crud_strings.fin_invoice.msg_list_empty = T("No Invoices currently overdue")
     149    return shn_rest_controller(module, "invoice", deletable=False, listadd=False)
    150150}}}
    151151
     
    161161{{{
    162162# Plug into REST controller
    163 s3xrc.model.set_method(module, 'person', method='search_simple', action=shn_pr_person_search_simple )
     163s3xrc.model.set_method(module, "person", method="search_simple", action=shn_pr_person_search_simple )
    164164}}}
    165165
     
    175175def inbox():                                                                                                                 
    176176    " RESTlike CRUD controller for inbox"                                                                                     
    177     person = db(db.pr_person.uuid==auth.user.person_uuid).select(db.pr_person.id)                                             
     177    person = db(db.pr_person.uuid == auth.user.person_uuid).select(db.pr_person.id)                                             
    178178    response.s3.filer = (db.msg_inbox.person_id == person[0].id)                                                             
    179     s3xrc.model.set_method(module, 'inbox', method='create', action = restricted_method)                                     
    180     return shn_rest_controller(module, 'inbox', listadd=False, editable = False) 
     179    s3xrc.model.set_method(module, "inbox", method="create", action = restricted_method)                                     
     180    return shn_rest_controller(module, "inbox", listadd=False, editable = False) 
    181181
    182182}}}