Changes between Version 39 and Version 40 of DeveloperGuidelinesNewModule


Ignore:
Timestamp:
06/27/10 09:33:02 (11 years ago)
Author:
Fran Boon
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • DeveloperGuidelinesNewModule

    v39 v40  
    1818To avoid namespace clashes, use the format: {{{db.module_table}}}
    1919
    20 e.g. if building a Vehicle Management System, create db.veh_vehicle:
     20e.g. if building a Vehicle Management System, create db.vts_vehicle:
    2121{{{
    22 module = 'veh'
    23 resource = 'vehicle'
     22module = "vts"
     23resource = "vehicle"
    2424
    25 tablename = module + '_' + resource
     25tablename = module + "_" + resource
    2626table = db.define_table(tablename, timestamp, uuidstamp,
    27                 Field('name'))
    28 table.uuid.requires = IS_NOT_IN_DB(db, '%s.uuid' % table)
     27                Field("name"))
     28table.uuid.requires = IS_NOT_IN_DB(db, "%s.uuid" % table)
    2929table.name.requires = IS_NOT_EMPTY()
    3030table.name.comment = SPAN("*", _class="req")
    31 }}}
    32 
    33 Add the messages for your resources:
    34 {{{
    35 s3.crud_strings[tablename] = Storage(
    36     title_create = T('Add Vehicle'),
    37     title_display = T('Vehicle Details'),
    38     title_list = T('List Vehicles'),
    39     title_update = T('Edit Vehicle'),
    40     title_search = T('Search Vehicles'),
    41     subtitle_create = T('Add New Vehicle'),
    42     subtitle_list = T('Vehicles'),
    43     label_list_button = T('List Vehicles'),
    44     label_create_button = T('Add Vehicle'),
    45     label_delete_button = T('Delete Vehicle'),
    46     msg_record_created = T('Vehicle added'),
    47     msg_record_modified = T('Vehicle updated'),
    48     msg_record_deleted = T('Vehicle deleted'),
    49     msg_list_empty = T('No Vehicles currently registered'))
    5031}}}
    5132
     
    5334Create a file: {{{/controllers/<MODULE NAME>.py}}}
    5435
    55 Add the S3 framework functions:
     36Add CRUD functions for your tables:
    5637{{{
    57 module = 'veh'
     38module = request.controller
    5839
     40def vehicle():
     41    "RESTful CRUD controller"
     42    resource = request.function
     43    return shn_rest_controller(module, resource)
     44}}}
     45
     46Manual method for if/when you need more control: DeveloperGuidelinesCreateReadUpdateDelete
     47
     48Add the messages for your resources:
     49{{{
     50def vehicle():
     51    "RESTful CRUD controller"
     52    resource = request.function
     53    s3.crud_strings[tablename] = Storage(
     54        title_create = T("Add Vehicle"),
     55        title_display = T("Vehicle Details"),
     56        title_list = T("List Vehicles"),
     57        title_update = T("Edit Vehicle"),
     58        title_search = T("Search Vehicles"),
     59        subtitle_create = T("Add New Vehicle"),
     60        subtitle_list = T("Vehicles"),
     61        label_list_button = T("List Vehicles"),
     62        label_create_button = T("Add Vehicle"),
     63        label_delete_button = T("Delete Vehicle"),
     64        msg_record_created = T("Vehicle added"),
     65        msg_record_modified = T("Vehicle updated"),
     66        msg_record_deleted = T("Vehicle deleted"),
     67        msg_list_empty = T("No Vehicles currently registered"))
     68
     69    return shn_rest_controller(module, resource)
     70}}}
     71
     72Add a menu:
     73{{{
    5974# Options Menu (available in all Functions' Views)
    6075response.menu_options = [
     
    6479    [T("Search Vehicles"), False, URL(r=request, f="vehicle", args="search")]
    6580]
    66 
    6781}}}
    68 
    69 Add CRUD functions for your tables:
    70 {{{
    71 def vehicle():
    72     "RESTful CRUD controller"
    73     return shn_rest_controller(module, "vehicle")
    74 }}}
    75 
    76 Manual method for if/when you need more control: DeveloperGuidelinesCreateReadUpdateDelete
    7782
    7883=== Views ===
     
    8287If Custom Views are wanted they are detected automatically if files are found in {{{/views/<MODULE NAME>/<RESOURCE>_<METHOD>.html}}}
    8388
     89----
    8490DeveloperGuidelines