Changes between Version 25 and Version 26 of DeveloperGuidelinesNewModule


Ignore:
Timestamp:
05/20/09 20:59:39 (13 years ago)
Author:
Fran Boon
Comment:

No more modules=modules, Python style

Legend:

Unmodified
Added
Removed
Modified
  • DeveloperGuidelinesNewModule

    v25 v26  
    3030This needs a table to store the module's menu options in:
    3131{{{
    32 module='name'
     32module = 'name'
    3333
    3434# Menu Options
     
    3636                db.Field('name'),
    3737                db.Field('function'),
    38                 db.Field('description',length=256),
    39                 db.Field('priority','integer'),
    40                 db.Field('enabled','boolean',default='True'))
    41 db['%s_menu_option' % module].name.requires=[IS_NOT_EMPTY(),IS_NOT_IN_DB(db,'%s_menu_option.name' % module)]
    42 db['%s_menu_option' % module].name.requires=IS_NOT_EMPTY()
    43 db['%s_menu_option' % module].priority.requires=[IS_NOT_EMPTY(),IS_NOT_IN_DB(db,'%s_menu_option.priority' % module)]
     38                db.Field('description', length=256),
     39                db.Field('priority', 'integer'),
     40                db.Field('enabled', 'boolean', default='True'))
     41db['%s_menu_option' % module].name.requires = [IS_NOT_EMPTY(), IS_NOT_IN_DB(db, '%s_menu_option.name' % module)]
     42db['%s_menu_option' % module].name.requires = IS_NOT_EMPTY()
     43db['%s_menu_option' % module].priority.requires = [IS_NOT_EMPTY(), IS_NOT_IN_DB(db, '%s_menu_option.priority' % module)]
    4444}}}
    4545Populate this table with the functions that you wish to expose to the module's front page & left-hand navigation bar:
     
    8181e.g. if building a Vehicle Management System, create db.veh_vehicle:
    8282{{{
    83 module='veh'
    84 resource='vehicle'
    85 table=module+'_'+resource
    86 db.define_table(table,timestamp,uuidstamp,
     83module = 'veh'
     84resource = 'vehicle'
     85table = module + '_' + resource
     86db.define_table(table, timestamp, uuidstamp,
    8787                db.Field('name'))
    88 s3.crud_fields[table]=['name']
    89 db[table].exposes=s3.crud_fields[table]
    90 db[table].uuid.requires=IS_NOT_IN_DB(db,'%s.uuid' % table)
    91 db.veh_vehicle.name.requires=IS_NOT_EMPTY()
    92 db.veh_vehicle.name.comment=SPAN("*",_class="req")
     88db[table].uuid.requires = IS_NOT_IN_DB(db, '%s.uuid' % table)
     89db.veh_vehicle.name.requires = IS_NOT_EMPTY()
     90db.veh_vehicle.name.comment = SPAN("*", _class="req")
    9391}}}
    9492
    9593Also add the messages for your resources:
    9694{{{
    97 title_create=T('Add Vehicle')
    98 title_display=T('Vehicle Details')
    99 title_list=T('List Vehicles')
    100 title_update=T('Edit Vehicle')
    101 title_search=T('Search Vehicles')
    102 subtitle_create=T('Add New Vehicle')
    103 subtitle_list=T('Vehicles')
    104 label_list_button=T('List Vehicles')
    105 label_create_button=T('Add Vehicle')
    106 msg_record_created=T('Vehicle added')
    107 msg_record_modified=T('Vehicle updated')
    108 msg_record_deleted=T('Vehicle deleted')
    109 msg_list_empty=T('No Vehicles currently registered')
    110 crud_strings[table]=Storage(title_create=title_create, title_display=title_display, title_list=title_list, title_update=title_update, subtitle_create=subtitle_create, subtitle_list=subtitle_list, label_list_button=label_list_button, label_create_button=label_create_button, msg_record_created=msg_record_created, msg_record_modified=msg_record_modified, msg_record_deleted=msg_record_deleted, msg_list_empty=msg_list_empty)
     95title_create = T('Add Vehicle')
     96title_display = T('Vehicle Details')
     97title_list = T('List Vehicles')
     98title_update = T('Edit Vehicle')
     99title_search = T('Search Vehicles')
     100subtitle_create = T('Add New Vehicle')
     101subtitle_list = T('Vehicles')
     102label_list_button = T('List Vehicles')
     103label_create_button = T('Add Vehicle')
     104msg_record_created = T('Vehicle added')
     105msg_record_modified = T('Vehicle updated')
     106msg_record_deleted = T('Vehicle deleted')
     107msg_list_empty = T('No Vehicles currently registered')
     108crud_strings[table] = Storage(title_create=title_create, title_display=title_display, title_list=title_list, title_update=title_update, subtitle_create=subtitle_create, subtitle_list=subtitle_list, label_list_button=label_list_button, label_create_button=label_create_button, msg_record_created=msg_record_created, msg_record_modified=msg_record_modified, msg_record_deleted=msg_record_deleted, msg_list_empty=msg_list_empty)
    111109}}}
    112110
     
    116114Add the S3 framework functions:
    117115{{{
    118 module='veh'
     116module = 'veh'
    119117# Current Module (for sidebar title)
    120 module_name=db(db.s3_module.name==module).select()[0].name_nice
    121 # List Modules (from which to build Menu of Modules)
    122 modules=db(db.s3_module.enabled=='Yes').select(db.s3_module.ALL,orderby=db.s3_module.priority)
     118module_name = db(db.s3_module.name==module).select()[0].name_nice
    123119# List Options (from which to build Menu for this Module)
    124 options=db(db['%s_menu_option' % module].enabled=='Yes').select(db['%s_menu_option' % module].ALL,orderby=db['%s_menu_option' % module].priority)
     120options = db(db['%s_menu_option' % module].enabled=='Yes').select(db['%s_menu_option' % module].ALL, orderby=db['%s_menu_option' % module].priority)
    125121}}}
    126122
     
    129125def vehicle():
    130126    "RESTful CRUD controller"
    131     return shn_rest_controller(module,'vehicle')
     127    return shn_rest_controller(module, 'vehicle')
    132128}}}
    133129