def ns_only(f, required=True, branches=True, updateable=True): """ Function to configure an organisation_id field to be restricted to just NS/Branch """ # Label if branches: f.label = T("National Society / Branch") else: f.label = T("National Society") # Requires db = current.db ttable = db.org_organisation_type type_id = db(ttable.name == "Red Cross / Red Crescent").select( ttable.id, limitby=(0, 1)).first().id if branches: not_filterby = None not_filter_opts = [] else: btable = db.org_organisation_branch rows = db(btable.deleted != True).select(btable.branch_id) branches = [row.branch_id for row in rows] not_filterby = "id" not_filter_opts = branches requires = IS_ONE_OF(db, "org_organisation.id", current.s3db.org_OrganisationRepresent(), filterby="organisation_type_id", filter_opts=[type_id], not_filterby=not_filterby, not_filter_opts=not_filter_opts, updateable=updateable, orderby="org_organisation.name", sort=True) if not required: requires = IS_EMPTY_OR(requires) f.requires = requires # Dropdown not Autocomplete f.widget = None # Comment s3_has_role = current.auth.s3_has_role if s3_has_role("ADMIN") or \ s3_has_role("ORG_ADMIN"): # Need to do import after setting Theme from s3layouts import S3AddResourceLink f.comment = S3AddResourceLink( c="org", f="organisation", vars={ "organisation.organisation_type_id$name": "Red Cross / Red Crescent" }, label=T("Add National Society"), title=T("National Society"), ) else: # Not allowed to add NS f.comment = ""
def testAddResourceLink(self): """ Test AddResourceLink """ auth = current.auth deployment_settings = current.deployment_settings comment = S3AddResourceLink(c="pr", f="person") # If the module is active, the comment should always be active self.assertEqual(comment.check_active(), deployment_settings.has_module("pr")) self.assertEqual(comment.method, "create") # Label should fall back to CRUD string from s3.s3crud import S3CRUD crud_string = S3CRUD.crud_string("pr_person", "label_create_button") self.assertEqual(comment.label, crud_string) if "inv" in deployment_settings.modules: comment = S3AddResourceLink(c="inv", f="inv_item") # Deactivate module inv = deployment_settings.modules["inv"] del deployment_settings.modules["inv"] # Comment should auto-deactivate self.assertFalse(comment.check_active()) # Restore module deployment_settings.modules["inv"] = inv # Comment should auto-reactivate self.assertTrue(comment.check_active()) self.assertFalse(comment.check_permission()) self.assertEqual(comment.xml(), "") auth.s3_impersonate("*****@*****.**") self.assertTrue(comment.check_permission()) output = comment.xml() self.assertTrue(type(output) is str) self.assertNotEqual(output, "") auth.s3_impersonate(None)
def person_id_comment(fieldname): T = current.T c_title = T("Person.") c_comment = T("Type the first few characters of one of the Person's names.") ADD_PERSON = T("Add Person") return S3AddResourceLink(c="pr", f="person", vars=dict(child=fieldname), label=ADD_PERSON, title=c_title, tooltip=c_comment)
def model(self): T = current.T db = current.db add_component = self.add_component configure = self.configure crud_strings = current.response.s3.crud_strings define_table = self.define_table settings = current.deployment_settings # --------------------------------------------------------------------- # Series # - lists of Posts displaying in recent-first mode # tablename = "cms_series" table = define_table( tablename, Field("name", length=255, notnull=True, unique=True, label=T("Name")), Field("avatar", "boolean", default=False, represent=s3_yes_no_represent, label=T("Show author picture?")), Field("location", "boolean", default=False, represent=s3_yes_no_represent, label=T("Show Location?")), Field("richtext", "boolean", default=True, represent=s3_yes_no_represent, label=T("Rich Text?")), Field("replies", "boolean", default=False, represent=s3_yes_no_represent, label=T("Comments permitted?")), s3_comments(), # Multiple Roles (@ToDo: Implement the restriction) s3_roles_permitted(readable=False, writable=False), *s3_meta_fields()) # CRUD Strings ADD_SERIES = T("Add Series") crud_strings[tablename] = Storage( title_create=ADD_SERIES, title_display=T("Series Details"), title_list=T("Series"), title_update=T("Edit Series"), title_search=T("Search Series"), title_upload=T("Import Series"), subtitle_create=T("Add New Series"), label_list_button=T("List Series"), label_create_button=ADD_SERIES, msg_record_created=T("Series added"), msg_record_modified=T("Series updated"), msg_record_deleted=T("Series deleted"), msg_list_empty=T("No series currently defined")) # Reusable field translate = settings.get_L10n_translate_cms_series() represent = S3Represent(lookup=tablename, translate=translate) series_id = S3ReusableField("series_id", table, readable=False, writable=False, represent=represent, requires=IS_NULL_OR( IS_ONE_OF(db, "cms_series.id", represent)), ondelete="CASCADE") # Resource Configuration configure(tablename, onaccept=self.cms_series_onaccept, create_next=URL(f="series", args=["[id]", "post"])) # Components add_component("cms_post", cms_series="series_id") # --------------------------------------------------------------------- # Posts # - single blocks of rich text which can be embedded into a page, # be viewed as full pages or as part of a Series # tablename = "cms_post" table = define_table( tablename, self.super_link("doc_id", "doc_entity"), series_id(), Field( "name", #notnull=True, comment= T("This isn't visible to the published site, but is used to allow menu items to point to the page" ), label=T("Name")), Field( "title", comment=T( "The title of the page, as seen in the browser (optional)" ), label=T("Title")), Field("body", "text", notnull=True, widget=s3_richtext_widget, label=T("Body")), # @ToDo: Move this to link table self.gis_location_id(), # @ToDo: Just use series_id setting? Field("avatar", "boolean", default=False, represent=s3_yes_no_represent, label=T("Show author picture?")), Field("replies", "boolean", default=False, represent=s3_yes_no_represent, label=T("Comments permitted?")), s3_datetime(default="now"), # @ToDo: Also have a datetime for 'Expires On' Field("expired", "boolean", default=False, represent=s3_yes_no_represent, label=T("Expired?")), #Field("published", "boolean", # default=True, # label=T("Published")), s3_comments(), # Multiple Roles (@ToDo: Implement the restriction) s3_roles_permitted(readable=False, writable=False), *s3_meta_fields()) # CRUD Strings ADD_POST = T("Add Post") crud_strings[tablename] = Storage( title_create=ADD_POST, title_display=T("Post Details"), title_list=T("Posts"), title_update=T("Edit Post"), title_search=T("Search Posts"), title_upload=T("Import Posts"), subtitle_create=T("Add New Post"), label_list_button=T("List Posts"), label_create_button=ADD_POST, msg_record_created=T("Post added"), msg_record_modified=T("Post updated"), msg_record_deleted=T("Post deleted"), msg_list_empty=T("No posts currently defined")) # Reusable field represent = S3Represent(lookup=tablename) post_id = S3ReusableField( "post_id", table, label=T("Post"), sortby="name", requires=IS_NULL_OR(IS_ONE_OF(db, "cms_post.id", represent)), represent=represent, comment=S3AddResourceLink( c="cms", f="post", title=ADD_POST, tooltip= T("A block of rich text which could be embedded into a page, viewed as a complete page or viewed as a list of news items." )), ondelete="CASCADE") # Resource Configuration configure( tablename, super_entity="doc_entity", onaccept=self.cms_post_onaccept, orderby=~table.created_on, list_orderby=~table.created_on, context={ "event": "event.id", "location": "location_id", "organisation": "created_by$organisation_id", }, ) # Components add_component("cms_comment", cms_post="post_id") add_component("cms_post_module", cms_post="post_id") add_component("cms_tag", cms_post=Storage(link="cms_post_tag", joinby="post_id", key="tag_id", actuate="hide")) # For InlineForm to tag Posts to Events add_component("event_event_post", cms_post="post_id") # For Profile to filter appropriately add_component("event_event", cms_post=Storage(link="event_event_post", joinby="post_id", key="event_id", actuate="hide")) # --------------------------------------------------------------------- # Modules <> Posts link table # tablename = "cms_post_module" table = define_table( tablename, post_id(), Field( "module", comment= T("If you specify a module then this will be used as the text in that module's index page" ), label=T("Module")), Field( "resource", comment= T("If you specify a resource then this will be used as the text in that resource's summary page" ), label=T("Resource")), *s3_meta_fields()) # CRUD Strings ADD_POST = T("Add Post") crud_strings[tablename] = Storage( title_create=ADD_POST, title_display=T("Post Details"), title_list=T("Posts"), title_update=T("Edit Post"), subtitle_create=T("Add New Post"), label_list_button=T("List Posts"), label_create_button=ADD_POST, msg_record_created=T("Post set as Module/Resource homepage"), msg_record_modified=T("Post updated"), msg_record_deleted=T("Post removed"), msg_list_empty=T( "No posts currently set as module/resource homepages")) # --------------------------------------------------------------------- # Tags # tablename = "cms_tag" table = define_table( tablename, Field("name", label=T("Tag")), s3_comments(), # Multiple Roles (@ToDo: Implement the restriction) #s3_roles_permitted(readable = False, # writable = False # ), *s3_meta_fields()) # CRUD Strings ADD_TAG = T("Add Tag") crud_strings[tablename] = Storage( title_create=ADD_TAG, title_display=T("Tag Details"), title_list=T("Tags"), title_update=T("Edit Tag"), title_search=T("Search Tags"), title_upload=T("Import Tags"), subtitle_create=T("Add New Tag"), label_list_button=T("List Tags"), label_create_button=ADD_TAG, msg_record_created=T("Tag added"), msg_record_modified=T("Tag updated"), msg_record_deleted=T("Tag deleted"), msg_list_empty=T("No tags currently defined")) # --------------------------------------------------------------------- # Tags <> Posts link table # tablename = "cms_tag_post" table = define_table(tablename, post_id(), Field("tag_id", "reference cms_tag"), *s3_meta_fields()) # CRUD Strings ADD_TAG = T("Tag Post") crud_strings[tablename] = Storage( title_create=ADD_TAG, title_display=T("Tag Details"), title_list=T("Tags"), title_update=T("Edit Tag"), title_search=T("Search Tags"), title_upload=T("Import Tags"), subtitle_create=T("Add New Tag"), label_list_button=T("List Tagged Posts"), label_create_button=ADD_TAG, msg_record_created=T("Post Tagged"), msg_record_modified=T("Tag updated"), msg_record_deleted=T("Tag removed"), msg_list_empty=T("No posts currently tagged")) # --------------------------------------------------------------------- # Comments # - threaded comments on Posts # # @ToDo: Attachments? # # Parent field allows us to: # * easily filter for top-level threads # * easily filter for next level of threading # * hook a new reply into the correct location in the hierarchy # tablename = "cms_comment" table = define_table( tablename, Field("parent", "reference cms_comment", requires=IS_NULL_OR(IS_ONE_OF(db, "cms_comment.id")), readable=False), post_id(), Field("body", "text", notnull=True, label=T("Comment")), *s3_meta_fields()) # Resource Configuration configure(tablename, list_fields=["id", "post_id", "created_by", "modified_on"]) # --------------------------------------------------------------------- # Pass names back to global scope (s3.*) # return Storage(cms_post_id=post_id, )
def model(self): T = current.T db = current.db s3 = current.response.s3 settings = current.deployment_settings configure = self.configure crud_strings = s3.crud_strings define_table = self.define_table messages = current.messages super_link = self.super_link set_method = self.set_method NAME = T("Name") if settings.get_org_autocomplete(): org_widget = S3OrganisationAutocompleteWidget( default_from_profile=True) else: org_widget = None # ------------------------------------------------------------------------- # Shelter types # e.g. NGO-operated, Government evacuation center, School, Hospital -- see Agasti opt_camp_type.) tablename = "cr_shelter_type" define_table( tablename, Field( "name", notnull=True, label=NAME, requires=IS_NOT_ONE_OF(db, "%s.name" % tablename), ), s3_comments(), *s3_meta_fields()) # CRUD strings if settings.get_ui_label_camp(): ADD_SHELTER_TYPE = T("Add Camp Type") SHELTER_TYPE_LABEL = T("Camp Type") crud_strings[tablename] = Storage( label_create=ADD_SHELTER_TYPE, title_display=T("Camp Type Details"), title_list=T("Camp Types"), title_update=T("Edit Camp Type"), label_list_button=T("List Camp Types"), msg_record_created=T("Camp Type added"), msg_record_modified=T("Camp Type updated"), msg_record_deleted=T("Camp Type deleted"), msg_list_empty=T("No Camp Types currently registered")) else: ADD_SHELTER_TYPE = T("Create Shelter Type") SHELTER_TYPE_LABEL = T("Shelter Type") crud_strings[tablename] = Storage( label_create=ADD_SHELTER_TYPE, title_display=T("Shelter Type Details"), title_list=T("Shelter Types"), title_update=T("Edit Shelter Type"), label_list_button=T("List Shelter Types"), msg_record_created=T("Shelter Type added"), msg_record_modified=T("Shelter Type updated"), msg_record_deleted=T("Shelter Type deleted"), msg_list_empty=T("No Shelter Types currently registered")) configure( tablename, deduplicate=self.cr_shelter_type_duplicate, ) represent = S3Represent(lookup=tablename) shelter_type_id = S3ReusableField( "shelter_type_id", "reference %s" % tablename, label=SHELTER_TYPE_LABEL, ondelete="RESTRICT", represent=represent, requires=IS_EMPTY_OR(IS_ONE_OF(db, "cr_shelter_type.id", represent)), comment=S3AddResourceLink(c="cr", f="shelter_type", label=ADD_SHELTER_TYPE), ) # ------------------------------------------------------------------------- # Shelter services # e.g. medical, housing, food, ... tablename = "cr_shelter_service" define_table(tablename, Field( "name", notnull=True, label=NAME, ), s3_comments(), *s3_meta_fields()) # CRUD strings if settings.get_ui_label_camp(): ADD_SHELTER_SERVICE = T("Add Camp Service") SHELTER_SERVICE_LABEL = T("Camp Service") crud_strings[tablename] = Storage( label_create=ADD_SHELTER_SERVICE, title_display=T("Camp Service Details"), title_list=T("Camp Services"), title_update=T("Edit Camp Service"), label_list_button=T("List Camp Services"), msg_record_created=T("Camp Service added"), msg_record_modified=T("Camp Service updated"), msg_record_deleted=T("Camp Service deleted"), msg_list_empty=T("No Camp Services currently registered")) else: ADD_SHELTER_SERVICE = T("Create Shelter Service") SHELTER_SERVICE_LABEL = T("Shelter Service") crud_strings[tablename] = Storage( label_create=ADD_SHELTER_SERVICE, title_display=T("Shelter Service Details"), title_list=T("Shelter Services"), title_update=T("Edit Shelter Service"), label_list_button=T("List Shelter Services"), msg_record_created=T("Shelter Service added"), msg_record_modified=T("Shelter Service updated"), msg_record_deleted=T("Shelter Service deleted"), msg_list_empty=T("No Shelter Services currently registered")) service_represent = S3Represent(lookup=tablename) service_multirepresent = S3Represent(lookup=tablename, multiple=True) shelter_service_id = S3ReusableField( "shelter_service_id", "list:reference cr_shelter_service", label=SHELTER_SERVICE_LABEL, ondelete="RESTRICT", represent=self.cr_shelter_service_multirepresent, requires=IS_EMPTY_OR( IS_ONE_OF(db, "cr_shelter_service.id", self.cr_shelter_service_represent, multiple=True)), sortby="name", comment=S3AddResourceLink(c="cr", f="shelter_service", label=ADD_SHELTER_SERVICE), widget=S3MultiSelectWidget(header=False, ), ) # ------------------------------------------------------------------------- cr_shelter_opts = {1: T("Closed"), 2: T("Open")} dynamic = settings.get_cr_shelter_population_dynamic() tablename = "cr_shelter" define_table(tablename, super_link("doc_id", "doc_entity"), super_link("pe_id", "pr_pentity"), super_link("site_id", "org_site"), #Field("code", # length=10, # Mayon compatibility # notnull=True, # unique=True, label=T("Code")), Field("name", notnull=True, length=64, # Mayon compatibility label = T("Shelter Name"), requires = IS_NOT_EMPTY(), ), self.org_organisation_id( widget = org_widget, ), shelter_type_id(), # e.g. NGO-operated, Government evacuation center, School, Hospital -- see Agasti opt_camp_type.) shelter_service_id(), # e.g. medical, housing, food, ... self.gis_location_id(), Field("phone", label = T("Phone"), requires = IS_EMPTY_OR(s3_phone_requires), ), Field("email", "string", label = T("Email"), ), self.pr_person_id(label = T("Contact Person / Camp Owner")), #Static field Field("population", "integer", label = T("Estimated Population"), represent = lambda v: IS_INT_AMOUNT.represent(v), requires = IS_EMPTY_OR( IS_INT_IN_RANGE(0, 999999)), readable = not dynamic, writable = not dynamic, comment = DIV(_class="tooltip", _title="%s|%s" % (T("Current estimated population"), T("Current estimated population in shelter. Staff, Volunteers and Evacuees."))), ), Field("capacity_day", "integer", default = 0, label = T("Evacuees Capacity (Day and Night)"), represent = lambda v: IS_INT_AMOUNT.represent(v), requires = IS_EMPTY_OR( IS_INT_IN_RANGE(0, 999999)), comment = DIV(_class="tooltip", _title="%s|%s" % (T("Capacity (Day and Night)"), T("Capacity of the shelter for people who need to stay both day and night"))), ), Field("capacity_night", "integer", default = 0, label = T("Evacuees Capacity (Night only)"), represent = lambda v: IS_INT_AMOUNT.represent(v), requires = IS_EMPTY_OR( IS_INT_IN_RANGE(0, 999999)), comment = DIV(_class="tooltip", _title="%s|%s" % (T("Capacity (Night only)"), T("Capacity of the shelter for people who need to stay for night only"))), ), Field("available_capacity_day", "integer", default = 0, label = T("Evacuees Available Capacity (Day and Night)"), represent = lambda v: IS_INT_AMOUNT.represent(v), requires = IS_EMPTY_OR( IS_INT_IN_RANGE(0, 999999)), readable = dynamic, # Automatically updated writable = False, ), Field("available_capacity_night", "integer", default = 0, label = T("Evacuees Available Capacity (Night only)"), represent = lambda v: IS_INT_AMOUNT.represent(v), requires = IS_EMPTY_OR( IS_INT_IN_RANGE(0, 999999)), readable = dynamic, # Automatically updated writable = False, ), Field("population_day", "integer", default = 0, label = T("Evacuees Current Population (Day and Night)"), represent = lambda v: IS_INT_AMOUNT.represent(v), requires = IS_EMPTY_OR( IS_INT_IN_RANGE(0, 999999)), comment = DIV(_class="tooltip", _title="%s|%s" % (T("Population (Day)"), T("Number of evacuees registered in the shelter for day and night"))), readable = dynamic, # Automatically updated writable = False ), Field("population_night", "integer", default = 0, label = T("Evacuues Current Population (Night only)"), represent = lambda v: IS_INT_AMOUNT.represent(v), requires = IS_EMPTY_OR( IS_INT_IN_RANGE(0, 999999)), comment = DIV(_class="tooltip", _title="%s|%s" % (T("Population (Night)"), T("Number of people registered in the shelter for night only"))), readable = dynamic, # Automatically updated writable = False ), Field("status", "integer", label = T("Status"), represent = lambda opt: \ cr_shelter_opts.get(opt, messages.UNKNOWN_OPT), requires = IS_EMPTY_OR( IS_IN_SET(cr_shelter_opts) ), ), Field("source", label = T("Source"), readable = False, writable = False, ), s3_comments(), Field("obsolete", "boolean", default = False, label = T("Obsolete"), represent = lambda opt: \ (opt and [T("Obsolete")] or [messages["NONE"]])[0], readable = False, writable = False, ), *s3_meta_fields()) # CRUD strings if settings.get_ui_label_camp(): ADD_SHELTER = T("Add Camp") SHELTER_LABEL = T("Camp") SHELTER_HELP = T("The Camp this Request is from") crud_strings[tablename] = Storage( label_create=ADD_SHELTER, title_display=T("Camp Details"), title_list=T("Camps"), title_update=T("Edit Camp"), label_list_button=T("List Camps"), msg_record_created=T("Camp added"), msg_record_modified=T("Camp updated"), msg_record_deleted=T("Camp deleted"), msg_list_empty=T("No Camps currently registered")) else: ADD_SHELTER = T("Create Shelter") SHELTER_LABEL = T("Shelter") SHELTER_HELP = T("The Shelter this Request is from") crud_strings[tablename] = Storage( label_create=ADD_SHELTER, title_display=T("Shelter Details"), title_list=T("Shelters"), title_update=T("Edit Shelter"), label_list_button=T("List Shelters"), msg_record_created=T("Shelter added"), msg_record_modified=T("Shelter updated"), msg_record_deleted=T("Shelter deleted"), msg_list_empty=T("No Shelters currently registered")) # Which levels of Hierarchy are we using? levels = current.gis.get_relevant_hierarchy_levels() report_fields = [ "name", "shelter_type_id", #"organisation_id", "status", ] if dynamic: report_fields.extend(( "population_day", "population_night", )) else: # Manual report_fields.append("population") text_fields = [ "name", "code", "comments", "organisation_id$name", "organisation_id$acronym", "location_id$name", ] list_fields = [ "id", "name", "status", "shelter_type_id", #"shelter_service_id", ] if dynamic: list_fields.extend(( "capacity_day", "capacity_night", "population_day", "population_night", )) else: # Manual list_fields.append("population") list_fields.append("location_id$addr_street") #list_fields.append("person_id") for level in levels: lfield = "location_id$%s" % level report_fields.append(lfield) text_fields.append(lfield) list_fields.append(lfield) cr_shelter_status_filter_opts = dict(cr_shelter_opts) cr_shelter_status_filter_opts[None] = T("Unspecified") if settings.get_org_branches(): org_filter = S3HierarchyFilter( "organisation_id", leafonly=False, ) else: org_filter = S3OptionsFilter( "organisation_id", filter=True, header="", #hidden = True, ) filter_widgets = [ S3TextFilter( text_fields, label=T("Name"), _class="filter-search", ), S3OptionsFilter( "shelter_type_id", label=T("Type"), #Doesn't translate #represent = "%(name)s", ), org_filter, S3LocationFilter( "location_id", label=T("Location"), levels=levels, ), S3OptionsFilter( "status", label=T("Status"), options=cr_shelter_status_filter_opts, none=True, ), ] if dynamic: filter_widgets.append( S3RangeFilter( "available_capacity_night", label=T("Available Capacity (Night)"), )) filter_widgets.append( S3RangeFilter( "capacity_night", label=T("Total Capacity (Night)"), )) configure( tablename, deduplicate=self.cr_shelter_duplicate, filter_widgets=filter_widgets, list_fields=list_fields, onaccept=self.cr_shelter_onaccept, report_options=Storage( rows=report_fields, cols=report_fields, fact=report_fields, defaults=Storage( rows=lfield, # Lowest-level of hierarchy cols="status", fact="count(name)", totals=True)), super_entity=("org_site", "doc_entity", "pr_pentity"), ) # Reusable field represent = S3Represent(lookup=tablename) shelter_id = S3ReusableField( "shelter_id", "reference %s" % tablename, label=SHELTER_LABEL, ondelete="RESTRICT", represent=represent, requires=IS_EMPTY_OR( IS_ONE_OF(db, "cr_shelter.id", represent, sort=True)), comment=S3AddResourceLink(c="cr", f="shelter", label=ADD_SHELTER, title=SHELTER_LABEL, tooltip="%s (%s)." % (SHELTER_HELP, T("optional"))), widget=S3AutocompleteWidget("cr", "shelter")) self.add_components(tablename, cr_shelter_allocation="shelter_id", cr_shelter_registration="shelter_id", cr_shelter_status={ "name": "status", "joinby": "shelter_id", }, event_event_shelter="shelter_id") # Custom Method to Assign HRs set_method( "cr", "shelter", method="assign", action=self.hrm_AssignMethod(component="human_resource_site")) set_method("cr", "shelter", method="dispatch", action=cr_notification_dispatcher) # ------------------------------------------------------------------------- # Shelter statuses # - a historical record of shelter status: opening/closing dates & populations # tablename = "cr_shelter_status" define_table(tablename, shelter_id(ondelete = "CASCADE"), s3_date(), Field("status", "integer", label = T("Status"), represent = lambda opt: \ cr_shelter_opts.get(opt, messages.UNKNOWN_OPT), requires = IS_EMPTY_OR( IS_IN_SET(cr_shelter_opts) ), ), Field("population", "integer", label = T("Population"), represent = lambda v: IS_INT_AMOUNT.represent(v), requires = IS_EMPTY_OR( IS_INT_IN_RANGE(0, 999999)), ), s3_comments(), *s3_meta_fields()) # CRUD strings if settings.get_ui_label_camp(): crud_strings[tablename] = Storage( label_create=T("Add Camp Status"), title_display=T("Camp Status Details"), title_list=T("Camp Statuses"), title_update=T("Edit Camp Status"), label_list_button=T("List Camp Statuses"), msg_record_created=T("Camp Status added"), msg_record_modified=T("Camp Status updated"), msg_record_deleted=T("Camp Status deleted"), msg_list_empty=T("No Camp Statuses currently registered")) else: crud_strings[tablename] = Storage( label_create=T("Create Shelter Status"), title_display=T("Shelter Status Details"), title_list=T("Shelter Statuses"), title_update=T("Edit Shelter Status"), label_list_button=T("List Shelter Statuses"), msg_record_created=T("Shelter Status added"), msg_record_modified=T("Shelter Status updated"), msg_record_deleted=T("Shelter Status deleted"), msg_list_empty=T("No Shelter Statuses currently registered")) # --------------------------------------------------------------------- # Pass variables back to global scope (response.s3.*) return dict( ADD_SHELTER=ADD_SHELTER, SHELTER_LABEL=SHELTER_LABEL, cr_shelter_id=shelter_id, )
def model(self): T = current.T db = current.db auth = current.auth s3 = current.response.s3 item_id = self.supply_item_id item_entity_id = self.supply_item_entity_id location_id = self.gis_location_id organisation_id = self.org_organisation_id person_id = self.pr_person_id messages = current.messages NONE = messages["NONE"] UNKNOWN_OPT = messages.UNKNOWN_OPT settings = current.deployment_settings org_site_label = settings.get_org_site_label() vehicle = settings.has_module("vehicle") # Shortcuts add_components = self.add_components configure = self.configure crud_strings = s3.crud_strings define_table = self.define_table super_link = self.super_link #-------------------------------------------------------------------------- # Assets # asset_type_opts = { ASSET_TYPE_VEHICLE: T("Vehicle"), #ASSET_TYPE_RADIO : T("Radio"), #ASSET_TYPE_TELEPHONE : T("Telephone"), ASSET_TYPE_OTHER: T("Other"), } ctable = self.supply_item_category itable = self.supply_item supply_item_represent = self.supply_item_represent asset_items_set = db((ctable.can_be_asset == True) & \ (itable.item_category_id == ctable.id)) tablename = "asset_asset" define_table(tablename, # Instances super_link("track_id", "sit_trackable"), super_link("doc_id", "doc_entity"), item_entity_id, Field("number", label = T("Asset Number"), ), # @ToDo: We could set this automatically based on Item Category Field("type", "integer", label = T("Type"), readable = vehicle, writable = vehicle, requires = IS_IN_SET(asset_type_opts), default = ASSET_TYPE_OTHER, represent = lambda opt: \ asset_type_opts.get(opt, UNKNOWN_OPT), ), item_id(represent = supply_item_represent, requires = IS_ONE_OF(asset_items_set, "supply_item.id", supply_item_represent, sort = True, ), script = None, # No Item Pack Filter widget = None, ), Field("kit", "boolean", default = False, label = T("Kit?"), represent = lambda opt: \ (opt and [T("Yes")] or [NONE])[0], ), organisation_id(requires=self.org_organisation_requires( updateable=True, #required=True ), required = True, script = ''' S3OptionsFilter({ 'triggerName':'organisation_id', 'targetName':'site_id', 'lookupResource':'site', 'lookupPrefix':'org', 'lookupField':'site_id', 'lookupURL':S3.Ap.concat('/org/sites_for_org/'), })''', ), # This is a component, so needs to be a super_link # - can't override field name, ondelete or requires super_link("site_id", "org_site", label = org_site_label, default = auth.user.site_id if auth.is_logged_in() else None, readable = True, writable = True, empty = False, ondelete = "RESTRICT", represent = self.org_site_represent, # Comment these to use a Dropdown & not an Autocomplete #widget = S3SiteAutocompleteWidget(), #comment = DIV(_class="tooltip", # _title="%s|%s" % (T("Warehouse"), # messages.AUTOCOMPLETE_HELP)), ), Field("sn", label = T("Serial Number"), ), organisation_id("supply_org_id", label = T("Supplier/Donor"), ondelete = "SET NULL", ), s3_date("purchase_date", label = T("Purchase Date"), ), Field("purchase_price", "double", #default=0.00, represent=lambda v, row=None: \ IS_FLOAT_AMOUNT.represent(v, precision=2), ), s3_currency("purchase_currency"), # Base Location, which should always be a Site & set via Log location_id(readable=False, writable=False, ), # Populated onaccept of the log to make a component tab person_id("assigned_to_id", readable=False, writable=False, comment=self.pr_person_comment(child="assigned_to_id"), ), s3_comments(), *s3_meta_fields()) # CRUD strings ADD_ASSET = T("Create Asset") crud_strings[tablename] = Storage( label_create=ADD_ASSET, title_display=T("Asset Details"), title_list=T("Assets"), title_update=T("Edit Asset"), title_upload=T("Import Assets"), label_list_button=T("List Assets"), label_delete_button=T("Delete Asset"), msg_record_created=T("Asset added"), msg_record_modified=T("Asset updated"), msg_record_deleted=T("Asset deleted"), msg_list_empty=T("No Assets currently registered")) # Reusable Field asset_id = S3ReusableField( "asset_id", "reference %s" % tablename, sortby="number", requires=IS_NULL_OR( IS_ONE_OF(db, "asset_asset.id", self.asset_represent, sort=True)), represent=self.asset_represent, label=T("Asset"), comment=S3AddResourceLink( c="asset", f="asset", tooltip= T("If you don't see the asset in the list, you can add a new one by clicking link 'Create Asset'." )), ondelete="CASCADE") # Which levels of Hierarchy are we using? hierarchy = current.gis.get_location_hierarchy() levels = hierarchy.keys() if len(settings.get_gis_countries()) == 1 or \ s3.gis.config.region_location_id: try: levels.remove("L0") except: pass list_fields = [ "id", "item_id$item_category_id", "item_id", "number", #"type", #"purchase_date", (T("Assigned To"), "assigned_to_id"), "organisation_id", "site_id", ] report_fields = [ "number", (T("Category"), "item_id$item_category_id"), (T("Item"), "item_id"), "organisation_id", "site_id", ] text_fields = [ "number", "item_id$name", #"item_id$category_id$name", "comments", ] for level in levels: lfield = "location_id$%s" % level report_fields.append(lfield) text_fields.append(lfield) list_fields.append(lfield) list_fields.append("comments") filter_widgets = [ S3TextFilter( text_fields, label=T("Search"), comment= T("You can search by asset number, item description or comments. You may use % as wildcard. Press 'Search' without input to list all assets." ), #_class = "filter-search", ), S3OptionsFilter("item_id$item_category_id", ), S3OptionsFilter( "organisation_id", represent="%(name)s", hidden=True, ), S3LocationFilter( "location_id", levels=levels, hidden=True, ), ] report_options = Storage( rows=report_fields, cols=report_fields, fact=[(T("Number of items"), "count(number)")], defaults=Storage( cols="location_id$%s" % levels[0], # Highest-level of hierarchy fact="count(number)", rows="item_id$item_category_id", totals=True, )) # Custom CRUD Form to allow ad-hoc Kits crud_form = S3SQLCustomForm( "number", "type", "item_id", "organisation_id", "site_id", "kit", # If not ad-hoc Kit "sn", "supply_org_id", "purchase_date", "purchase_price", "purchase_currency", # If ad-hoc Kit S3SQLInlineComponent( "item", label=T("Items"), fields=[ "item_id", "quantity", "sn", # These are too wide for the screen & hence hide the AddResourceLinks #"supply_org_id", #"purchase_date", #"purchase_price", #"purchase_currency", "comments", ], ), "comments", ) # Default summary summary = [ { "name": "addform", "common": True, "widgets": [{ "method": "create" }], }, { "name": "table", "label": "Table", "widgets": [{ "method": "datatable" }] }, { "name": "report", "label": "Report", "widgets": [{ "method": "report", "ajax_init": True }] }, { "name": "map", "label": "Map", "widgets": [{ "method": "map", "ajax_init": True }], }, ] # Resource Configuration configure( tablename, # Open Tabs after creation create_next=URL(c="asset", f="asset", args=["[id]"]), crud_form=crud_form, filter_widgets=filter_widgets, list_fields=list_fields, mark_required=["organisation_id"], onaccept=self.asset_onaccept, realm_components=["log", "presence"], report_options=report_options, summary=summary, super_entity=("supply_item_entity", "sit_trackable"), update_realm=True, ) # Components add_components( tablename, asset_item="asset_id", asset_log="asset_id", vehicle_gps="asset_id", vehicle_vehicle={ "joinby": "asset_id", "multiple": False }, ) # ===================================================================== # Asset Items # - to allow building ad-hoc Kits # tablename = "asset_item" define_table(tablename, item_entity_id, asset_id(ondelete="CASCADE"), item_id(represent = supply_item_represent, requires = IS_ONE_OF(asset_items_set, "supply_item.id", supply_item_represent, sort = True, ), script = None, # No Item Pack Filter widget = None, ), Field("quantity", "integer", notnull=True, default = 1, label = T("Quantity"), requires = IS_INT_IN_RANGE(1, 1000), ), Field("sn", label = T("Serial Number")), organisation_id("supply_org_id", label = T("Supplier/Donor"), ondelete = "SET NULL"), s3_date("purchase_date", label = T("Purchase Date")), Field("purchase_price", "double", #default=0.00, represent=lambda v, row=None: \ IS_FLOAT_AMOUNT.represent(v, precision=2)), s3_currency("purchase_currency"), # Base Location, which should always be a Site & set via Log location_id(readable=False, writable=False), s3_comments(comment=None), *s3_meta_fields()) # ===================================================================== # Asset Log # asset_log_status_opts = { ASSET_LOG_SET_BASE: T("Base %(facility)s Set") % dict(facility=org_site_label), ASSET_LOG_ASSIGN: T("Assigned"), ASSET_LOG_RETURN: T("Returned"), ASSET_LOG_CHECK: T("Checked"), ASSET_LOG_REPAIR: T("Repaired"), ASSET_LOG_DONATED: T("Donated"), ASSET_LOG_LOST: T("Lost"), ASSET_LOG_STOLEN: T("Stolen"), ASSET_LOG_DESTROY: T("Destroyed"), } asset_condition_opts = { 1: T("Good Condition"), 2: T("Minor Damage"), 3: T("Major Damage"), 4: T("Un-Repairable"), 5: T("Needs Maintenance"), } if auth.permission.format == "html": # T isn't JSON serializable site_types = auth.org_site_types for key in site_types.keys(): site_types[key] = str(site_types[key]) site_types = json.dumps(site_types) script = ''' S3OptionsFilter({ 'triggerName':'organisation_id', 'targetName':'site_id', 'lookupPrefix':'org', 'lookupResource':'site', 'lookupField':'site_id', 'fncRepresent': function(record,PrepResult){ var InstanceTypeNice=%(instance_type_nice)s return record.name+" ("+InstanceTypeNice[record.instance_type]+")" }})''' % dict(instance_type_nice=site_types) else: script = None tablename = "asset_log" define_table(tablename, asset_id(), Field("status", "integer", label = T("Status"), requires = IS_IN_SET(asset_log_status_opts), represent = lambda opt: \ asset_log_status_opts.get(opt, UNKNOWN_OPT) ), s3_datetime("datetime", default="now", empty=False, represent="date", ), s3_datetime("datetime_until", label = T("Date Until"), represent="date", ), person_id(label = T("Assigned To")), Field("check_in_to_person", "boolean", #label = T("Mobile"), # Relabel? label = T("Track with this Person?"), comment = DIV(_class="tooltip", #_title="%s|%s" % (T("Mobile"), _title="%s|%s" % (T("Track with this Person?"), T("If selected, then this Asset's Location will be updated whenever the Person's Location is updated."))), readable = False, writable = False), # The Organisation to whom the loan is made organisation_id( readable = False, writable = False, widget = None ), # This is a component, so needs to be a super_link # - can't override field name, ondelete or requires super_link("site_id", "org_site", label = org_site_label, #filterby = "site_id", #filter_opts = auth.permitted_facilities(redirect_on_error=False), instance_types = auth.org_site_types, updateable = True, not_filterby = "obsolete", not_filter_opts = (True,), #default = user.site_id if is_logged_in() else None, readable = True, writable = True, empty = False, represent = self.org_site_represent, #widget = S3SiteAutocompleteWidget(), script = script, ), self.org_room_id(), #location_id(), Field("cancel", "boolean", default = False, label = T("Cancel Log Entry"), represent = s3_yes_no_represent, comment = DIV(_class="tooltip", _title="%s|%s" % (T("Cancel Log Entry"), T("'Cancel' will indicate an asset log entry did not occur"))) ), Field("cond", "integer", # condition is a MySQL reserved word requires = IS_IN_SET(asset_condition_opts, zero = "%s..." % T("Please select")), represent = lambda opt: \ asset_condition_opts.get(opt, UNKNOWN_OPT), label = T("Condition")), person_id("by_person_id", label = T("Assigned By"), # This can either be the Asset controller if signed-out from the store default = auth.s3_logged_in_person(), # or the previous owner if passed on directly (e.g. to successor in their post) comment = self.pr_person_comment(child="by_person_id"), ), s3_comments(), *s3_meta_fields()) # CRUD strings ADD_ASSIGN = T("New Entry in Asset Log") crud_strings[tablename] = Storage( label_create=ADD_ASSIGN, title_display=T("Asset Log Details"), title_list=T("Asset Log"), title_update=T("Edit Asset Log Entry"), label_list_button=T("Asset Log"), label_delete_button=T("Delete Asset Log Entry"), msg_record_created=T("Entry added to Asset Log"), msg_record_modified=T("Asset Log Entry updated"), msg_record_deleted=T("Asset Log Entry deleted"), msg_list_empty=T("Asset Log Empty")) # Resource configuration configure( tablename, listadd=False, list_fields=[ "id", "datetime", "status", "datetime_until", "organisation_id", "site_id", "room_id", "person_id", #"location_id", "cancel", "cond", "comments", ], onaccept=self.asset_log_onaccept, ) # --------------------------------------------------------------------- # Pass names back to global scope (s3.*) # return dict( asset_asset_id=asset_id, asset_represent=self.asset_represent, )
def model(self): T = current.T db = current.db crud_strings = current.response.s3.crud_strings define_table = self.define_table # ===================================================================== # Basic Disease Information # tablename = "disease_disease" table = define_table(tablename, self.super_link("doc_id", "doc_entity"), Field("name"), Field("short_name"), Field("acronym"), Field("code", label = T("ICD-10-CM Code"), ), Field("description", "text"), Field("trace_period", "integer", label = T("Trace Period before Symptom Debut (days)"), ), Field("watch_period", "integer", label = T("Watch Period after Exposure (days)"), ), s3_comments(), *s3_meta_fields()) represent = S3Represent(lookup=tablename) disease_id = S3ReusableField("disease_id", "reference %s" % tablename, label = T("Disease"), represent = represent, requires = IS_ONE_OF(db, "disease_disease.id", represent, ), sortby = "name", comment = S3AddResourceLink(f="disease", tooltip=T("Add a new disease to the catalog"), ), ) self.add_components(tablename, disease_symptom = "disease_id", ) self.configure(tablename, super_entity = "doc_entity", deduplicate = self.disease_duplicate, ) # CRUD strings crud_strings[tablename] = Storage( label_create = T("Create Disease"), title_display = T("Disease Information"), title_list = T("Diseases"), title_update = T("Edit Disease Information"), title_upload = T("Import Disease Information"), label_list_button = T("List Diseases"), label_delete_button = T("Delete Disease Information"), msg_record_created = T("Disease Information added"), msg_record_modified = T("Disease Information updated"), msg_record_deleted = T("Disease Information deleted"), msg_list_empty = T("No Diseases currently registered")) # ===================================================================== # Symptom Information # tablename = "disease_symptom" table = define_table(tablename, disease_id(), Field("name"), Field("description", label = T("Short Description"), ), Field("assessment", label = T("Assessment method"), ), *s3_meta_fields()) # @todo: refine to include disease name? represent = S3Represent(lookup=tablename) symptom_id = S3ReusableField("symptom_id", "reference %s" % tablename, label = T("Symptom"), represent = represent, requires = IS_ONE_OF(db, "disease_symptom.id", represent, ), sortby = "name", ) # CRUD strings crud_strings[tablename] = Storage( label_create = T("Add Symptom"), title_display = T("Symptom Information"), title_list = T("Symptoms"), title_update = T("Edit Symptom Information"), title_upload = T("Import Symptom Information"), label_list_button = T("List Symptoms"), label_delete_button = T("Delete Symptom Information"), msg_record_created = T("Symptom Information added"), msg_record_modified = T("Symptom Information updated"), msg_record_deleted = T("Symptom Information deleted"), msg_list_empty = T("No Symptom Information currently available")) # Pass names back to global scope (s3.*) return dict(disease_disease_id = disease_id, disease_symptom_id = symptom_id, )
def model(self): T = current.T db = current.db crud_strings = current.response.s3.crud_strings define_table = self.define_table # ----------------------------------------------------------- # Fire Zone Types tablename = "fire_zone_type" define_table(tablename, Field("name", label=T("Name")), # @ToDo: Currently unused - apply in layer_feature for now Field("style", "text", label=T("Style")), s3_comments(), *s3_meta_fields()) # CRUD strings ADD_ZONE_TYPE = T("Create Zone Type") crud_strings[tablename] = Storage( label_create = ADD_ZONE_TYPE, title_display = T("Zone Type Details"), title_list = T("Zone Types"), title_update = T("Edit Zone Type"), title_upload = T("Import Zone Types"), label_list_button = T("List Zone Types"), label_delete_button = T("Delete Zone Type"), msg_record_created = T("Zone Type added"), msg_record_modified = T("Zone Type updated"), msg_record_deleted = T("Zone Type deleted"), msg_list_empty = T("No Zone Types currently registered")) zone_type_represent = S3Represent(lookup=tablename) self.configure(tablename, deduplicate = self.fire_zone_type_duplicate, ) # ----------------------------------------------------------- # Fire Zones tablename = "fire_zone" define_table(tablename, Field("name", label=T("Name")), Field("zone_type_id", db.fire_zone_type, requires = IS_EMPTY_OR( IS_ONE_OF(db, "fire_zone_type.id", zone_type_represent, sort=True)), represent = zone_type_represent, comment = S3AddResourceLink(c="fire", f="zone_type", label=ADD_ZONE_TYPE, tooltip=T("Select a Zone Type from the list or click 'Add Zone Type'")), label=T("Type")), self.gis_location_id( widget = S3LocationSelectorWidget2( catalog_layers = True, points = False, polygons = True, ) ), s3_comments(), *s3_meta_fields()) # CRUD strings crud_strings[tablename] = Storage( label_create = T("Create Zone"), title_display = T("Zone Details"), title_list = T("Zones"), title_update = T("Edit Zone"), title_upload = T("Import Zones"), label_list_button = T("List Zones"), label_delete_button = T("Delete Zone"), msg_record_created = T("Zone added"), msg_record_modified = T("Zone updated"), msg_record_deleted = T("Zone deleted"), msg_list_empty = T("No Zones currently registered")) # --------------------------------------------------------------------- # Pass names back to global scope (s3.*) # return dict()
def model(self): T = current.T db = current.db auth = current.auth crud_strings = current.response.s3.crud_strings define_table = self.define_table ADMIN = current.session.s3.system_roles.ADMIN is_admin = auth.s3_has_role(ADMIN) root_org = auth.root_org() if is_admin: filter_opts = () elif root_org: filter_opts = (root_org, None) else: filter_opts = (None, ) # --------------------------------------------------------------------- # Volunteer Award # tablename = "vol_award" define_table( tablename, Field("name", label=T("Name")), # Only included in order to be able to set # realm_entity to filter appropriately self.org_organisation_id( default=root_org, readable=is_admin, writable=is_admin, ), s3_comments(label=T("Description"), comment=None), *s3_meta_fields()) crud_strings[tablename] = Storage( label_create=T("Create Award"), title_display=T("Award"), title_list=T("Award"), title_update=T("Edit Award"), title_upload=T("Import Awards"), label_list_button=T("List Awards"), label_delete_button=T("Delete Award"), msg_record_created=T("Award added"), msg_record_modified=T("Award updated"), msg_record_deleted=T("Award deleted"), msg_list_empty=T("No Awards found")) comment = S3AddResourceLink( c="vol", f="award", label=crud_strings[tablename].label_create, title=T("Award"), ) represent = S3Represent(lookup=tablename) award_id = S3ReusableField("award_id", "reference %s" % tablename, label=T("Award"), requires=IS_EMPTY_OR( IS_ONE_OF(db, "vol_award.id", represent, filterby="organisation_id", filter_opts=filter_opts)), represent=represent, comment=comment) # --------------------------------------------------------------------- # Volunteers <> Awards link table # tablename = "vol_volunteer_award" define_table(tablename, self.pr_person_id(empty=False), award_id(), s3_date(), s3_comments(), *s3_meta_fields()) crud_strings[tablename] = Storage( label_create=T("Create Award"), title_display=T("Award"), title_list=T("Award"), title_update=T("Edit Award"), title_upload=T("Import Awards"), label_list_button=T("List Awards"), label_delete_button=T("Delete Award"), msg_record_created=T("Award added"), msg_record_modified=T("Award updated"), msg_record_deleted=T("Award deleted"), msg_list_empty=T("No Awards found")) self.configure( tablename, context={"person": "person_id"}, ) # Pass names back to global scope (s3.*) return dict()
def model(self): T = current.T db = current.db define_table = self.define_table configure = self.configure s3 = current.response.s3 crud_strings = s3.crud_strings organisation_id = self.org_organisation_id # Organisation Represent should link to po/organisation org_link = URL(c="po", f="organisation", args="[id]") org_represent = self.org_OrganisationRepresent( show_link=True, linkto=org_link, ) # Organisation AddResourceLink should go to po/organisation ADD_ORGANISATION = T("Create Agency") tooltip = T( "If you don't see the Agency in the list, you can add a new one by clicking link 'Create Agency'." ) org_comment = S3AddResourceLink( c="po", f="organisation", label=ADD_ORGANISATION, title=ADD_ORGANISATION, tooltip=tooltip, ) # --------------------------------------------------------------------- # Referral Agency (context link table), currently not visible # tablename = "po_referral_organisation" define_table( tablename, organisation_id( represent=org_represent, comment=org_comment, ), #s3_comments(), *s3_meta_fields()) # --------------------------------------------------------------------- # Areas Served by a Referral Agency # tablename = "po_organisation_area" define_table( tablename, # @todo: AddResourceLink should go to po/organisation organisation_id( label=T("Agency"), represent=org_represent, comment=org_comment, ), self.po_area_id(), s3_comments(), *s3_meta_fields()) # CRUD Strings crud_strings[tablename] = Storage( label_create=T("Add Agency"), title_update=T("Edit Referral Agency"), label_list_button=T("List Agencies"), label_delete_button=T("Remove Agency"), ) # --------------------------------------------------------------------- # Referral Household=>Agency # tablename = "po_organisation_household" define_table( tablename, # @todo: AddResourceLink should go to po/organisation organisation_id( label=T("Referral Agency"), represent=org_represent, comment=org_comment, ), self.po_household_id(), s3_date( default="now", label=T("Date Referral Made"), ), s3_comments(), *s3_meta_fields()) # CRUD Strings crud_strings[tablename] = Storage( label_create=T("Add Referral"), title_update=T("Edit Referral Details"), label_delete_button=T("Delete Referral"), ) # Table Configuration configure( tablename, orderby="%s.date desc" % tablename, list_fields=( "date", "organisation_id", "household_id", "comments", ), )
def model(self): T = current.T db = current.db UNKNOWN_OPT = current.messages.UNKNOWN_OPT crud_strings = current.response.s3.crud_strings define_table = self.define_table # --------------------------------------------------------------------- # Needs # tablename = "dvr_need" define_table(tablename, Field("name", label = T("name"), ), s3_comments(), *s3_meta_fields()) # CRUD Strings ADD_NEED = T("Create Need") crud_strings[tablename] = Storage( label_create = ADD_NEED, title_display = T("Need Details"), title_list = T("Needs"), title_update = T("Edit Need"), label_list_button = T("List Needs"), label_delete_button = T("Delete Need"), msg_record_created = T("Need added"), msg_record_modified = T("Need updated"), msg_record_deleted = T("Need deleted"), msg_list_empty = T("No Needs found") ) represent = S3Represent(lookup=tablename, translate=True) need_id = S3ReusableField("need_id", "reference %s" % tablename, label = T("Need"), ondelete = "RESTRICT", represent = represent, requires = IS_EMPTY_OR( IS_ONE_OF(db, "dvr_need.id", represent)), comment=S3AddResourceLink(c="dvr", f="need", label=ADD_NEED), ) # --------------------------------------------------------------------- # Case # #dvr_damage_opts = { # 1: T("Very High"), # 2: T("High"), # 3: T("Medium"), # 4: T("Low"), #} #dvr_status_opts = { # 1: T("Open"), # 2: T("Accepted"), # 3: T("Rejected"), #} tablename = "dvr_case" define_table(tablename, # @ToDo: Option to autogenerate these, like Waybills, et al Field("reference", label = T("Case Number"), ), self.pr_person_id( # @ToDo: Modify this to update location_id if the selected person has a Home Address already comment = None, represent = self.pr_PersonRepresent(show_link=True), requires = IS_ADD_PERSON_WIDGET2(), widget = S3AddPersonWidget2(controller="pr"), ), #Field("damage", "integer", # label= T("Damage Assessment"), # represent = lambda opt: \ # dvr_damage_opts.get(opt, UNKNOWN_OPT), # requires = IS_EMPTY_OR(IS_IN_SET(dvr_damage_opts)), # ), #Field("insurance", "boolean", # label = T("Insurance"), # represent = s3_yes_no_represent, # ), #Field("status", "integer", # default = 1, # label = T("Status"), # represent = lambda opt: \ # dvr_status_opts.get(opt, UNKNOWN_OPT), # requires = IS_EMPTY_OR(IS_IN_SET(dvr_status_opts)), # ), s3_comments(), *s3_meta_fields()) # CRUD Strings crud_strings[tablename] = Storage( label_create = T("Create Case"), title_display = T("Case Details"), title_list = T("Cases"), title_update = T("Edit Case"), label_list_button = T("List Cases"), label_delete_button = T("Delete Case"), msg_record_created = T("Case added"), msg_record_modified = T("Case updated"), msg_record_deleted = T("Case deleted"), msg_list_empty = T("No Cases found") ) represent = S3Represent(lookup=tablename, fields=("reference",)) case_id = S3ReusableField("case_id", "reference %s" % tablename, label = T("Case"), ondelete = "RESTRICT", represent = represent, requires = IS_EMPTY_OR( IS_ONE_OF(db, "dvr_case.id", represent)), ) self.add_components(tablename, dvr_need = {"link": "dvr_case_need", "joinby": "case_id", "key": "need_id", }, pr_address = ({"name": "current_address", "link": "pr_person", "joinby": "id", "key": "pe_id", "fkey": "pe_id", "pkey": "person_id", "filterby": "type", "filterfor": ("1",), }, {"name": "permanent_address", "link": "pr_person", "joinby": "id", "key": "pe_id", "fkey": "pe_id", "pkey": "person_id", "filterby": "type", "filterfor": ("2",), }, ), ) crud_form = S3SQLCustomForm("reference", "person_id", S3SQLInlineComponent("current_address", label = T("Current Address"), fields = [("", "location_id"), ], default = {"type": 1}, # Current Home Address link = False, multiple = False, ), S3SQLInlineComponent("permanent_address", comment = T("If Displaced"), label = T("Normal Address"), fields = [("", "location_id"), ], default = {"type": 2}, # Permanent Home Address link = False, multiple = False, ), S3SQLInlineLink("need", field = "need_id", ), "comments", ) self.configure(tablename, crud_form = crud_form, ) # --------------------------------------------------------------------- # Cases <> Needs # tablename = "dvr_case_need" define_table(tablename, case_id(empty = False, ondelete = "CASCADE", ), need_id(empty = False, ondelete = "CASCADE", ), s3_comments(), *s3_meta_fields()) # --------------------------------------------------------------------- # Pass names back to global scope (s3.*) # return {}
def model(self): T = current.T db = current.db auth = current.auth person_id = self.pr_person_id location_id = self.gis_location_id organisation_id = self.org_organisation_id UNKNOWN_OPT = current.messages.UNKNOWN_OPT settings = current.deployment_settings org_site_label = settings.get_org_site_label() vehicle = settings.has_module("vehicle") # Shortcuts add_component = self.add_component configure = self.configure crud_strings = current.response.s3.crud_strings define_table = self.define_table super_link = self.super_link #-------------------------------------------------------------------------- # Assets # asset_type_opts = {ASSET_TYPE_VEHICLE : T("Vehicle"), #ASSET_TYPE_RADIO : T("Radio"), #ASSET_TYPE_TELEPHONE : T("Telephone"), ASSET_TYPE_OTHER : T("Other") } ctable = self.supply_item_category itable = self.supply_item supply_item_represent = self.supply_item_represent tablename = "asset_asset" table = define_table(tablename, super_link("track_id", "sit_trackable"), super_link("doc_id", "doc_entity"), Field("number", label = T("Asset Number")), self.supply_item_entity_id, # @ToDo: Can we set this automatically based on Item Category? Field("type", "integer", readable = vehicle, writable = vehicle, requires = IS_IN_SET(asset_type_opts), default = ASSET_TYPE_OTHER, represent = lambda opt: \ asset_type_opts.get(opt, UNKNOWN_OPT), label = T("Type")), self.supply_item_id(represent = supply_item_represent, requires = IS_ONE_OF(db((ctable.can_be_asset == True) & \ (itable.item_category_id == ctable.id)), "supply_item.id", supply_item_represent, sort=True, ), widget = None, script = None, # No Item Pack Filter ), organisation_id(#requires=self.org_organisation_requires( # updateable=True, # required=True), required = True, script = ''' S3OptionsFilter({ 'triggerName':'organisation_id', 'targetName':'site_id', 'lookupResource':'site', 'lookupPrefix':'org', 'lookupField':'site_id', 'lookupURL':S3.Ap.concat('/org/sites_for_org/'), })'''), # This is a component, so needs to be a super_link # - can't override field name, ondelete or requires super_link("site_id", "org_site", label = org_site_label, default = auth.user.site_id if auth.is_logged_in() else None, readable = True, writable = True, empty = False, ondelete = "RESTRICT", represent = self.org_site_represent, # Comment these to use a Dropdown & not an Autocomplete #widget = S3SiteAutocompleteWidget(), #comment = DIV(_class="tooltip", # _title="%s|%s" % (T("Warehouse"), # T("Enter some characters to bring up a list of possible matches"))), ), Field("sn", label = T("Serial Number")), organisation_id("supply_org_id", label = T("Supplier/Donor"), ondelete = "SET NULL"), s3_date("purchase_date", label = T("Purchase Date")), Field("purchase_price", "double", #default=0.00, represent=lambda v, row=None: \ IS_FLOAT_AMOUNT.represent(v, precision=2)), s3_currency("purchase_currency"), # Base Location, which should always be a Site & set via Log location_id(readable=False, writable=False), # Populated onaccept of the log to make a component tab person_id("assigned_to_id", readable=False, writable=False, comment=self.pr_person_comment(child="assigned_to_id")), s3_comments(), *s3_meta_fields()) # CRUD strings ADD_ASSET = T("Add Asset") crud_strings[tablename] = Storage( title_create = ADD_ASSET, title_display = T("Asset Details"), title_list = T("Assets"), title_update = T("Edit Asset"), title_search = T("Search Assets"), title_upload = T("Import Assets"), subtitle_create = T("Add New Asset"), label_list_button = T("List Assets"), label_create_button = ADD_ASSET, label_delete_button = T("Delete Asset"), msg_record_created = T("Asset added"), msg_record_modified = T("Asset updated"), msg_record_deleted = T("Asset deleted"), msg_list_empty = T("No Assets currently registered")) # Reusable Field asset_id = S3ReusableField("asset_id", table, sortby="number", requires = IS_NULL_OR( IS_ONE_OF(db, "asset_asset.id", self.asset_represent, sort=True)), represent = self.asset_represent, label = T("Asset"), comment = S3AddResourceLink(c="asset", f="asset", tooltip=T("If you don't see the asset in the list, you can add a new one by clicking link 'Add Asset'.")), ondelete = "CASCADE") # Search Method # @ToDo: Replace with S3Filter report_search = [ S3SearchSimpleWidget( name="asset_search_text", label=T("Search"), comment=T("You can search by asset number, item description or comments. You may use % as wildcard. Press 'Search' without input to list all assets."), field=["number", "item_id$name", #"item_id$category_id$name", "comments", ] ), S3SearchOptionsWidget( name="asset_search_item_category", field="item_id$item_category_id", label=T("Category"), cols = 3 ), S3SearchOptionsWidget( name="asset_search_organisation_id", label=T("Organization"), field="organisation_id", represent ="%(name)s", cols = 3 ), S3SearchOptionsWidget( name="asset_search_L0", field="location_id$L0", location_level="L0", cols = 3 ), S3SearchOptionsWidget( name="asset_search_L1", field="location_id$L1", location_level="L1", cols = 3 ), S3SearchOptionsWidget( name="asset_search_L2", field="location_id$L2", location_level="L2", cols = 3 ), S3SearchOptionsWidget( name="asset_search_L3", field="location_id$L3", location_level="L3", cols = 3 )] # Map Search widget doesn't currently work with Report method as no Map in page advanced_search = report_search + [S3SearchLocationWidget( name="asset_search_map", label=T("Map"), )] search_method = S3Search( # Advanced Search only simple=(), advanced = advanced_search ) report_fields = ["number", (T("Category"), "item_id$item_category_id"), (T("Item"), "item_id"), "organisation_id", "site_id", (T("Country"),"location_id$L0"), "location_id$L1", "location_id$L2", ] # Work-in-progress #crud_form = S3SQLCustomForm("number", # S3SQLInlineComponent( # "sub", # label = T("Component Assets"), # link = True, # #comment = "Bob", # fields = ["number", # "type", # "item_id", # ], # ), # ) # Resource Configuration configure(tablename, super_entity = ("supply_item_entity", "sit_trackable"), mark_required = ["organisation_id"], # Open Tabs after creation create_next = URL(c="asset", f="asset", args=["[id]"]), onaccept=self.asset_onaccept, #crud_form = crud_form, search_method=search_method, report_options=Storage( search=report_search, rows=report_fields, cols=report_fields, fact=[("number", "count", T("Number of items"))], defaults=Storage( cols="asset.location_id$L1", fact="count:asset.number", rows="asset.item_id$item_category_id" ) ), list_fields=["id", "item_id$item_category_id", "item_id", "number", "type", #"purchase_date", (T("Assigned To"), "assigned_to_id"), "organisation_id", "site_id", (current.messages.COUNTRY, "location_id$L0"), "location_id$L1", #"location_id$L2", #"location_id$L3", "comments", ], realm_components = ["log", "presence"], update_realm = True, ) # Log as component of Assets add_component("asset_log", asset_asset="asset_id") # Vehicles as component of Assets add_component("vehicle_vehicle", asset_asset=dict(joinby="asset_id", multiple=False)) # GPS as a component of Assets add_component("vehicle_gps", asset_asset="asset_id") # Sub Assets #add_component("asset_asset", # asset_asset=dict(name="sub", # link="asset_sub_asset", # joinby="organisation_id", # key="sub_id", # #actuate="embed", # #autocomplete="number", # autodelete=True)) # For imports #add_component("asset_asset", # asset_asset=dict(name="parent", # link="asset_sub_asset", # joinby="sub_id", # key="organisation_id", # #actuate="embed", # #autocomplete="number", # autodelete=False)) # --------------------------------------------------------------------- # Sub Assets # #tablename = "asset_sub_asset" #table = define_table(tablename, # asset_id(ondelete="CASCADE"), # asset_id("sub_id", # label=T("Component Asset"), # default=None, # ondelete="CASCADE"), # *s3_meta_fields()) # ===================================================================== # Asset Log # asset_log_status_opts = {ASSET_LOG_SET_BASE : T("Base %(facility)s Set") % dict(facility = org_site_label), ASSET_LOG_ASSIGN : T("Assigned"), ASSET_LOG_RETURN : T("Returned"), ASSET_LOG_CHECK : T("Checked"), ASSET_LOG_REPAIR : T("Repaired"), ASSET_LOG_DONATED : T("Donated"), ASSET_LOG_LOST : T("Lost"), ASSET_LOG_STOLEN : T("Stolen"), ASSET_LOG_DESTROY : T("Destroyed"), } asset_condition_opts = {1:T("Good Condition"), 2:T("Minor Damage"), 3:T("Major Damage"), 4:T("Un-Repairable"), 5:T("Needs Maintenance"), } if auth.permission.format == "html": # T isn't JSON serializable site_types = auth.org_site_types for key in site_types.keys(): site_types[key] = str(site_types[key]) site_types = json.dumps(site_types) script = ''' S3OptionsFilter({ 'triggerName':'organisation_id', 'targetName':'site_id', 'lookupPrefix':'org', 'lookupResource':'site', 'lookupField':'site_id', 'fncRepresent': function(record,PrepResult){ var InstanceTypeNice=%(instance_type_nice)s return record.name+" ("+InstanceTypeNice[record.instance_type]+")" }})''' % dict(instance_type_nice = site_types) else: script = None tablename = "asset_log" table = define_table(tablename, asset_id(), Field("status", "integer", label = T("Status"), requires = IS_IN_SET(asset_log_status_opts), represent = lambda opt: \ asset_log_status_opts.get(opt, UNKNOWN_OPT) ), s3_datetime("datetime", default="now", empty=False, represent="date", ), s3_datetime("datetime_until", label = T("Date Until"), represent="date", ), person_id(label = T("Assigned To")), Field("check_in_to_person", "boolean", #label = T("Mobile"), # Relabel? label = T("Track with this Person?"), comment = DIV(_class="tooltip", #_title="%s|%s" % (T("Mobile"), _title="%s|%s" % (T("Track with this Person?"), T("If selected, then this Asset's Location will be updated whenever the Person's Location is updated."))), readable = False, writable = False), # The Organisation to whom the loan is made organisation_id( readable = False, writable = False, widget = None ), # This is a component, so needs to be a super_link # - can't override field name, ondelete or requires super_link("site_id", "org_site", label = org_site_label, #filterby = "site_id", #filter_opts = auth.permitted_facilities(redirect_on_error=False), instance_types = auth.org_site_types, updateable = True, not_filterby = "obsolete", not_filter_opts = [True], #default = user.site_id if is_logged_in() else None, readable = True, writable = True, empty = False, represent = self.org_site_represent, #widget = S3SiteAutocompleteWidget(), script = script, ), self.org_room_id(), #location_id(), Field("cancel", "boolean", default = False, label = T("Cancel Log Entry"), represent = s3_yes_no_represent, comment = DIV(_class="tooltip", _title="%s|%s" % (T("Cancel Log Entry"), T("'Cancel' will indicate an asset log entry did not occur"))) ), Field("cond", "integer", # condition is a MySQL reserved word requires = IS_IN_SET(asset_condition_opts, zero = "%s..." % T("Please select")), represent = lambda opt: \ asset_condition_opts.get(opt, UNKNOWN_OPT), label = T("Condition")), person_id("by_person_id", label = T("Assigned By"), # This can either be the Asset controller if signed-out from the store default = auth.s3_logged_in_person(), # or the previous owner if passed on directly (e.g. to successor in their post) comment = self.pr_person_comment(child="by_person_id"), ), s3_comments(), *s3_meta_fields()) # CRUD strings ADD_ASSIGN = T("New Entry in Asset Log") crud_strings[tablename] = Storage( title_create = ADD_ASSIGN, title_display = T("Asset Log Details"), title_list = T("Asset Log"), title_update = T("Edit Asset Log Entry"), title_search = T("Search Asset Log"), subtitle_create = ADD_ASSIGN, label_list_button = T("Asset Log"), label_create_button = ADD_ASSIGN, label_delete_button = T("Delete Asset Log Entry"), msg_record_created = T("Entry added to Asset Log"), msg_record_modified = T("Asset Log Entry updated"), msg_record_deleted = T("Asset Log Entry deleted"), msg_list_empty = T("Asset Log Empty")) # Resource configuration configure(tablename, onaccept = self.asset_log_onaccept, listadd = False, list_fields = ["id", "status", "datetime", "datetime_until", "organisation_id", "site_id", "room_id", #"location_id", "cancel", "cond", "comments"] ) # --------------------------------------------------------------------- # Pass names back to global scope (s3.*) # return dict(asset_asset_id = asset_id, asset_rheader = asset_rheader, asset_represent = self.asset_represent, asset_log_prep = self.asset_log_prep, )
def model(self): T = current.T db = current.db crud_strings = current.response.s3.crud_strings define_table = self.define_table location_id = self.gis_location_id # ----------------------------------------------------------- # Security Levels # - according to the UN Security Level System (SLS) # http://ictemergency.wfp.org/c/document_library/get_file?uuid=c025cb98-2297-4208-bcc6-76ba02719c02&groupId=10844 # http://geonode.wfp.org/layers/geonode:wld_bnd_securitylevel_wfp # level_opts = { 1: T("Minimal"), 2: T("Low"), 3: T("Moderate"), 4: T("Substantial"), 5: T("High"), 6: T("Extreme"), } tablename = "security_level" define_table( tablename, location_id( #label = T("Security Level Area"), widget=S3LocationSelector(show_map=False), ), # Overall Level Field( "level", "integer", label=T("Security Level"), represent=lambda v: level_opts.get( v, current.messages.UNKNOWN_OPT), requires=IS_IN_SET(level_opts), ), # Categories Field( "armed_conflict", "integer", label=T("Armed Conflict"), represent=lambda v: level_opts.get( v, current.messages.UNKNOWN_OPT), requires=IS_IN_SET(level_opts), ), Field( "terrorism", "integer", label=T("Terrorism"), represent=lambda v: level_opts.get( v, current.messages.UNKNOWN_OPT), requires=IS_IN_SET(level_opts), ), Field( "crime", "integer", label=T("Crime"), represent=lambda v: level_opts.get( v, current.messages.UNKNOWN_OPT), requires=IS_IN_SET(level_opts), ), Field( "civil_unrest", "integer", label=T("Civil Unrest"), represent=lambda v: level_opts.get( v, current.messages.UNKNOWN_OPT), requires=IS_IN_SET(level_opts), ), Field( "hazards", "integer", label=T("Hazards"), represent=lambda v: level_opts.get( v, current.messages.UNKNOWN_OPT), requires=IS_IN_SET(level_opts), comment=T("e.g. earthquakes or floods"), ), s3_comments(), *s3_meta_fields()) # CRUD strings crud_strings[tablename] = Storage( label_create=T("Classify Area"), title_display=T("Security Level Details"), title_list=T("Security Levels"), title_update=T("Edit Security Level"), title_upload=T("Import Security Levels"), label_list_button=T("List Security Levels"), label_delete_button=T("Delete Security Level"), msg_record_created=T("Security Area classified"), msg_record_modified=T("Security Level updated"), msg_record_deleted=T("Security Level deleted"), msg_list_empty=T("No Security Areas currently classified")) # ----------------------------------------------------------- # Security Zone Types # tablename = "security_zone_type" define_table(tablename, Field( "name", label=T("Name"), ), s3_comments(), *s3_meta_fields()) # CRUD strings ADD_ZONE_TYPE = T("Create Zone Type") crud_strings[tablename] = Storage( label_create=ADD_ZONE_TYPE, title_display=T("Zone Type Details"), title_list=T("Zone Types"), title_update=T("Edit Zone Type"), title_upload=T("Import Zone Types"), label_list_button=T("List Zone Types"), label_delete_button=T("Delete Zone Type"), msg_record_created=T("Zone Type added"), msg_record_modified=T("Zone Type updated"), msg_record_deleted=T("Zone Type deleted"), msg_list_empty=T("No Zone Types currently registered")) zone_type_represent = S3Represent(lookup=tablename) self.configure( tablename, deduplicate=self.security_zone_type_duplicate, ) # ----------------------------------------------------------- # Security Zones # tablename = "security_zone" define_table( tablename, Field( "name", label=T("Name"), ), Field( "zone_type_id", db.security_zone_type, label=T("Type"), represent=zone_type_represent, requires=IS_EMPTY_OR( IS_ONE_OF(db, "security_zone_type.id", zone_type_represent, sort=True)), comment=S3AddResourceLink( c="security", f="zone_type", label=ADD_ZONE_TYPE, tooltip= T("Select a Zone Type from the list or click 'Add Zone Type'" )), ), location_id(widget=S3LocationSelector( catalog_layers=True, points=False, polygons=True, ), ), s3_comments(), *s3_meta_fields()) # CRUD strings ADD_ZONE = T("Create Zone") crud_strings[tablename] = Storage( label_create=ADD_ZONE, title_display=T("Zone Details"), title_list=T("Zones"), title_update=T("Edit Zone"), title_upload=T("Import Zones"), label_list_button=T("List Zones"), label_delete_button=T("Delete Zone"), msg_record_created=T("Zone added"), msg_record_modified=T("Zone updated"), msg_record_deleted=T("Zone deleted"), msg_list_empty=T("No Zones currently registered")) zone_represent = S3Represent(lookup=tablename) # ----------------------------------------------------------- # Security Staff Types # tablename = "security_staff_type" define_table(tablename, Field("name", label=T("Name")), s3_comments(), *s3_meta_fields()) # CRUD strings ADD_STAFF = T("Add Staff Type") crud_strings[tablename] = Storage( label_create=ADD_STAFF, title_display=T("Staff Type Details"), title_list=T("Staff Types"), title_update=T("Edit Staff Type"), title_upload=T("Import Staff Types"), label_list_button=T("List Staff Types"), label_delete_button=T("Delete Staff Type"), msg_record_created=T("Staff Type added"), msg_record_modified=T("Staff Type updated"), msg_record_deleted=T("Staff Type deleted"), msg_list_empty=T("No Staff Types currently registered")) staff_type_represent = S3Represent(lookup=tablename) # ----------------------------------------------------------- # Security Staff # tablename = "security_staff" define_table( tablename, self.hrm_human_resource_id(), Field( "staff_type_id", "list:reference security_staff_type", label=T("Type"), represent=self.security_staff_type_multirepresent, requires=IS_EMPTY_OR( IS_ONE_OF(db, "security_staff_type.id", staff_type_represent, sort=True, multiple=True)), comment=S3AddResourceLink( c="security", f="staff_type", label=ADD_STAFF, tooltip= T("Select a Staff Type from the list or click 'Add Staff Type'" )), ), Field( "zone_id", db.security_zone, label=T("Zone"), represent=zone_represent, requires=IS_EMPTY_OR( IS_ONE_OF(db, "security_zone.id", zone_represent, sort=True)), comment=S3AddResourceLink( c="security", f="zone", label=ADD_ZONE, tooltip= T("For wardens, select a Zone from the list or click 'Add Zone'" )), ), self.super_link( "site_id", "org_site", label=T("Facility"), represent=self.org_site_represent, readable=True, writable=True, ), s3_comments(), *s3_meta_fields()) # CRUD strings crud_strings[tablename] = Storage( label_create=T("Add Security-Related Staff"), title_display=T("Security-Related Staff Details"), title_list=T("Security-Related Staff"), title_update=T("Edit Security-Related Staff"), title_upload=T("Import Security-Related Staff"), label_list_button=T("List Security-Related Staff"), label_delete_button=T("Delete Security-Related Staff"), msg_record_created=T("Security-Related Staff added"), msg_record_modified=T("Security-Related Staff updated"), msg_record_deleted=T("Security-Related Staff deleted"), msg_list_empty=T("No Security-Related Staff currently registered")) # --------------------------------------------------------------------- # Pass names back to global scope (s3.*) # return {}
def model(self): T = current.T db = current.db auth = current.auth s3 = current.response.s3 settings = current.deployment_settings person_id = self.pr_person_id organisation_id = self.org_organisation_id NONE = current.messages["NONE"] ADMIN = current.session.s3.system_roles.ADMIN is_admin = auth.s3_has_role(ADMIN) add_component = self.add_component configure = self.configure crud_strings = s3.crud_strings define_table = self.define_table root_org = auth.root_org() if is_admin: filter_opts = () elif root_org: filter_opts = (root_org, None) else: filter_opts = (None, ) if settings.get_org_autocomplete(): org_widget = S3OrganisationAutocompleteWidget( default_from_profile=True) else: org_widget = None # --------------------------------------------------------------------- # Membership Types # tablename = "member_membership_type" table = define_table( tablename, Field("name", notnull=True, length=64, label=T("Name")), # Only included in order to be able to set # realm_entity to filter appropriately organisation_id( default=root_org, readable=is_admin, writable=is_admin, ), s3_comments(label=T("Description"), comment=None), *s3_meta_fields()) crud_strings[tablename] = Storage( title_create=T("Add Membership Type"), title_display=T("Membership Type Details"), title_list=T("Membership Types"), title_update=T("Edit Membership Type"), title_search=T("Search Membership Types"), title_upload=T("Import Membership Types"), subtitle_create=T("Add New Membership Type"), label_list_button=T("List Membership Types"), label_create_button=T("Add Membership Type"), label_delete_button=T("Delete Membership Type"), msg_record_created=T("Membership Type added"), msg_record_modified=T("Membership Type updated"), msg_record_deleted=T("Membership Type deleted"), msg_list_empty=T("No membership types currently registered")) label_create = crud_strings[tablename].label_create_button represent = S3Represent(lookup=tablename) membership_type_id = S3ReusableField( "membership_type_id", table, sortby="name", label=T("Type"), requires=IS_NULL_OR( IS_ONE_OF(db, "member_membership_type.id", represent, filterby="organisation_id", filter_opts=filter_opts)), represent=represent, comment=S3AddResourceLink( f="membership_type", label=label_create, title=label_create, tooltip=T("Add a new membership type to the catalog.")), ondelete="SET NULL") configure( tablename, deduplicate=self.member_type_duplicate, ) # --------------------------------------------------------------------- # Members # tablename = "member_membership" table = define_table( tablename, organisation_id( empty=False, requires=self.org_organisation_requires(updateable=True, ), widget=org_widget, ), Field( "code", label=T("Member ID"), #readable = False, #writable = False, ), self.pr_person_id( comment=None, requires=IS_ADD_PERSON_WIDGET(), widget=S3AddPersonWidget(controller="member"), ), membership_type_id(), # History s3_date( "start_date", label=T("Date Joined"), ), s3_date( "end_date", label=T("Date resigned"), ), Field( "membership_fee", "double", label=T("Membership Fee"), ), s3_date("membership_paid", label=T("Membership Paid")), # Location (from pr_address component) self.gis_location_id(readable=False, writable=False), *s3_meta_fields()) crud_strings[tablename] = Storage( title_create=T("Add Member"), title_display=T("Member Details"), title_list=T("Members"), title_update=T("Edit Member"), title_search=T("Search Members"), title_upload=T("Import Members"), subtitle_create=T("Add New Member"), label_list_button=T("List Members"), label_create_button=T("Add Member"), label_delete_button=T("Delete Member"), msg_record_created=T("Member added"), msg_record_modified=T("Member updated"), msg_record_deleted=T("Member deleted"), msg_list_empty=T("No members currently registered")) table.paid = Field.Lazy(self.member_membership_paid) # Components # Email add_component("pr_contact", member_membership=dict( name="email", link="pr_person", joinby="id", key="pe_id", fkey="pe_id", pkey="person_id", filterby="contact_method", filterfor=["EMAIL"], )) # Phone add_component("pr_contact", member_membership=dict( name="phone", link="pr_person", joinby="id", key="pe_id", fkey="pe_id", pkey="person_id", filterby="contact_method", filterfor=[ "SMS", "HOME_PHONE", "WORK_PHONE", ], )) def member_type_opts(): """ Provide the options for the Membership Type search filter """ ttable = self.member_membership_type if root_org: query = (ttable.deleted == False) & \ ((ttable.organisation_id == root_org) | \ (ttable.organisation_id == None)) else: query = (ttable.deleted == False) & \ (ttable.organisation_id == None) opts = db(query).select(ttable.id, ttable.name) _dict = {} for opt in opts: _dict[opt.id] = opt.name return _dict # Which levels of Hierarchy are we using? hierarchy = current.gis.get_location_hierarchy() levels = hierarchy.keys() if len(settings.get_gis_countries()) == 1 or \ s3.gis.config.region_location_id: levels.remove("L0") list_fields = [ "person_id", "organisation_id", "membership_type_id", "start_date", # useful for testing the paid virtual field #"membership_paid", (T("Paid"), "paid"), (T("Email"), "email.value"), (T("Phone"), "phone.value"), ] report_fields = [ "person_id", "membership_type_id", "paid", "organisation_id", ] text_fields = [ "membership_type_id", "organisation_id$name", "organisation_id$acronym", "person_id$first_name", "person_id$middle_name", "person_id$last_name", ] for level in levels: lfield = "location_id$%s" % level list_fields.append(lfield) report_fields.append(lfield) text_fields.append(lfield) filter_widgets = [ S3TextFilter( text_fields, label=T("Search"), ), S3OptionsFilter( "membership_type_id", cols=3, options=member_type_opts, hidden=True, ), S3OptionsFilter( "paid", cols=3, options={ T("paid"): T("paid"), T("overdue"): T("overdue"), T("expired"): T("expired"), }, hidden=True, ), S3OptionsFilter( "organisation_id", widget="multiselect", hidden=True, ), S3LocationFilter( "location_id", label=T("Location"), levels=levels, widget="multiselect", hidden=True, ), ] report_options = Storage(rows=report_fields, cols=report_fields, facts=report_fields, defaults=Storage( cols="membership.organisation_id", rows="membership.membership_type_id", fact="count(membership.person_id)", totals=True, )) configure( tablename, create_next=URL(f="person", args="address", vars={"membership.id": "[id]"}), deduplicate=self.member_duplicate, extra_fields=["start_date", "membership_paid"], list_fields=list_fields, onaccept=self.member_onaccept, report_options=report_options, filter_widgets=filter_widgets, update_realm=True, ) # --------------------------------------------------------------------- # Pass names back to global scope (s3.*) # return Storage()
def customize_pr_person(**attr): """ Customize pr_person controller """ s3db = current.s3db request = current.request s3 = current.response.s3 tablename = "pr_person" table = s3db.pr_person # CRUD Strings ADD_CONTACT = T("Add New Contact") s3.crud_strings[tablename] = Storage( title_create=T("Add Contact"), title_display=T("Contact Details"), title_list=T("Contact Directory"), title_update=T("Edit Contact Details"), title_search=T("Search Contacts"), subtitle_create=ADD_CONTACT, label_list_button=T("List Contacts"), label_create_button=ADD_CONTACT, label_delete_button=T("Delete Contact"), msg_record_created=T("Contact added"), msg_record_modified=T("Contact details updated"), msg_record_deleted=T("Contact deleted"), msg_list_empty=T("No Contacts currently registered")) # Custom PreP standard_prep = s3.prep def custom_prep(r): # Call standard prep if callable(standard_prep): result = standard_prep(r) if not result: return False if r.method == "validate": # Can't validate image without the file image_field = s3db.pr_image.image image_field.requires = None MOBILE = settings.get_ui_label_mobile_phone() EMAIL = T("Email") htable = s3db.hrm_human_resource htable.organisation_id.widget = None site_field = htable.site_id represent = S3Represent(lookup="org_site") site_field.label = T("Office") site_field.represent = represent site_field.requires = IS_ONE_OF(current.db, "org_site.site_id", represent, orderby="org_site.name") from s3layouts import S3AddResourceLink site_field.comment = S3AddResourceLink( c="org", f="office", vars={"child": "site_id"}, label=T("Add New Office"), title=T("Office"), tooltip= T("If you don't see the Office in the list, you can add a new one by clicking link 'Add New Office'." )) # Best to have no labels when only 1 field in the row s3db.pr_contact.value.label = "" image_field = s3db.pr_image.image image_field.label = "" # ImageCrop widget doesn't currently work within an Inline Form from gluon.validators import IS_IMAGE image_field.requires = IS_IMAGE() image_field.widget = None hr_fields = [ "organisation_id", "job_title_id", "site_id", ] # Context from a Profile page?" organisation_id = request.get_vars.get("(organisation)", None) if organisation_id: field = s3db.hrm_human_resource.organisation_id field.default = organisation_id field.readable = field.writable = False hr_fields.remove("organisation_id") s3_sql_custom_fields = [ "first_name", #"middle_name", "last_name", S3SQLInlineComponent( "human_resource", name="human_resource", label="", multiple=False, fields=hr_fields, ), S3SQLInlineComponent("image", name="image", label=T("Photo"), multiple=False, fields=["image"], filterby=dict(field="profile", options=[True])), ] list_fields = [ "human_resource.organisation_id", "first_name", #"middle_name", "last_name", (T("Job Title"), "human_resource.job_title_id"), (T("Office"), "human_resource.site_id"), ] # Don't include Email/Phone for unauthenticated users if current.auth.is_logged_in(): list_fields += [ (MOBILE, "phone.value"), (EMAIL, "email.value"), ] s3_sql_custom_fields.insert( 3, S3SQLInlineComponent("contact", name="phone", label=MOBILE, multiple=False, fields=["value"], filterby=dict(field="contact_method", options="SMS")), ) s3_sql_custom_fields.insert( 3, S3SQLInlineComponent("contact", name="email", label=EMAIL, multiple=False, fields=["value"], filterby=dict(field="contact_method", options="EMAIL")), ) crud_form = S3SQLCustomForm(*s3_sql_custom_fields) filter_widgets = [ S3TextFilter( [ "pe_label", "first_name", "middle_name", "last_name", "local_name", "identity.value", "human_resource.organisation_id", "human_resource.job_title_id", "human_resource.site_id", ], label=T("Search"), ), S3OptionsFilter( "human_resource.organisation_id", # Doesn't support translation #represent="%(name)s", widget="multiselect", ), S3OptionsFilter( "human_resource.job_title_id", # Doesn't support translation #represent="%(name)s", widget="multiselect", ), S3OptionsFilter( "human_resource.site_id", # Doesn't support translation #represent="%(name)s", widget="multiselect", ), ] # Return to List view after create/update/delete (unless done via Modal) #url_next = URL(c="pr", f="person", ) # Report options report_fields = [ "organisation_id", ] report_options = Storage( rows=report_fields, cols=report_fields, fact=["count(id)"], defaults=Storage( rows="organisation_id", cols="", fact="count(id)", totals=True, chart="barchart:rows", #table = "collapse", )) s3db.configure( tablename, #create_next = url_next, #delete_next = url_next, #update_next = url_next, crud_form=crud_form, filter_widgets=filter_widgets, list_fields=list_fields, report_options=report_options, # Don't include a Create form in 'More' popups #listadd = False if r.method=="datalist" else True, #list_layout = render_contacts, ) # Custom postp standard_postp = s3.postp def custom_postp(r, output): # Call standard postp if callable(standard_postp): output = standard_postp(r, output) if r.interactive and isinstance(output, dict): output["rheader"] = "" actions = [ dict(label=str(T("Open")), _class="action-btn", url=URL(c="pr", f="person", args=["[id]", "read"])) ] s3.actions = actions if "form" in output: output["form"].add_class("pr_person") elif "item" in output and hasattr(output["item"], "add_class"): output["item"].add_class("pr_person") return output s3.postp = custom_postp # Remove rheader attr["rheader"] = None return attr
def model(self): T = current.T db = current.db define_table = self.define_table s3 = current.response.s3 crud_strings = s3.crud_strings # --------------------------------------------------------------------- # Area # tablename = "po_area" define_table(tablename, Field("name", requires = IS_NOT_EMPTY(), ), # @todo: link demographics? self.gis_location_id( widget = S3LocationSelector(points = False, polygons = True, ), ), s3_comments(), *s3_meta_fields()) # CRUD Strings crud_strings[tablename] = Storage( label_create = T("Create Area"), title_display = T("Area Details"), title_list = T("Areas"), title_update = T("Edit Area"), label_list_button = T("List Areas"), label_delete_button = T("Delete Area"), msg_record_created = T("Area created"), msg_record_modified = T("Area updated"), msg_record_deleted = T("Area deleted"), msg_list_empty = T("No Areas currently registered"), ) # Reusable field # @todo: represent area as link either to details or household list represent = S3Represent(lookup=tablename, show_link=True) area_id = S3ReusableField("area_id", "reference %s" % tablename, label = T("Area"), represent = represent, requires = IS_ONE_OF(db, "po_area.id", represent, ), sortby = "name", comment = S3AddResourceLink(f="area", tooltip=T("Create a new area"), ), ) # Components self.add_components(tablename, po_household = "area_id", ) levels = current.gis.get_relevant_hierarchy_levels() # Filters filter_widgets = [S3TextFilter(["name"]), S3LocationFilter("location_id", levels = levels), ] # @todo: reports # Table Configuration self.configure(tablename, filter_widgets = filter_widgets, ) # --------------------------------------------------------------------- # Pass names back to global scope (s3.*) # return {"po_area_id": area_id, }
def model(self): T = current.T db = current.db crud_strings = current.response.s3.crud_strings define_table = self.define_table case_id = self.disease_case_id # ===================================================================== # Tracing Information: when/where did a case pose risk for exposure? # # Processing Status contact_tracing_status = { "OPEN": T("Open"), # not all contacts identified yet "COMPLETE": T("Complete"), # all contacts identified, closed } tablename = "disease_tracing" table = define_table(tablename, case_id(), s3_datetime("start_date", label = T("From"), widget = S3DateTimeWidget(set_min="disease_end_date", ), ), s3_datetime("end_date", label = T("To"), widget = S3DateTimeWidget(set_max="disease_start_date", ), ), # @todo: add site_id? self.gis_location_id(), Field("circumstances", "text", ), Field("status", default = "OPEN", label = T("Tracing Status"), requires = IS_IN_SET(contact_tracing_status, zero=None), represent = S3Represent(options=contact_tracing_status), ), s3_comments(), *s3_meta_fields()) # @todo: implement specific S3Represent class represent = S3Represent(lookup=tablename, fields=["case_id"]) tracing_id = S3ReusableField("tracing_id", "reference %s" % tablename, label = T("Tracing Record"), represent = represent, requires = IS_EMPTY_OR( IS_ONE_OF(db, "disease_tracing.id", represent, )), sortby = "date", comment = S3AddResourceLink(f="tracing", tooltip=T("Add a new contact tracing information"), ), ) self.add_components(tablename, disease_exposure = "tracing_id", ) # CRUD strings crud_strings[tablename] = Storage( label_create = T("Add Tracing Record"), title_display = T("Tracing Details"), title_list = T("Contact Tracings"), title_update = T("Edit Tracing Information"), title_upload = T("Import Tracing Information"), label_list_button = T("List Tracing Record"), label_delete_button = T("Delete Tracing Record"), msg_record_created = T("Tracing Record added"), msg_record_modified = T("Tracing Record updated"), msg_record_deleted = T("Tracing Record deleted"), msg_list_empty = T("No Contact Tracings currently registered")) # ===================================================================== # Protection # protection_level = {"NONE": T("Unknown"), "PARTIAL": T("Partial"), "FULL": T("Full"), } protection_level_represent = S3Represent(options = protection_level) # ===================================================================== # Exposure Type # exposure_type = {"UNKNOWN": T("Unknown"), "DIRECT": T("Direct"), "INDIRECT": T("Indirect"), } exposure_type_represent = S3Represent(options = exposure_type) # ===================================================================== # Exposure Risk Level # exposure_risk = {"UNKNOWN": T("Unknown"), "NONE": T("No known exposure"), "LOW": T("Low risk exposure"), "HIGH": T("High risk exposure"), } exposure_risk_represent = S3Represent(options = exposure_risk) # ===================================================================== # Exposure: when and how was a person exposed to the disease? # tablename = "disease_exposure" table = define_table(tablename, case_id(), tracing_id(), self.pr_person_id(requires = IS_ADD_PERSON_WIDGET2(), widget = S3AddPersonWidget2(controller="pr"), ), s3_datetime(), #self.gis_location_id(), Field("exposure_type", default = "UNKNOWN", represent = exposure_type_represent, requires = IS_IN_SET(exposure_type, zero=None), ), Field("protection_level", default = "NONE", represent = protection_level_represent, requires = IS_IN_SET(protection_level, zero=None), ), Field("exposure_risk", default = "LOW", represent = exposure_risk_represent, requires = IS_IN_SET(exposure_risk, zero=None), ), Field("circumstances", "text"), *s3_meta_fields()) self.configure(tablename, onaccept = self.exposure_onaccept, ) crud_strings[tablename] = Storage( label_create = T("Add Exposure Information"), title_display = T("Exposure Details"), title_list = T("Exposure Information"), title_update = T("Edit Exposure Information"), title_upload = T("Import Exposure Information"), label_list_button = T("List Exposures"), label_delete_button = T("Delete Exposure Information"), msg_record_created = T("Exposure Information added"), msg_record_modified = T("Exposure Information updated"), msg_record_deleted = T("Exposure Information deleted"), msg_list_empty = T("No Exposure Information currently registered")) # Pass names back to global scope (s3.*) return dict()
def model(self): T = current.T db = current.db define_table = self.define_table super_link = self.super_link configure = self.configure s3 = current.response.s3 crud_strings = s3.crud_strings settings = current.deployment_settings # --------------------------------------------------------------------- # Household # tablename = "po_household" define_table( tablename, super_link("doc_id", "doc_entity"), super_link("pe_id", "pr_pentity"), self.po_area_id(), # @todo: inherit Lx from area and hide Lx (in area prep) self.gis_location_id( label=T("Address"), widget=S3LocationSelector( show_address=True, show_map=settings.get_gis_map_selector(), show_postcode=settings.get_gis_postcode_selector(), prevent_duplicate_addresses=True, ), ), s3_date( "date_visited", default="now", empty=False, label=T("Date visited"), ), Field( "followup", "boolean", default=False, label=T("Follow up"), represent=s3_yes_no_represent, ), s3_comments(), *s3_meta_fields()) # CRUD Strings crud_strings[tablename] = Storage( label_create=T("Create Household"), title_display=T("Household Details"), title_list=T("Households"), title_update=T("Edit Household"), label_list_button=T("List Households"), label_delete_button=T("Delete Household"), msg_record_created=T("Household created"), msg_record_modified=T("Household updated"), msg_record_deleted=T("Household deleted"), msg_list_empty=T("No Households currently registered"), ) # Reusable Field represent = po_HouseholdRepresent() household_id = S3ReusableField( "household_id", "reference %s" % tablename, label=T("Household"), represent=represent, requires=IS_ONE_OF( db, "po_household.id", represent, ), sortby="name", comment=S3AddResourceLink( f="household", tooltip=T("Create a new household"), ), ) # Filter Widgets filter_widgets = [ S3TextFilter( ( "household_member.person_id$first_name", "household_member.person_id$middle_name", "household_member.person_id$last_name", "location_id$addr_street", ), label=T("Search"), comment=T("Search by Address or Name of Household Member"), ), S3OptionsFilter("area_id", #hidden = True, ), S3DateFilter( "date_visited", label=T("Date visited"), hidden=True, ), S3OptionsFilter( "followup", cols=2, hidden=True, ), S3DateFilter( "household_followup.followup_date", label=T("Follow-up Date"), hidden=True, ), S3OptionsFilter( "household_followup.completed", cols=2, hidden=True, ), S3OptionsFilter( "organisation_household.organisation_id", hidden=True, ), ] # List fields list_fields = ( "area_id", "location_id", "date_visited", "followup", "household_followup.followup_date", "household_followup.completed", "organisation_household.organisation_id", "comments", ) # Reports report_axes = [ "area_id", "followup", "organisation_household.organisation_id", "household_followup.completed", "household_followup.evaluation", ] reports = ((T("Number of Households Visited"), "count(id)"), ) # Custom Form crud_form = S3SQLCustomForm( "area_id", "location_id", "date_visited", "followup", S3SQLInlineComponent( "contact", label=T("Contact Information"), fields=[ "priority", (T("Type"), "contact_method"), (T("Number"), "value"), "comments", ], orderby="priority", ), "household_social.language", "household_social.community", "household_dwelling.dwelling_type", "household_dwelling.type_of_use", "household_dwelling.repair_status", "comments", ) configure( tablename, create_next=self.household_create_next, crud_form=crud_form, filter_widgets=filter_widgets, list_fields=list_fields, onaccept=self.household_onaccept, report_options={ "rows": report_axes, "cols": report_axes, "fact": reports, "defaults": { "rows": "area_id", "cols": "followup", "fact": "count(id)", } }, super_entity=("doc_entity", "pr_pentity"), ) # Components self.add_components( tablename, pr_person={ "link": "po_household_member", "joinby": "household_id", "key": "person_id", "actuate": "replace", }, po_household_dwelling={ "joinby": "household_id", "multiple": False, }, po_household_social={ "joinby": "household_id", "multiple": False, }, po_household_followup={ "joinby": "household_id", "multiple": False, }, po_organisation_household="household_id", ) # --------------------------------------------------------------------- # Household Members # tablename = "po_household_member" define_table(tablename, household_id(), self.pr_person_id(), s3_comments(), *s3_meta_fields()) # --------------------------------------------------------------------- # Household Member Age Groups (under 18,18-30,30-55,56-75,75+) # age_groups = ("<18", "18-30", "30-55", "56-75", "75+") tablename = "po_age_group" define_table( tablename, self.pr_person_id(), Field( "age_group", label=T("Age Group"), requires=IS_EMPTY_OR(IS_IN_SET(age_groups)), ), *s3_meta_fields()) # --------------------------------------------------------------------- # Dwelling # dwelling_type = { "U": T("Unit"), "H": T("House"), "A": T("Apartment"), "S": T("Supervised House"), "O": T("Other"), } type_of_use = { "S": T("Owner-occupied"), "R": T("Renting"), "B": T("Boarding"), "O": T("Other"), } repair_status = { "W": T("waiting"), "R": T("rebuild"), "C": T("completed"), "N": T("not required"), "O": T("other"), } tablename = "po_household_dwelling" define_table( tablename, household_id(), Field( "dwelling_type", label=T("Type of Dwelling"), represent=S3Represent(options=dwelling_type), requires=IS_EMPTY_OR(IS_IN_SET(dwelling_type)), ), Field( "type_of_use", label=T("Type of Use"), represent=S3Represent(options=type_of_use), requires=IS_EMPTY_OR(IS_IN_SET(type_of_use)), ), Field( "repair_status", label=T("Stage of Repair"), represent=S3Represent(options=repair_status), requires=IS_EMPTY_OR(IS_IN_SET(repair_status)), ), s3_comments(), *s3_meta_fields()) # CRUD Strings crud_strings[tablename] = Storage( title_update=T("Edit Dwelling Data"), ) # --------------------------------------------------------------------- # Social Information # languages = dict(IS_ISO639_2_LANGUAGE_CODE.language_codes()) tablename = "po_household_social" define_table( tablename, household_id(), Field( "language", label=T("Main Language"), represent=S3Represent(options=languages), requires=IS_EMPTY_OR( IS_ISO639_2_LANGUAGE_CODE( select=None, sort=True, )), ), Field( "community", "text", label=T("Community Connections"), ), s3_comments(), *s3_meta_fields()) # CRUD Strings crud_strings[tablename] = Storage( title_update=T("Edit Social Information"), ) # --------------------------------------------------------------------- # Follow-up Details # evaluation = { "B": T("better"), "S": T("same"), "W": T("worse"), } twoweeks = current.request.utcnow + datetime.timedelta(days=14) tablename = "po_household_followup" define_table( tablename, household_id(), Field( "followup_required", label=T("Follow-up required"), ), s3_date( "followup_date", label=T("Date for Follow-up"), default=twoweeks, past=0, ), Field( "followup", "text", label=T("Follow-up made"), ), Field( "completed", "boolean", default=False, label="Follow-up completed", represent=s3_yes_no_represent, ), Field( "evaluation", label=T("Evaluation"), represent=S3Represent(options=evaluation), requires=IS_EMPTY_OR(IS_IN_SET(evaluation)), ), s3_comments(), *s3_meta_fields()) # CRUD Strings crud_strings[tablename] = Storage( title_update=T("Edit Follow-up Details"), ) configure( tablename, deletable=False, ) # --------------------------------------------------------------------- # Pass names back to global scope (s3.*) # return { "po_household_id": household_id, }
def model(self): T = current.T db = current.db auth = current.auth define_table = self.define_table super_link = self.super_link s3 = current.response.s3 crud_strings = s3.crud_strings root_org = auth.root_org() ADMIN = current.session.s3.system_roles.ADMIN is_admin = auth.s3_has_role(ADMIN) # --------------------------------------------------------------------- # Area # tablename = "po_area" define_table( tablename, super_link("doc_id", "doc_entity"), super_link("pe_id", "pr_pentity"), Field( "name", requires=IS_NOT_EMPTY(), ), # @todo: link demographics? self.gis_location_id(widget=S3LocationSelector( points=False, polygons=True, feature_required=True, ), ), # Only included to set realm entity: self.org_organisation_id( default=root_org, readable=is_admin, writable=is_admin, ), Field( "attempted_visits", "integer", comment=DIV( _class="tooltip", _title="%s|%s" % (T("Attempted Visits"), T("Number of households in the area where nobody was at home at the time of visit" ))), default=0, label=T("Attempted Visits"), requires=IS_EMPTY_OR(IS_INT_IN_RANGE(minimum=0)), ), s3_comments(), *s3_meta_fields()) # CRUD Strings crud_strings[tablename] = Storage( label_create=T("Create Area"), title_display=T("Area Details"), title_list=T("Areas"), title_update=T("Edit Area"), label_list_button=T("List Areas"), label_delete_button=T("Delete Area"), msg_record_created=T("Area created"), msg_record_modified=T("Area updated"), msg_record_deleted=T("Area deleted"), msg_list_empty=T("No Areas currently registered"), ) # Reusable field represent = S3Represent(lookup=tablename, show_link=True) area_id = S3ReusableField( "area_id", "reference %s" % tablename, label=T("Area"), represent=represent, requires=IS_ONE_OF( db, "po_area.id", represent, ), sortby="name", comment=S3AddResourceLink( f="area", tooltip=T("Create a new area"), ), ) # Components self.add_components( tablename, po_household="area_id", org_organisation={ "link": "po_organisation_area", "joinby": "area_id", "key": "organisation_id", "actuate": "hide", }, ) levels = current.gis.get_relevant_hierarchy_levels() # Filters filter_widgets = [ S3TextFilter(["name"]), S3LocationFilter("location_id", levels=levels), ] # @todo: reports # Table Configuration self.configure( tablename, filter_widgets=filter_widgets, summary=( { "common": True, "name": "add", "widgets": [{ "method": "create" }], }, { "name": "table", "label": "Table", "widgets": [{ "method": "datatable" }] }, { "name": "map", "label": "Map", "widgets": [{ "method": "map", "ajax_init": True }], }, ), super_entity=("doc_entity", "pr_pentity"), onaccept=self.area_onaccept, ondelete=self.area_ondelete, ) # --------------------------------------------------------------------- # Pass names back to global scope (s3.*) # return { "po_area_id": area_id, }
def model(self): T = current.T db = current.db crud_strings = current.response.s3.crud_strings define_table = self.define_table # ===================================================================== # Data Collection # tablename = "dc_collection" define_table( tablename, self.super_link("doc_id", "doc_entity"), self.dc_template_id(), s3_date(default="now"), self.gis_location_id(), self.org_organisation_id(), self.pr_person_id(default=current.auth.s3_logged_in_person(), ), s3_comments(), *s3_meta_fields()) # Configuration self.configure( tablename, super_entity="doc_entity", orderby="dc_collection.date desc", ) # Components self.add_components( tablename, dc_answer="collection_id", ) # CRUD strings crud_strings[tablename] = Storage( label_create=T("Create Data Collection"), title_display=T("Data Collection Details"), title_list=T("Data Collections"), title_update=T("Edit Data Collection"), title_upload=T("Import Data Collections"), label_list_button=T("List Data Collections"), label_delete_button=T("Delete Data Collection"), msg_record_created=T("Data Collection added"), msg_record_modified=T("Data Collection updated"), msg_record_deleted=T("Data Collection deleted"), msg_list_empty=T("No Data Collections currently registered")) # @todo: representation including template name, location and date # (not currently required since always hidden) represent = S3Represent( lookup=tablename, fields=["date"], ) # Reusable field collection_id = S3ReusableField( "collection_id", "reference %s" % tablename, label=T("Data Collection"), represent=represent, requires=IS_ONE_OF( db, "dc_collection.id", represent, ), comment=S3AddResourceLink( f="collection", tooltip=T("Add a new data collection"), ), ) # ===================================================================== # Data Collection Answer # tablename = "dc_answer" define_table( tablename, collection_id(), self.dc_question_id(), Field( "answer", "json", requires=IS_EMPTY_OR(IS_JSON()), # @todo: representation? (based the question model) # @todo: widget? (based the question model) ), s3_comments(), *s3_meta_fields()) # CRUD strings crud_strings[tablename] = Storage( label_create=T("Create Answer"), title_display=T("Answer Details"), title_list=T("Answers"), title_update=T("Edit Answer"), title_upload=T("Import Answers"), label_list_button=T("List Answers"), label_delete_button=T("Delete Answer"), msg_record_created=T("Answer added"), msg_record_modified=T("Answer updated"), msg_record_deleted=T("Answer deleted"), msg_list_empty=T("No Answers currently registered")) # ===================================================================== # Pass names back to global scope (s3.*) return dict(dc_collection_id=collection_id, )
def model(self): T = current.T db = current.db settings = current.deployment_settings configure = self.configure crud_strings = current.response.s3.crud_strings define_table = self.define_table messages = current.messages super_link = self.super_link NAME = T("Name") # ------------------------------------------------------------------------- # Shelter types # e.g. NGO-operated, Government evacuation center, School, Hospital -- see Agasti opt_camp_type.) tablename = "cr_shelter_type" table = define_table( tablename, Field("name", notnull=True, label=NAME, requires=IS_NOT_ONE_OF(db, "%s.name" % tablename)), s3_comments(), *s3_meta_fields()) # CRUD strings if settings.get_ui_label_camp(): ADD_SHELTER_TYPE = T("Add Camp Type") SHELTER_TYPE_LABEL = T("Camp Type") crud_strings[tablename] = Storage( title_create=ADD_SHELTER_TYPE, title_display=T("Camp Type Details"), title_list=T("Camp Types"), title_update=T("Edit Camp Type"), title_search=T("Search Camp Types"), subtitle_create=T("Add New Camp Type"), label_list_button=T("List Camp Types"), label_create_button=ADD_SHELTER_TYPE, msg_record_created=T("Camp Type added"), msg_record_modified=T("Camp Type updated"), msg_record_deleted=T("Camp Type deleted"), msg_list_empty=T("No Camp Types currently registered"), name_nice=T("Camp"), name_nice_plural=T("Camps")) else: ADD_SHELTER_TYPE = T("Add Shelter Type") SHELTER_TYPE_LABEL = T("Shelter Type") crud_strings[tablename] = Storage( title_create=ADD_SHELTER_TYPE, title_display=T("Shelter Type Details"), title_list=T("Shelter Types"), title_update=T("Edit Shelter Type"), title_search=T("Search Shelter Types"), subtitle_create=T("Add New Shelter Type"), label_list_button=T("List Shelter Types"), label_create_button=ADD_SHELTER_TYPE, msg_record_created=T("Shelter Type added"), msg_record_modified=T("Shelter Type updated"), msg_record_deleted=T("Shelter Type deleted"), msg_list_empty=T("No Shelter Types currently registered"), name_nice=T("Shelter"), name_nice_plural=T("Shelters")) configure( tablename, deduplicate=self.cr_shelter_type_duplicate, ) represent = S3Represent(lookup=tablename) shelter_type_id = S3ReusableField( "shelter_type_id", table, requires=IS_NULL_OR(IS_ONE_OF(db, "cr_shelter_type.id", represent)), represent=represent, comment=S3AddResourceLink(c="cr", f="shelter_type", label=ADD_SHELTER_TYPE), ondelete="RESTRICT", label=SHELTER_TYPE_LABEL) # ------------------------------------------------------------------------- # Shelter services # e.g. medical, housing, food, ... tablename = "cr_shelter_service" table = define_table(tablename, Field( "name", notnull=True, label=NAME, ), s3_comments(), *s3_meta_fields()) # CRUD strings if settings.get_ui_label_camp(): ADD_SHELTER_SERVICE = T("Add Camp Service") SHELTER_SERVICE_LABEL = T("Camp Service") crud_strings[tablename] = Storage( title_create=ADD_SHELTER_SERVICE, title_display=T("Camp Service Details"), title_list=T("Camp Services"), title_update=T("Edit Camp Service"), title_search=T("Search Camp Services"), subtitle_create=T("Add New Camp Service"), label_list_button=T("List Camp Services"), label_create_button=ADD_SHELTER_SERVICE, msg_record_created=T("Camp Service added"), msg_record_modified=T("Camp Service updated"), msg_record_deleted=T("Camp Service deleted"), msg_list_empty=T("No Camp Services currently registered"), name_nice=T("Camp Service"), name_nice_plural=T("Camp Services")) else: ADD_SHELTER_SERVICE = T("Add Shelter Service") SHELTER_SERVICE_LABEL = T("Shelter Service") crud_strings[tablename] = Storage( title_create=ADD_SHELTER_SERVICE, title_display=T("Shelter Service Details"), title_list=T("Shelter Services"), title_update=T("Edit Shelter Service"), title_search=T("Search Shelter Services"), subtitle_create=T("Add New Shelter Service"), label_list_button=T("List Shelter Services"), label_create_button=ADD_SHELTER_SERVICE, msg_record_created=T("Shelter Service added"), msg_record_modified=T("Shelter Service updated"), msg_record_deleted=T("Shelter Service deleted"), msg_list_empty=T("No Shelter Services currently registered"), name_nice=T("Shelter Service"), name_nice_plural=T("Shelter Services")) shelter_service_id = S3ReusableField( "shelter_service_id", "list:reference cr_shelter_service", sortby="name", requires=IS_NULL_OR( IS_ONE_OF(db, "cr_shelter_service.id", self.cr_shelter_service_represent, multiple=True)), represent=self.cr_shelter_service_multirepresent, label=SHELTER_SERVICE_LABEL, comment=S3AddResourceLink(c="cr", f="shelter_service", label=ADD_SHELTER_SERVICE), ondelete="RESTRICT", #widget = SQLFORM.widgets.checkboxes.widget ) # ------------------------------------------------------------------------- cr_shelter_opts = {1: T("Closed"), 2: T("Open")} tablename = "cr_shelter" table = define_table(tablename, super_link("doc_id", "doc_entity"), super_link("pe_id", "pr_pentity"), super_link("site_id", "org_site"), #Field("code", # length=10, # Mayon compatibility # notnull=True, # unique=True, label=T("Code")), Field("name", notnull=True, length=64, # Mayon compatibility requires = IS_NOT_EMPTY(), label = T("Shelter Name") ), self.org_organisation_id( widget = S3OrganisationAutocompleteWidget(default_from_profile=True) ), shelter_type_id(), # e.g. NGO-operated, Government evacuation center, School, Hospital -- see Agasti opt_camp_type.) shelter_service_id(), # e.g. medical, housing, food, ... self.gis_location_id(), Field("phone", label = T("Phone"), requires = IS_NULL_OR(s3_phone_requires)), self.pr_person_id(label = T("Contact Person")), Field("capacity_day", "integer", label = T("Capacity (Day)"), requires = IS_NULL_OR( IS_INT_IN_RANGE(0, 999999)), represent=lambda v: \ IS_INT_AMOUNT.represent(v), comment = DIV(_class="tooltip", _title="%s|%s" % (T("Capacity (Day / Evacuation)"), T("Evacuation is short-term whilst storm passing e.g. 12 hours, hence people need less space."))), ), Field("capacity_night", "integer", label = T("Capacity (Night)"), requires = IS_NULL_OR( IS_INT_IN_RANGE(0, 999999)), represent=lambda v: \ IS_INT_AMOUNT.represent(v), comment = DIV(_class="tooltip", _title="%s|%s" % (T("Capacity (Night / Post-Impact)"), T("Post-impact shelterees are there for a longer time, so need more space to Sleep."))), ), Field("population", "integer", label = T("Population"), requires = IS_NULL_OR( IS_INT_IN_RANGE(0, 999999)), represent=lambda v: \ IS_INT_AMOUNT.represent(v) ), Field("status", "integer", requires = IS_NULL_OR( IS_IN_SET(cr_shelter_opts) ), represent = lambda opt: \ cr_shelter_opts.get(opt, messages.UNKNOWN_OPT), label = T("Status")), Field("source", readable = False, writable = False, label = T("Source")), s3_comments(), Field("obsolete", "boolean", label = T("Obsolete"), represent = lambda bool: \ (bool and [T("Obsolete")] or [messages["NONE"]])[0], default = False, readable = False, writable = False), *s3_meta_fields()) # CRUD strings if settings.get_ui_label_camp(): ADD_SHELTER = T("Add Camp") SHELTER_LABEL = T("Camp") SHELTER_HELP = T("The Camp this Request is from") crud_strings[tablename] = Storage( title_create=ADD_SHELTER, title_display=T("Camp Details"), title_list=T("Camps"), title_update=T("Edit Camp"), title_search=T("Search Camps"), subtitle_create=T("Add New Camp"), label_list_button=T("List Camps"), label_create_button=ADD_SHELTER, msg_record_created=T("Camp added"), msg_record_modified=T("Camp updated"), msg_record_deleted=T("Camp deleted"), msg_list_empty=T("No Camps currently registered"), name_nice=T("Camp"), name_nice_plural=T("Camps")) else: ADD_SHELTER = T("Add Shelter") SHELTER_LABEL = T("Shelter") SHELTER_HELP = T("The Shelter this Request is from") crud_strings[tablename] = Storage( title_create=ADD_SHELTER, title_display=T("Shelter Details"), title_list=T("Shelters"), title_update=T("Edit Shelter"), title_search=T("Search Shelters"), subtitle_create=T("Add New Shelter"), label_list_button=T("List Shelters"), label_create_button=ADD_SHELTER, msg_record_created=T("Shelter added"), msg_record_modified=T("Shelter updated"), msg_record_deleted=T("Shelter deleted"), msg_list_empty=T("No Shelters currently registered"), name_nice=T("Shelter"), name_nice_plural=T("Shelters")) # Search method cr_shelter_search = S3Search(advanced=( S3SearchSimpleWidget( name="shelter_search_advanced", label=T("Name or Organization"), comment= T("To search for a shelter, enter any of the names of the shelter, or the organisation name or acronym, separated by spaces. You may use % as wildcard. Press 'Search' without input to list all shelters." ), field=[ "name", "code", #"aka1", #"aka2", #"gov_uuid", "organisation_id$name", "organisation_id$acronym" ]), S3SearchOptionsWidget(name="shelter_search_type", label=T("Type"), field="shelter_type_id"), S3SearchOptionsWidget( name="shelter_search_L1", field="location_id$L1", location_level="L1", cols=3, ), S3SearchOptionsWidget( name="shelter_search_L2", field="location_id$L2", location_level="L2", cols=3, ), S3SearchOptionsWidget( name="shelter_search_L3", field="location_id$L3", location_level="L3", cols=3, ), S3SearchOptionsWidget( name="shelter_search_status", label=T("Status"), field="status", options=cr_shelter_opts, ), )) report_fields = [ "name", "shelter_type_id", #"organisation_id", "location_id$L1", "location_id$L2", "location_id$L3", "status", "population", ] configure( tablename, super_entity=("org_site", "doc_entity", "pr_pentity"), onaccept=self.cr_shelter_onaccept, search_method=cr_shelter_search, deduplicate=self.cr_shelter_duplicate, report_options=Storage(search=[ S3SearchOptionsWidget(name="shelter_search_type", label=T("Type"), field="shelter_type_id"), S3SearchOptionsWidget( name="shelter_search_L1", field="location_id$L1", location_level="L1", cols=3, ), S3SearchOptionsWidget( name="shelter_search_L2", field="location_id$L2", location_level="L2", cols=3, ), S3SearchOptionsWidget( name="shelter_search_L3", field="location_id$L3", location_level="L3", cols=3, ), S3SearchOptionsWidget( name="shelter_search_status", label=T("Status"), field="status", options=cr_shelter_opts, ), ], rows=report_fields, cols=report_fields, fact=report_fields, methods=["count", "list", "sum"], defaults=Storage(rows="location_id$L2", cols="status", fact="name", aggregate="count")), list_fields=[ "id", "name", "status", "shelter_type_id", #"shelter_service_id", "capacity_day", "capacity_night", "population", "location_id$addr_street", "location_id$L1", "location_id$L2", "location_id$L3", #"person_id", ]) # Reusable field represent = S3Represent(lookup=tablename) shelter_id = S3ReusableField( "shelter_id", table, requires=IS_NULL_OR( IS_ONE_OF(db, "cr_shelter.id", represent, sort=True)), represent=represent, ondelete="RESTRICT", comment=S3AddResourceLink(c="cr", f="shelter", label=ADD_SHELTER, title=SHELTER_LABEL, tooltip="%s (%s)." % (SHELTER_HELP, T("optional"))), label=SHELTER_LABEL, widget=S3AutocompleteWidget("cr", "shelter")) self.add_component("cr_shelter_status", cr_shelter=dict(joinby="shelter_id", name="status")) # ------------------------------------------------------------------------- # Shelter statuses # - a historical record of shelter status: opening/closing dates & populations # tablename = "cr_shelter_status" table = define_table(tablename, shelter_id(ondelete = "CASCADE"), s3_date(), Field("status", "integer", requires = IS_NULL_OR( IS_IN_SET(cr_shelter_opts) ), represent = lambda opt: \ cr_shelter_opts.get(opt, messages.UNKNOWN_OPT), label = T("Status")), Field("population", "integer", label = T("Population"), requires = IS_NULL_OR( IS_INT_IN_RANGE(0, 999999)), represent=lambda v: \ IS_INT_AMOUNT.represent(v) ), s3_comments(), *s3_meta_fields()) # CRUD strings if settings.get_ui_label_camp(): ADD_SHELTER_STATUS = T("Add Camp Status") SHELTER_STATUS_LABEL = T("Camp Status") crud_strings[tablename] = Storage( title_create=ADD_SHELTER_STATUS, title_display=T("Camp Status Details"), title_list=T("Camp Statuses"), title_update=T("Edit Camp Status"), title_search=T("Search Camp Statuses"), subtitle_create=T("Add New Camp Status"), label_list_button=T("List Camp Statuses"), label_create_button=ADD_SHELTER_STATUS, msg_record_created=T("Camp Status added"), msg_record_modified=T("Camp Status updated"), msg_record_deleted=T("Camp Status deleted"), msg_list_empty=T("No Camp Statuses currently registered"), name_nice=T("Camp Status"), name_nice_plural=T("Camp Statuses")) else: ADD_SHELTER_STATUS = T("Add Shelter Status") SHELTER_STATUS_LABEL = T("Shelter Status") crud_strings[tablename] = Storage( title_create=ADD_SHELTER_STATUS, title_display=T("Shelter Status Details"), title_list=T("Shelter Statuses"), title_update=T("Edit Shelter Status"), title_search=T("Search Shelter Statuses"), subtitle_create=T("Add New Shelter Status"), label_list_button=T("List Shelter Statuses"), label_create_button=ADD_SHELTER_STATUS, msg_record_created=T("Shelter Status added"), msg_record_modified=T("Shelter Status updated"), msg_record_deleted=T("Shelter Status deleted"), msg_list_empty=T("No Shelter Statuses currently registered"), name_nice=T("Shelter Status"), name_nice_plural=T("Shelter Statuses")) # Pass variables back to global scope (response.s3.*) return Storage( ADD_SHELTER=ADD_SHELTER, SHELTER_LABEL=SHELTER_LABEL, )
def model(self): T = current.T db = current.db crud_strings = current.response.s3.crud_strings define_table = self.define_table add_components = self.add_components # ===================================================================== # Data Collection Template # tablename = "dc_template" define_table( tablename, Field( "name", requires=IS_NOT_EMPTY(), ), # Whether to show this template in the form list # (required since form list can't use authorization) Field( "public", "boolean", default=False, ), s3_comments(), *s3_meta_fields()) self.configure( tablename, xform={ "collection": "dc_collection", "questions": "question", "answers": "answer", }, ) # Represent represent = S3Represent(lookup=tablename) # Reusable field template_id = S3ReusableField( "template_id", "reference %s" % tablename, label=T("Template"), represent=represent, requires=IS_ONE_OF( db, "dc_template.id", represent, ), sortby="name", comment=S3AddResourceLink( f="template", tooltip=T("Add a new data collection template"), ), ) # CRUD strings crud_strings[tablename] = Storage( label_create=T("Create Template"), title_display=T("Template Details"), title_list=T("Templates"), title_update=T("Edit Template"), title_upload=T("Import Templates"), label_list_button=T("List Templates"), label_delete_button=T("Delete Template"), msg_record_created=T("Template added"), msg_record_modified=T("Template updated"), msg_record_deleted=T("Template deleted"), msg_list_empty=T("No Templates currently registered")) # Components add_components( tablename, dc_question={ "link": "dc_template_question", "joinby": "template_id", "key": "question_id", "actuate": "hide", "autodelete": False, }, ) # ===================================================================== # Data Collection Question # tablename = "dc_question" define_table( tablename, Field( "question", requires=IS_NOT_EMPTY(), ), Field( "model", "json", requires=IS_EMPTY_OR(IS_JSON()), # @todo: representation? # @todo: widget? ), s3_comments(), *s3_meta_fields()) # CRUD strings crud_strings[tablename] = Storage( label_create=T("Create Question"), title_display=T("Question Details"), title_list=T("Questions"), title_update=T("Edit Question"), title_upload=T("Import Questions"), label_list_button=T("List Questions"), label_delete_button=T("Delete Question"), msg_record_created=T("Question added"), msg_record_modified=T("Question updated"), msg_record_deleted=T("Question deleted"), msg_list_empty=T("No Questions currently registered")) # Represent represent = S3Represent( lookup=tablename, fields=["question"], show_link=True, ) # Reusable field question_id = S3ReusableField( "question_id", "reference %s" % tablename, label=T("Question"), represent=represent, requires=IS_ONE_OF( db, "dc_question.id", represent, ), sortby="name", comment=S3AddResourceLink( f="question", tooltip=T("Add a new data collection question"), ), ) # Components add_components( tablename, dc_question_l10n="question_id", ) # ===================================================================== # Template <=> Question link table # tablename = "dc_template_question" define_table(tablename, template_id(), question_id(), *s3_meta_fields()) # CRUD strings crud_strings[tablename] = Storage( label_create=T("Add Question"), label_delete_button=T("Remove Question"), msg_record_created=T("Question added"), msg_record_deleted=T("Question remove"), msg_list_empty=T("No Questions currently registered")) # ===================================================================== # Questions l10n # tablename = "dc_question_l10n" define_table( tablename, question_id(ondelete="CASCADE", ), Field( "language", label=T("Language"), represent=IS_ISO639_2_LANGUAGE_CODE.represent, requires=IS_ISO639_2_LANGUAGE_CODE(sort=True), ), Field( "question", requires=IS_NOT_EMPTY(), ), Field( "model", "json", requires=IS_EMPTY_OR(IS_JSON()), # @todo: representation? # @todo: widget? ), s3_comments(), *s3_meta_fields()) # CRUD strings crud_strings[tablename] = Storage( label_create=T("Create Translation"), title_display=T("Translation"), title_list=T("Translations"), title_update=T("Edit Translation"), title_upload=T("Import Translations"), label_list_button=T("List Translations"), label_delete_button=T("Delete Translation"), msg_record_created=T("Translation added"), msg_record_modified=T("Translation updated"), msg_record_deleted=T("Translation deleted"), msg_list_empty=T("No Translations currently available")) # ===================================================================== # Pass names back to global scope (s3.*) return dict( dc_template_id=template_id, dc_question_id=question_id, )
def model(self): db = current.db T = current.T crud_strings = current.response.s3.crud_strings define_table = self.define_table # --------------------------------------------------------------------- # Volunteer Cluster tablename = "vol_cluster_type" table = define_table(tablename, Field("name", unique=True, label=T("Name")), *s3_meta_fields()) crud_strings[tablename] = Storage( title_create=T("Add Volunteer Cluster Type"), title_display=T("Volunteer Cluster Type"), title_list=T("Volunteer Cluster Type"), title_update=T("Edit Volunteer Cluster Type"), title_search=T("Search Volunteer Cluster Types"), title_upload=T("Import Volunteer Cluster Types"), subtitle_create=T("Add New Volunteer Cluster Type"), label_list_button=T("List Volunteer Cluster Types"), label_create_button=T("Add Volunteer Cluster Type"), label_delete_button=T("Delete Volunteer Cluster Type"), msg_record_created=T("Volunteer Cluster Type added"), msg_record_modified=T("Volunteer Cluster Type updated"), msg_record_deleted=T("Volunteer Cluster Type deleted"), msg_list_empty=T("No Volunteer Cluster Types")) comment = S3AddResourceLink( c="vol", f="cluster_type", vars=dict(child="vol_cluster_type_id", parent="volunteer_cluster"), label=crud_strings[tablename].label_create_button, title=T("Volunteer Cluster Type"), ) represent = S3Represent(lookup=tablename) vol_cluster_type_id = S3ReusableField( "vol_cluster_type_id", table, label=T("Volunteer Cluster Type"), requires=IS_NULL_OR(IS_ONE_OF(db, "vol_cluster_type.id", represent)), represent=represent, comment=comment) # --------------------------------------------------------------------- # Volunteer Cluster tablename = "vol_cluster" table = define_table(tablename, vol_cluster_type_id(), Field("name", unique=True, label=T("Name")), *s3_meta_fields()) crud_strings[tablename] = Storage( title_create=T("Add Volunteer Cluster"), title_display=T("Volunteer Cluster"), title_list=T("Volunteer Cluster"), title_update=T("Edit Volunteer Cluster"), title_search=T("Search Volunteer Clusters"), title_upload=T("Import Volunteer Clusters"), subtitle_create=T("Add New Volunteer Cluster"), label_list_button=T("List Volunteer Clusters"), label_create_button=T("Add Volunteer Cluster"), label_delete_button=T("Delete Volunteer Cluster"), msg_record_created=T("Volunteer Cluster added"), msg_record_modified=T("Volunteer Cluster updated"), msg_record_deleted=T("Volunteer Cluster deleted"), msg_list_empty=T("No Volunteer Clusters")) comment = S3AddResourceLink( c="vol", f="cluster", vars=dict(child="vol_cluster_id", parent="volunteer_cluster"), label=crud_strings[tablename].label_create_button, title=T("Volunteer Cluster"), ) represent = S3Represent(lookup=tablename) vol_cluster_id = S3ReusableField("vol_cluster_id", table, label=T("Volunteer Cluster"), requires=IS_NULL_OR( IS_ONE_OF(db, "vol_cluster.id", represent)), represent=represent, comment=comment) # --------------------------------------------------------------------- # Volunteer Group Position # tablename = "vol_cluster_position" table = define_table(tablename, Field("name", unique=True, label=T("Name")), *s3_meta_fields()) crud_strings[tablename] = Storage( title_create=T("Add Volunteer Cluster Position"), title_display=T("Volunteer Cluster Position"), title_list=T("Volunteer Cluster Position"), title_update=T("Edit Volunteer Cluster Position"), title_search=T("Search Volunteer Cluster Positions"), title_upload=T("Import Volunteer Cluster Positions"), subtitle_create=T("Add New Volunteer Cluster Position"), label_list_button=T("List Volunteer Cluster Positions"), label_create_button=T("Add Volunteer Cluster Position"), label_delete_button=T("Delete Volunteer Cluster Position"), msg_record_created=T("Volunteer Cluster Position added"), msg_record_modified=T("Volunteer Cluster Position updated"), msg_record_deleted=T("Volunteer Cluster Position deleted"), msg_list_empty=T("No Volunteer Cluster Positions")) comment = S3AddResourceLink( c="vol", f="cluster_position", vars=dict(child="vol_cluster_position_id", parent="volunteer_cluster"), label=crud_strings[tablename].label_create_button, title=T("Volunteer Cluster Position"), ) represent = S3Represent(lookup=tablename) vol_cluster_position_id = S3ReusableField( "vol_cluster_position_id", table, label=T("Volunteer Cluster Postion"), requires=IS_NULL_OR( IS_ONE_OF(db, "vol_cluster_position.id", represent)), represent=represent, comment=comment) # --------------------------------------------------------------------- # Volunteer Cluster Link Table cluster_type_filter = ''' S3OptionsFilter({ 'triggerName':'vol_cluster_type_id', 'targetName':'vol_cluster_id', 'lookupKey':'vol_cluster_type_id', 'lookupPrefix':'vol', 'lookupResource':'cluster', })''' tablename = "vol_volunteer_cluster" table = define_table( tablename, self.hrm_human_resource_id(ondelete="CASCADE"), vol_cluster_type_id( script=cluster_type_filter ), # This field is ONLY here to provide a filter vol_cluster_id(readable=False, writable=False), vol_cluster_position_id(readable=False, writable=False), *s3_meta_fields()) # Pass names back to global scope (s3.*) return Storage( vol_cluster_type_id=vol_cluster_type_id, vol_cluster_id=vol_cluster_id, )
def model(self): T = current.T db = current.db s3 = current.response.s3 settings = current.deployment_settings configure = self.configure crud_strings = s3.crud_strings define_table = self.define_table messages = current.messages super_link = self.super_link NAME = T("Name") if settings.get_org_autocomplete(): org_widget = S3OrganisationAutocompleteWidget( default_from_profile=True) else: org_widget = None # ------------------------------------------------------------------------- # Shelter types # e.g. NGO-operated, Government evacuation center, School, Hospital -- see Agasti opt_camp_type.) tablename = "cr_shelter_type" define_table( tablename, Field("name", notnull=True, label=NAME, requires=IS_NOT_ONE_OF(db, "%s.name" % tablename)), s3_comments(), *s3_meta_fields()) # CRUD strings if settings.get_ui_label_camp(): ADD_SHELTER_TYPE = T("Add Camp Type") SHELTER_TYPE_LABEL = T("Camp Type") crud_strings[tablename] = Storage( label_create=ADD_SHELTER_TYPE, title_display=T("Camp Type Details"), title_list=T("Camp Types"), title_update=T("Edit Camp Type"), label_list_button=T("List Camp Types"), msg_record_created=T("Camp Type added"), msg_record_modified=T("Camp Type updated"), msg_record_deleted=T("Camp Type deleted"), msg_list_empty=T("No Camp Types currently registered")) else: ADD_SHELTER_TYPE = T("Create Shelter Type") SHELTER_TYPE_LABEL = T("Shelter Type") crud_strings[tablename] = Storage( label_create=ADD_SHELTER_TYPE, title_display=T("Shelter Type Details"), title_list=T("Shelter Types"), title_update=T("Edit Shelter Type"), label_list_button=T("List Shelter Types"), msg_record_created=T("Shelter Type added"), msg_record_modified=T("Shelter Type updated"), msg_record_deleted=T("Shelter Type deleted"), msg_list_empty=T("No Shelter Types currently registered")) configure( tablename, deduplicate=self.cr_shelter_type_duplicate, ) represent = S3Represent(lookup=tablename) shelter_type_id = S3ReusableField( "shelter_type_id", "reference %s" % tablename, requires=IS_EMPTY_OR(IS_ONE_OF(db, "cr_shelter_type.id", represent)), represent=represent, comment=S3AddResourceLink(c="cr", f="shelter_type", label=ADD_SHELTER_TYPE), ondelete="RESTRICT", label=SHELTER_TYPE_LABEL) # ------------------------------------------------------------------------- # Shelter services # e.g. medical, housing, food, ... tablename = "cr_shelter_service" define_table(tablename, Field( "name", notnull=True, label=NAME, ), s3_comments(), *s3_meta_fields()) # CRUD strings if settings.get_ui_label_camp(): ADD_SHELTER_SERVICE = T("Add Camp Service") SHELTER_SERVICE_LABEL = T("Camp Service") crud_strings[tablename] = Storage( label_create=ADD_SHELTER_SERVICE, title_display=T("Camp Service Details"), title_list=T("Camp Services"), title_update=T("Edit Camp Service"), label_list_button=T("List Camp Services"), msg_record_created=T("Camp Service added"), msg_record_modified=T("Camp Service updated"), msg_record_deleted=T("Camp Service deleted"), msg_list_empty=T("No Camp Services currently registered")) else: ADD_SHELTER_SERVICE = T("Create Shelter Service") SHELTER_SERVICE_LABEL = T("Shelter Service") crud_strings[tablename] = Storage( label_create=ADD_SHELTER_SERVICE, title_display=T("Shelter Service Details"), title_list=T("Shelter Services"), title_update=T("Edit Shelter Service"), label_list_button=T("List Shelter Services"), msg_record_created=T("Shelter Service added"), msg_record_modified=T("Shelter Service updated"), msg_record_deleted=T("Shelter Service deleted"), msg_list_empty=T("No Shelter Services currently registered")) shelter_service_id = S3ReusableField( "shelter_service_id", "list:reference cr_shelter_service", sortby="name", requires=IS_EMPTY_OR( IS_ONE_OF(db, "cr_shelter_service.id", self.cr_shelter_service_represent, multiple=True)), represent=self.cr_shelter_service_multirepresent, label=SHELTER_SERVICE_LABEL, comment=S3AddResourceLink(c="cr", f="shelter_service", label=ADD_SHELTER_SERVICE), ondelete="RESTRICT", widget=S3MultiSelectWidget(header=False, ), ) # ------------------------------------------------------------------------- cr_shelter_opts = {1: T("Closed"), 2: T("Open")} tablename = "cr_shelter" define_table(tablename, super_link("doc_id", "doc_entity"), super_link("pe_id", "pr_pentity"), super_link("site_id", "org_site"), #Field("code", # length=10, # Mayon compatibility # notnull=True, # unique=True, label=T("Code")), Field("name", notnull=True, length=64, # Mayon compatibility requires = IS_NOT_EMPTY(), label = T("Shelter Name") ), self.org_organisation_id( widget = org_widget, ), shelter_type_id(), # e.g. NGO-operated, Government evacuation center, School, Hospital -- see Agasti opt_camp_type.) shelter_service_id(), # e.g. medical, housing, food, ... self.gis_location_id(), Field("phone", label = T("Phone"), requires = IS_EMPTY_OR(s3_phone_requires)), self.pr_person_id(label = T("Contact Person")), Field("capacity_day", "integer", label = T("Capacity (Day)"), requires = IS_EMPTY_OR( IS_INT_IN_RANGE(0, 999999)), represent=lambda v: \ IS_INT_AMOUNT.represent(v), comment = DIV(_class="tooltip", _title="%s|%s" % (T("Capacity (Day / Evacuation)"), T("Evacuation is short-term whilst storm passing e.g. 12 hours, hence people need less space."))), ), Field("capacity_night", "integer", label = T("Capacity (Night)"), requires = IS_EMPTY_OR( IS_INT_IN_RANGE(0, 999999)), represent=lambda v: \ IS_INT_AMOUNT.represent(v), comment = DIV(_class="tooltip", _title="%s|%s" % (T("Capacity (Night / Post-Impact)"), T("Post-impact shelterees are there for a longer time, so need more space to Sleep."))), ), Field("population", "integer", label = T("Population"), requires = IS_EMPTY_OR( IS_INT_IN_RANGE(0, 999999)), represent=lambda v: \ IS_INT_AMOUNT.represent(v) ), Field("status", "integer", requires = IS_EMPTY_OR( IS_IN_SET(cr_shelter_opts) ), represent = lambda opt: \ cr_shelter_opts.get(opt, messages.UNKNOWN_OPT), label = T("Status")), Field("source", readable = False, writable = False, label = T("Source")), s3_comments(), Field("obsolete", "boolean", label = T("Obsolete"), represent = lambda opt: \ (opt and [T("Obsolete")] or [messages["NONE"]])[0], default = False, readable = False, writable = False), *s3_meta_fields()) # CRUD strings if settings.get_ui_label_camp(): ADD_SHELTER = T("Add Camp") SHELTER_LABEL = T("Camp") SHELTER_HELP = T("The Camp this Request is from") crud_strings[tablename] = Storage( label_create=ADD_SHELTER, title_display=T("Camp Details"), title_list=T("Camps"), title_update=T("Edit Camp"), label_list_button=T("List Camps"), msg_record_created=T("Camp added"), msg_record_modified=T("Camp updated"), msg_record_deleted=T("Camp deleted"), msg_list_empty=T("No Camps currently registered")) else: ADD_SHELTER = T("Create Shelter") SHELTER_LABEL = T("Shelter") SHELTER_HELP = T("The Shelter this Request is from") crud_strings[tablename] = Storage( label_create=ADD_SHELTER, title_display=T("Shelter Details"), title_list=T("Shelters"), title_update=T("Edit Shelter"), label_list_button=T("List Shelters"), msg_record_created=T("Shelter added"), msg_record_modified=T("Shelter updated"), msg_record_deleted=T("Shelter deleted"), msg_list_empty=T("No Shelters currently registered")) # Which levels of Hierarchy are we using? hierarchy = current.gis.get_location_hierarchy() levels = hierarchy.keys() if len(settings.get_gis_countries()) == 1 or \ s3.gis.config.region_location_id: levels.remove("L0") report_fields = [ "name", "shelter_type_id", #"organisation_id", "status", "population", ] text_fields = [ "name", "code", "comments", "organisation_id$name", "organisation_id$acronym", "location_id$name", ] list_fields = [ "id", "name", "status", "shelter_type_id", #"shelter_service_id", "capacity_day", "capacity_night", "population", "location_id$addr_street", #"person_id", ] for level in levels: lfield = "location_id$%s" % level report_fields.append(lfield) text_fields.append(lfield) list_fields.append(lfield) filter_widgets = [ S3TextFilter( text_fields, label=T("Name"), _class="filter-search", ), S3OptionsFilter( "shelter_type_id", label=T("Type"), represent="%(name)s", widget="multiselect", #cols=3, #hidden=True, ), S3LocationFilter( "location_id", label=T("Location"), levels=levels, widget="multiselect", #cols=3, #hidden=True, ), S3OptionsFilter( "status", label=T("Status"), options=cr_shelter_opts, #represent="%(name)s", widget="multiselect", #cols=3, #hidden=True, ), S3RangeFilter( "capacity_night", label=T("Capacity (Night)"), #represent="%(name)s", #hidden=True, ), ] configure( tablename, deduplicate=self.cr_shelter_duplicate, filter_widgets=filter_widgets, list_fields=list_fields, onaccept=self.cr_shelter_onaccept, report_options=Storage(rows=report_fields, cols=report_fields, fact=report_fields, defaults=Storage(rows="location_id$L2", cols="status", fact="count(name)", totals=True)), super_entity=("org_site", "doc_entity", "pr_pentity"), ) # Reusable field represent = S3Represent(lookup=tablename) shelter_id = S3ReusableField( "shelter_id", "reference %s" % tablename, requires=IS_EMPTY_OR( IS_ONE_OF(db, "cr_shelter.id", represent, sort=True)), represent=represent, ondelete="RESTRICT", comment=S3AddResourceLink(c="cr", f="shelter", label=ADD_SHELTER, title=SHELTER_LABEL, tooltip="%s (%s)." % (SHELTER_HELP, T("optional"))), label=SHELTER_LABEL, widget=S3AutocompleteWidget("cr", "shelter")) self.add_components( tablename, cr_shelter_status={ "name": "status", "joinby": "shelter_id", }, ) # ------------------------------------------------------------------------- # Shelter statuses # - a historical record of shelter status: opening/closing dates & populations # tablename = "cr_shelter_status" define_table(tablename, shelter_id(ondelete = "CASCADE"), s3_date(), Field("status", "integer", requires = IS_EMPTY_OR( IS_IN_SET(cr_shelter_opts) ), represent = lambda opt: \ cr_shelter_opts.get(opt, messages.UNKNOWN_OPT), label = T("Status")), Field("population", "integer", label = T("Population"), requires = IS_EMPTY_OR( IS_INT_IN_RANGE(0, 999999)), represent=lambda v: \ IS_INT_AMOUNT.represent(v) ), s3_comments(), *s3_meta_fields()) # CRUD strings if settings.get_ui_label_camp(): ADD_SHELTER_STATUS = T("Add Camp Status") SHELTER_STATUS_LABEL = T("Camp Status") crud_strings[tablename] = Storage( label_create=ADD_SHELTER_STATUS, title_display=T("Camp Status Details"), title_list=T("Camp Statuses"), title_update=T("Edit Camp Status"), label_list_button=T("List Camp Statuses"), msg_record_created=T("Camp Status added"), msg_record_modified=T("Camp Status updated"), msg_record_deleted=T("Camp Status deleted"), msg_list_empty=T("No Camp Statuses currently registered")) else: ADD_SHELTER_STATUS = T("Create Shelter Status") SHELTER_STATUS_LABEL = T("Shelter Status") crud_strings[tablename] = Storage( label_create=ADD_SHELTER_STATUS, title_display=T("Shelter Status Details"), title_list=T("Shelter Statuses"), title_update=T("Edit Shelter Status"), label_list_button=T("List Shelter Statuses"), msg_record_created=T("Shelter Status added"), msg_record_modified=T("Shelter Status updated"), msg_record_deleted=T("Shelter Status deleted"), msg_list_empty=T("No Shelter Statuses currently registered")) # Pass variables back to global scope (response.s3.*) return Storage( ADD_SHELTER=ADD_SHELTER, SHELTER_LABEL=SHELTER_LABEL, )
def model(self): T = current.T db = current.db # Shortcuts crud_strings = current.response.s3.crud_strings define_table = self.define_table # ----------------------------------------------------------- # Water Zone Types # tablename = "water_zone_type" table = define_table(tablename, Field("name", label=T("Name")), s3_comments(), *s3_meta_fields()) # CRUD strings ADD_ZONE_TYPE = T("Add Zone Type") crud_strings[tablename] = Storage( title_create = ADD_ZONE_TYPE, title_display = T("Zone Type Details"), title_list = T("Zone Types"), title_update = T("Edit Zone Type"), title_search = T("Search Zone Types"), title_upload = T("Import Zone Types"), subtitle_create = T("Add New Zone Type"), label_list_button = T("List Zone Types"), label_create_button = T("Add New Zone Type"), label_delete_button = T("Delete Zone Type"), msg_record_created = T("Zone Type added"), msg_record_modified = T("Zone Type updated"), msg_record_deleted = T("Zone Type deleted"), msg_list_empty = T("No Zone Types currently registered")) zone_type_represent = S3Represent(lookup=tablename) self.configure(tablename, deduplicate = self.water_zone_type_duplicate, ) # ----------------------------------------------------------- # Water Zones # - e.g. Floods # tablename = "water_zone" table = define_table(tablename, Field("name", label=T("Name")), Field("zone_type_id", db.water_zone_type, requires = IS_NULL_OR( IS_ONE_OF(db, "water_zone_type.id", zone_type_represent, sort=True)), represent = zone_type_represent, comment = S3AddResourceLink(c="water", f="zone_type", label=ADD_ZONE_TYPE, tooltip=T("Select a Zone Type from the list or click 'Add Zone Type'")), label=T("Type")), self.gis_location_id( widget = S3LocationSelectorWidget( catalog_layers=True, polygon=True ) ), s3_comments(), *s3_meta_fields()) # CRUD strings ADD_ZONE = T("Add Zone") crud_strings[tablename] = Storage( title_create = ADD_ZONE, title_display = T("Zone Details"), title_list = T("Zones"), title_update = T("Edit Zone"), title_search = T("Search Zones"), title_upload = T("Import Zones"), subtitle_create = T("Add New Zone"), label_list_button = T("List Zones"), label_create_button = T("Add New Zone"), label_delete_button = T("Delete Zone"), msg_record_created = T("Zone added"), msg_record_modified = T("Zone updated"), msg_record_deleted = T("Zone deleted"), msg_list_empty = T("No Zones currently registered")) zone_represent = S3Represent(lookup=tablename) # ----------------------------------------------------------------------------- # Rivers tablename = "water_river" table = define_table(tablename, Field("name", label=T("Name"), requires = IS_NOT_EMPTY()), s3_comments(), *s3_meta_fields()) # CRUD strings ADD_RIVER = T("Add River") crud_strings[tablename] = Storage( title_create = ADD_RIVER, title_display = T("River Details"), title_list = T("Rivers"), title_update = T("Edit River"), title_search = T("Search Rivers"), subtitle_create = T("Add New River"), label_list_button = T("List Rivers"), label_create_button = ADD_RIVER, msg_record_created = T("River added"), msg_record_modified = T("River updated"), msg_record_deleted = T("River deleted"), msg_list_empty = T("No Rivers currently registered")) #represent = S3Represent(lookup = tablename) #river_id = S3ReusableField("river_id", table, # requires = IS_NULL_OR(IS_ONE_OF(db, "water_river.id", represent)), # represent = represent, # label = T("River"), # comment = S3AddResourceLink(c="water", # f="river", # title=ADD_RIVER), # ondelete = "RESTRICT") # ----------------------------------------------------------------------------- # Gauges # # @ToDo: Link together ones on same river with upstream/downstream relationships # flowstatus_opts = { 1:T("Normal"), 2:T("High"), 3:T("Very High"), 4:T("Low") } tablename = "water_gauge" table = define_table(tablename, Field("name", label=T("Name")), Field("code", label=T("Code")), #super_link("source_id", "doc_source_entity"), self.gis_location_id(), Field("url", label = T("URL"), requires = IS_NULL_OR(IS_URL()), represent = lambda url: \ A(url, _href=url, _target="blank") ), Field("image_url", label=T("Image URL")), Field("discharge", "integer", label = T("Discharge (cusecs)")), Field("status", "integer", requires = IS_NULL_OR(IS_IN_SET(flowstatus_opts)), represent = lambda opt: \ flowstatus_opts.get(opt, opt), label = T("Flow Status")), s3_comments(), *s3_meta_fields()) ADD_GAUGE = T("Add Gauge") crud_strings[tablename] = Storage( title_create = ADD_GAUGE, title_display = T("Gauge Details"), title_list = T("Gauges"), title_update = T("Edit Gauge"), title_search = T("Search Gauges"), title_map = T("Map of Gauges"), subtitle_create = T("Add New Gauge"), label_list_button = T("List Gauges"), label_create_button = ADD_GAUGE, msg_record_created = T("Gauge added"), msg_record_modified = T("Gauge updated"), msg_record_deleted = T("Gauge deleted"), msg_list_empty = T("No Gauges currently registered"), name_nice = T("Gauge"), name_nice_plural = T("Gauges")) # --------------------------------------------------------------------- # Pass names back to global scope (s3.*) # return dict()
def model(self): # @todo: add treatment component? T = current.T db = current.db crud_strings = current.response.s3.crud_strings define_table = self.define_table configure = self.configure add_components = self.add_components person_id = self.pr_person_id # ===================================================================== # Diagnosis Status # diagnosis_status = {"UNKNOWN": T("Unknown"), "RISK": T("At Risk"), "PROBABLE": T("Probable"), "CONFIRMED-POS": T("Confirmed Positive"), "CONFIRMED-NEG": T("Confirmed Negative"), } diagnosis_status_represent = S3Represent(options = diagnosis_status) # ===================================================================== # Monitoring Levels # monitoring_levels = {"NONE": T("No Monitoring"), # Clinical observation required: "OBSERVATION": T("Observation"), # Targeted diagnostics required: "DIAGNOSTICS": T("Diagnostics"), # Quarantine required: "QUARANTINE": T("Quarantine"), # Follow-up after recovery: "FOLLOW-UP": T("Post-Recovery Follow-Up"), } monitoring_level_represent = S3Represent(options = monitoring_levels) # ===================================================================== # Illness status # illness_status = {"UNKNOWN": T("Unknown, Not Checked"), "ASYMPTOMATIC": T("Asymptomatic, Clinical Signs Negative"), "SYMPTOMATIC": T("Symptomatic, Clinical Signs Positive"), "SEVERE": T("Severely Ill, Clinical Signs Positive"), "DECEASED": T("Deceased, Clinical Signs Positive"), "RECOVERED": T("Recovered"), } illness_status_represent = S3Represent(options = illness_status) # ===================================================================== # Case # tablename = "disease_case" table = define_table(tablename, Field("case_number", length=64, requires = IS_EMPTY_OR(IS_NOT_IN_DB(db, "disease_case.case_number")), ), person_id(empty = False, ondelete = "CASCADE", ), self.disease_disease_id(), #s3_date(), # date registered == created_on? self.gis_location_id(), # @todo: add site ID for registering site? # Current illness status and symptom debut Field("illness_status", label = T("Current Illness Status"), represent = illness_status_represent, requires = IS_IN_SET(illness_status), default = "UNKNOWN", ), s3_date("symptom_debut", label = T("Symptom Debut"), ), # Current diagnosis status and date of last status update Field("diagnosis_status", label = T("Diagnosis Status"), represent = diagnosis_status_represent, requires = IS_IN_SET(diagnosis_status), default = "UNKNOWN", ), s3_date("diagnosis_date", default = "now", label = T("Diagnosis Date"), ), # Current monitoring level and end date Field("monitoring_level", label = T("Current Monitoring Level"), represent = monitoring_level_represent, requires = IS_IN_SET(monitoring_levels), default = "NONE", ), s3_date("monitoring_until", label = T("Monitoring required until"), ), *s3_meta_fields()) # Reusable Field represent = disease_CaseRepresent() case_id = S3ReusableField("case_id", "reference %s" % tablename, label = T("Case"), represent = represent, requires = IS_ONE_OF(db, "disease_case.id", represent, ), comment = S3AddResourceLink(f="case", tooltip=T("Add a new case"), ), ) # Components add_components(tablename, disease_case_monitoring = "case_id", disease_case_diagnostics = "case_id", disease_tracing = "case_id", disease_exposure = ({"name": "exposure", "joinby": "person_id", "pkey": "person_id", }, {"name": "contact", "joinby": "case_id", }, ), ) report_fields = ["disease_id", "location_id", "illness_status", "monitoring_level", "diagnosis_status", ] report_options = {"rows": report_fields, "cols": report_fields, "fact": [(T("Number of Cases"), "count(id)"), ], "defaults": {"rows": "location_id", "cols": "diagnosis_status", "fact": "count(id)", "totals": True, }, } filter_widgets = [S3TextFilter(["case_number", "person_id$first_name", "person_id$middle_name", "person_id$last_name", ], label = T("Search"), comment = T("Enter Case Number or Name"), ), S3OptionsFilter("monitoring_level", options = monitoring_levels, ), S3OptionsFilter("diagnosis_status", options = diagnosis_status, ), S3LocationFilter("location_id", ), ] configure(tablename, create_onvalidation = self.case_create_onvalidation, deduplicate = self.case_duplicate, delete_next = URL(f="case", args=["summary"]), filter_widgets = filter_widgets, onaccept = self.case_onaccept, report_options = report_options, ) # CRUD strings crud_strings[tablename] = Storage( label_create = T("Create Case"), title_display = T("Case Details"), title_list = T("Cases"), title_update = T("Edit Cases"), title_upload = T("Import Cases"), label_list_button = T("List Cases"), label_delete_button = T("Delete Case"), msg_record_created = T("Case added"), msg_record_modified = T("Case updated"), msg_record_deleted = T("Case deleted"), msg_list_empty = T("No Cases currently registered")) # ===================================================================== # Monitoring # tablename = "disease_case_monitoring" table = define_table(tablename, case_id(), s3_datetime(default="now"), Field("illness_status", represent = illness_status_represent, requires = IS_IN_SET(illness_status), ), s3_comments(), *s3_meta_fields()) # Reusable Field represent = S3Represent(lookup=tablename, fields=["case_id"]) status_id = S3ReusableField("status_id", "reference %s" % tablename, label = T("Case"), represent = represent, requires = IS_ONE_OF(db, "disease_case.id", represent, ), comment = S3AddResourceLink(f="case", tooltip=T("Add a new case"), ), ) # Components add_components(tablename, disease_symptom = {"link": "disease_case_monitoring_symptom", "joinby": "status_id", "key": "symptom_id", } ) # Custom CRUD form crud_fields = ["case_id", "date", "illness_status", S3SQLInlineLink("symptom", field = "symptom_id", label = T("Symptoms"), multiple = True, ), "comments", ] configure(tablename, crud_form = S3SQLCustomForm(*crud_fields), list_fields = ["date", "illness_status", (T("Symptoms"), "symptom.name"), "comments", ], onaccept = self.monitoring_onaccept, ) # CRUD strings crud_strings[tablename] = Storage( label_create = T("Add Monitoring Update"), title_display = T("Monitoring Update"), title_list = T("Monitoring Updates"), title_update = T("Edit Monitoring Update"), title_upload = T("Import Monitoring Updates"), label_list_button = T("List Monitoring Updates"), label_delete_button = T("Delete Monitoring Update"), msg_record_created = T("Monitoring Update added"), msg_record_modified = T("Monitoring Update updated"), msg_record_deleted = T("Monitoring Update deleted"), msg_list_empty = T("No Monitoring Information currently available")) # ===================================================================== # Monitoring <=> Symptom # tablename = "disease_case_monitoring_symptom" table = define_table(tablename, Field("status_id", "reference disease_case_monitoring", requires = IS_ONE_OF(db, "disease_case_monitoring.id"), ), self.disease_symptom_id(), *s3_meta_fields()) # ===================================================================== # Diagnostics # probe_status = {"PENDING": T("Pending"), "PROCESSED": T("Processed"), "VALIDATED": T("Validated"), "INVALID": T("Invalid"), "LOST": T("Lost"), } tablename = "disease_case_diagnostics" table = define_table(tablename, case_id(), # @todo: make a lookup table in DiseaseDataModel: Field("probe_type"), Field("probe_number", length = 64, unique = True, ), s3_date("probe_date", default = "now", label = T("Probe Date"), ), Field("probe_status", represent = S3Represent(options = probe_status), requires = IS_IN_SET(probe_status), default = "PENDING", ), # @todo: make a lookup table in DiseaseDataModel: Field("test_type"), Field("result"), s3_date("result_date", label = T("Result Date"), ), Field("conclusion", represent = diagnosis_status_represent, requires = IS_EMPTY_OR( IS_IN_SET(diagnosis_status)), ), s3_comments(), *s3_meta_fields()) # CRUD strings crud_strings[tablename] = Storage( label_create = T("Add Diagnostic Test"), title_display = T("Diagnostic Test Details"), title_list = T("Diagnostic Tests"), title_update = T("Edit Diagnostic Test Details"), title_upload = T("Import Diagnostic Test Data"), label_list_button = T("List Diagnostic Tests"), label_delete_button = T("Delete Diagnostic Test"), msg_record_created = T("Diagnostic Test added"), msg_record_modified = T("Diagnostic Test updated"), msg_record_deleted = T("Diagnostic Test deleted"), msg_list_empty = T("No Diagnostic Tests currently registered")) # ===================================================================== # Pass names back to global scope (s3.*) return dict(disease_case_id = case_id)
def model(self): T = current.T db = current.db crud_strings = current.response.s3.crud_strings define_table = self.define_table # ----------------------------------------------------------- # Security Zone Types # tablename = "security_zone_type" define_table(tablename, Field("name", label=T("Name")), s3_comments(), *s3_meta_fields()) # CRUD strings ADD_ZONE_TYPE = T("Add Zone Type") crud_strings[tablename] = Storage( label_create=ADD_ZONE_TYPE, title_display=T("Zone Type Details"), title_list=T("Zone Types"), title_update=T("Edit Zone Type"), title_upload=T("Import Zone Types"), label_list_button=T("List Zone Types"), label_delete_button=T("Delete Zone Type"), msg_record_created=T("Zone Type added"), msg_record_modified=T("Zone Type updated"), msg_record_deleted=T("Zone Type deleted"), msg_list_empty=T("No Zone Types currently registered")) zone_type_represent = S3Represent(lookup=tablename) self.configure( tablename, deduplicate=self.security_zone_type_duplicate, ) # ----------------------------------------------------------- # Security Zones # tablename = "security_zone" define_table( tablename, Field("name", label=T("Name")), Field( "zone_type_id", db.security_zone_type, requires=IS_NULL_OR( IS_ONE_OF(db, "security_zone_type.id", zone_type_represent, sort=True)), represent=zone_type_represent, comment=S3AddResourceLink( c="security", f="zone_type", label=ADD_ZONE_TYPE, tooltip= T("Select a Zone Type from the list or click 'Add Zone Type'" )), label=T("Type")), self.gis_location_id(widget=S3LocationSelectorWidget2( catalog_layers=True, polygons=True)), s3_comments(), *s3_meta_fields()) # CRUD strings ADD_ZONE = T("Add Zone") crud_strings[tablename] = Storage( label_create=ADD_ZONE, title_display=T("Zone Details"), title_list=T("Zones"), title_update=T("Edit Zone"), title_upload=T("Import Zones"), label_list_button=T("List Zones"), label_delete_button=T("Delete Zone"), msg_record_created=T("Zone added"), msg_record_modified=T("Zone updated"), msg_record_deleted=T("Zone deleted"), msg_list_empty=T("No Zones currently registered")) zone_represent = S3Represent(lookup=tablename) # ----------------------------------------------------------- # Security Staff Types # tablename = "security_staff_type" define_table(tablename, Field("name", label=T("Name")), s3_comments(), *s3_meta_fields()) # CRUD strings ADD_STAFF = T("Add Staff Type") crud_strings[tablename] = Storage( label_create=ADD_STAFF, title_display=T("Staff Type Details"), title_list=T("Staff Types"), title_update=T("Edit Staff Type"), title_upload=T("Import Staff Types"), label_list_button=T("List Staff Types"), label_delete_button=T("Delete Staff Type"), msg_record_created=T("Staff Type added"), msg_record_modified=T("Staff Type updated"), msg_record_deleted=T("Staff Type deleted"), msg_list_empty=T("No Staff Types currently registered")) staff_type_represent = S3Represent(lookup=tablename) # ----------------------------------------------------------- # Security Staff # tablename = "security_staff" define_table( tablename, self.hrm_human_resource_id(), Field( "staff_type_id", "list:reference security_staff_type", requires=IS_NULL_OR( IS_ONE_OF(db, "security_staff_type.id", staff_type_represent, sort=True, multiple=True)), represent=self.security_staff_type_multirepresent, comment=S3AddResourceLink( c="security", f="staff_type", label=ADD_STAFF, tooltip= T("Select a Staff Type from the list or click 'Add Staff Type'" )), label=T("Type")), Field( "zone_id", db.security_zone, requires=IS_NULL_OR( IS_ONE_OF( db, "security_zone.id", zone_represent, sort=True)), represent=zone_represent, comment=S3AddResourceLink( c="security", f="zone", label=ADD_ZONE, tooltip= T("For wardens, select a Zone from the list or click 'Add Zone'" )), label=T("Zone")), self.super_link("site_id", "org_site", label=T("Facility"), represent=self.org_site_represent, readable=True, writable=True), s3_comments(), *s3_meta_fields()) # CRUD strings ADD_STAFF = T("Add Security-Related Staff") crud_strings[tablename] = Storage( label_create=ADD_STAFF, title_display=T("Security-Related Staff Details"), title_list=T("Security-Related Staff"), title_update=T("Edit Security-Related Staff"), title_upload=T("Import Security-Related Staff"), label_list_button=T("List Security-Related Staff"), label_delete_button=T("Delete Security-Related Staff"), msg_record_created=T("Security-Related Staff added"), msg_record_modified=T("Security-Related Staff updated"), msg_record_deleted=T("Security-Related Staff deleted"), msg_list_empty=T("No Security-Related Staff currently registered")) # --------------------------------------------------------------------- # Pass names back to global scope (s3.*) # return dict()
def model(self): T = current.T db = current.db crud_strings = current.response.s3.crud_strings define_table = self.define_table location_id = self.gis_location_id # ----------------------------------------------------------- # Water Zone Types # tablename = "water_zone_type" define_table(tablename, Field( "name", label=T("Name"), ), s3_comments(), *s3_meta_fields()) # CRUD strings ADD_ZONE_TYPE = T("Create Zone Type") crud_strings[tablename] = Storage( label_create=ADD_ZONE_TYPE, title_display=T("Zone Type Details"), title_list=T("Zone Types"), title_update=T("Edit Zone Type"), title_upload=T("Import Zone Types"), label_list_button=T("List Zone Types"), label_delete_button=T("Delete Zone Type"), msg_record_created=T("Zone Type added"), msg_record_modified=T("Zone Type updated"), msg_record_deleted=T("Zone Type deleted"), msg_list_empty=T("No Zone Types currently registered")) zone_type_represent = S3Represent(lookup=tablename) self.configure( tablename, deduplicate=self.water_zone_type_duplicate, ) # ----------------------------------------------------------- # Water Zones # - e.g. Floods # tablename = "water_zone" define_table( tablename, Field( "name", label=T("Name"), ), Field( "zone_type_id", db.water_zone_type, label=T("Type"), represent=zone_type_represent, requires=IS_EMPTY_OR( IS_ONE_OF(db, "water_zone_type.id", zone_type_represent, sort=True)), comment=S3AddResourceLink( c="water", f="zone_type", label=ADD_ZONE_TYPE, tooltip= T("Select a Zone Type from the list or click 'Add Zone Type'" )), ), location_id(widget=S3LocationSelectorWidget2( catalog_layers=True, points=False, polygons=True, )), s3_comments(), *s3_meta_fields()) # CRUD strings crud_strings[tablename] = Storage( label_create=T("Create Zone"), title_display=T("Zone Details"), title_list=T("Zones"), title_update=T("Edit Zone"), title_upload=T("Import Zones"), label_list_button=T("List Zones"), label_delete_button=T("Delete Zone"), msg_record_created=T("Zone added"), msg_record_modified=T("Zone updated"), msg_record_deleted=T("Zone deleted"), msg_list_empty=T("No Zones currently registered")) zone_represent = S3Represent(lookup=tablename) # ----------------------------------------------------------------------------- # Rivers tablename = "water_river" define_table( tablename, Field( "name", label=T("Name"), requires=IS_NOT_EMPTY(), ), location_id(widget=S3LocationSelectorWidget2( catalog_layers=True, points=False, polygons=True, )), s3_comments(), *s3_meta_fields()) # CRUD strings ADD_RIVER = T("Create River") crud_strings[tablename] = Storage( label_create=ADD_RIVER, title_display=T("River Details"), title_list=T("Rivers"), title_update=T("Edit River"), label_list_button=T("List Rivers"), msg_record_created=T("River added"), msg_record_modified=T("River updated"), msg_record_deleted=T("River deleted"), msg_list_empty=T("No Rivers currently registered")) #represent = S3Represent(lookup = tablename) #river_id = S3ReusableField("river_id", "reference %s" % tablename, # label = T("River"), # ondelete = "RESTRICT", # represent = represent, # requires = IS_EMPTY_OR(IS_ONE_OF(db, "water_river.id", represent)), # comment = S3AddResourceLink(c="water", # f="river", # title=ADD_RIVER), # ) # ----------------------------------------------------------------------------- # Gauges # # @ToDo: Link together ones on same river with upstream/downstream relationships # flowstatus_opts = { 1: T("Normal"), 2: T("High"), 3: T("Very High"), 4: T("Low") } tablename = "water_gauge" define_table(tablename, Field("name", label = T("Name"), ), Field("code", label = T("Code"), ), #super_link("source_id", "doc_source_entity"), location_id(), Field("url", label = T("URL"), represent = lambda url: \ A(url, _href=url, _target="blank"), requires = IS_EMPTY_OR(IS_URL()), ), Field("image_url", label = T("Image URL"), ), Field("discharge", "integer", label = T("Discharge (cusecs)"), ), Field("status", "integer", label = T("Flow Status"), represent = lambda opt: \ flowstatus_opts.get(opt, opt), requires = IS_EMPTY_OR(IS_IN_SET(flowstatus_opts)), ), s3_comments(), *s3_meta_fields()) crud_strings[tablename] = Storage( label_create=T("Create Gauge"), title_display=T("Gauge Details"), title_list=T("Gauges"), title_update=T("Edit Gauge"), title_map=T("Map of Gauges"), label_list_button=T("List Gauges"), msg_record_created=T("Gauge added"), msg_record_modified=T("Gauge updated"), msg_record_deleted=T("Gauge deleted"), msg_list_empty=T("No Gauges currently registered")) # ----------------------------------------------------------------------------- # Debris Basins # http://dpw.lacounty.gov/wrd/sediment/why_move_dirt.cfm # #tablename = "water_debris_basin" #define_table(tablename, # Field("name", # label = T("Name"), # ), # location_id(), # s3_comments(), # *s3_meta_fields()) #crud_strings[tablename] = Storage( # label_create = T("Create Debris Basin"), # title_display = T("Debris Basin Details"), # title_list = T("Debris Basins"), # title_update = T("Edit Debris Basin"), # title_map = T("Map of Debris Basins"), # label_list_button = T("List Debris Basins"), # msg_record_created = T("Debris Basin added"), # msg_record_modified = T("Debris Basin updated"), # msg_record_deleted = T("Debris Basin deleted"), # msg_list_empty = T("No Debris Basins currently registered")) # ----------------------------------------------------------------------------- # Reservoirs # Water Storage areas # #tablename = "water_reservoir" #define_table(tablename, # Field("name", # label = T("Name"), # ), # location_id(), # s3_comments(), # *s3_meta_fields()) #crud_strings[tablename] = Storage( # label_create = T("Create Reservoir"), # title_display = T("Reservoir Details"), # title_list = T("Reservoirs"), # title_update = T("Edit Reservoir"), # title_map = T("Map of Reservoirs"), # label_list_button = T("List Reservoirs"), # msg_record_created = T("Reservoir added"), # msg_record_modified = T("Reservoir updated"), # msg_record_deleted = T("Reservoir deleted"), # msg_list_empty = T("No Reservoirs currently registered")) # --------------------------------------------------------------------- # Pass names back to global scope (s3.*) # return dict()
def model(self): T = current.T db = current.db auth = current.auth s3 = current.response.s3 organisation_id = self.org_organisation_id ADMIN = current.session.s3.system_roles.ADMIN is_admin = auth.s3_has_role(ADMIN) add_components = self.add_components configure = self.configure crud_strings = s3.crud_strings define_table = self.define_table root_org = auth.root_org() if is_admin: filter_opts = () elif root_org: filter_opts = (root_org, None) else: filter_opts = (None, ) # --------------------------------------------------------------------- # Membership Types # tablename = "member_membership_type" define_table( tablename, Field( "name", notnull=True, length=64, label=T("Name"), ), # Only included in order to be able to set # realm_entity to filter appropriately organisation_id( default=root_org, readable=is_admin, writable=is_admin, ), s3_comments( label=T("Description"), comment=None, ), *s3_meta_fields()) ADD_MEMBERSHIP_TYPE = T("Create Membership Type") crud_strings[tablename] = Storage( label_create=ADD_MEMBERSHIP_TYPE, title_display=T("Membership Type Details"), title_list=T("Membership Types"), title_update=T("Edit Membership Type"), title_upload=T("Import Membership Types"), label_list_button=T("List Membership Types"), label_delete_button=T("Delete Membership Type"), msg_record_created=T("Membership Type added"), msg_record_modified=T("Membership Type updated"), msg_record_deleted=T("Membership Type deleted"), msg_list_empty=T("No membership types currently registered")) represent = S3Represent(lookup=tablename) membership_type_id = S3ReusableField( "membership_type_id", "reference %s" % tablename, label=T("Type"), ondelete="SET NULL", represent=represent, requires=IS_EMPTY_OR( IS_ONE_OF(db, "member_membership_type.id", represent, filterby="organisation_id", filter_opts=filter_opts)), sortby="name", comment=S3AddResourceLink( f="membership_type", label=ADD_MEMBERSHIP_TYPE, title=ADD_MEMBERSHIP_TYPE, tooltip=T("Add a new membership type to the catalog.")), ) configure( tablename, deduplicate=self.member_type_duplicate, ) # --------------------------------------------------------------------- # Members # tablename = "member_membership" define_table( tablename, organisation_id( empty=False, requires=self.org_organisation_requires(updateable=True, ), ), Field( "code", label=T("Member ID"), #readable = False, #writable = False, ), self.pr_person_id( comment=None, requires=IS_ADD_PERSON_WIDGET2(), widget=S3AddPersonWidget2(controller="member"), ), membership_type_id(), # History s3_date( "start_date", label=T("Date Joined"), ), s3_date( "end_date", label=T("Date resigned"), ), Field( "membership_fee", "double", label=T("Membership Fee"), ), s3_date( "membership_paid", label=T("Membership Paid"), ), # Location (from pr_address component) self.gis_location_id( readable=False, writable=False, ), Field.Method("paid", self.member_membership_paid), *s3_meta_fields()) crud_strings[tablename] = Storage( label_create=T("Create Member"), title_display=T("Member Details"), title_list=T("Members"), title_update=T("Edit Member"), title_upload=T("Import Members"), label_list_button=T("List Members"), label_delete_button=T("Delete Member"), msg_record_created=T("Member added"), msg_record_modified=T("Member updated"), msg_record_deleted=T("Member deleted"), msg_list_empty=T("No Members currently registered")) def member_type_opts(): """ Provide the options for the Membership Type search filter """ ttable = self.member_membership_type if root_org: query = (ttable.deleted == False) & \ ((ttable.organisation_id == root_org) | \ (ttable.organisation_id == None)) else: query = (ttable.deleted == False) & \ (ttable.organisation_id == None) rows = db(query).select(ttable.id, ttable.name) return dict((row.id, row.name) for row in rows) # Which levels of Hierarchy are we using? levels = current.gis.get_relevant_hierarchy_levels() list_fields = [ "person_id", "organisation_id", "membership_type_id", "start_date", # useful for testing the paid virtual field #"membership_paid", (T("Paid"), "paid"), (T("Email"), "email.value"), (T("Phone"), "phone.value"), ] report_fields = [ "person_id", "membership_type_id", (T("Paid"), "paid"), "organisation_id", ] text_fields = [ "membership_type_id", "organisation_id$name", "organisation_id$acronym", "person_id$first_name", "person_id$middle_name", "person_id$last_name", ] for level in levels: lfield = "location_id$%s" % level list_fields.append(lfield) report_fields.append(lfield) text_fields.append(lfield) if current.deployment_settings.get_org_branches(): org_filter = S3HierarchyFilter( "organisation_id", # Can be unhidden in customise_xx_resource if there is a need to use a default_filter hidden=True, leafonly=False, ) else: org_filter = S3OptionsFilter( "organisation_id", filter=True, header="", # Can be unhidden in customise_xx_resource if there is a need to use a default_filter hidden=True, ) filter_widgets = [ S3TextFilter( text_fields, label=T("Search"), ), org_filter, S3OptionsFilter( "membership_type_id", cols=3, options=member_type_opts, hidden=True, ), S3OptionsFilter( "paid", cols=3, label=T("Paid"), options={ T("paid"): T("paid"), T("overdue"): T("overdue"), T("expired"): T("expired"), }, hidden=True, ), S3LocationFilter( "location_id", label=T("Location"), levels=levels, hidden=True, ), ] report_options = Storage(rows=report_fields, cols=report_fields, facts=report_fields, defaults=Storage( cols="membership.organisation_id", rows="membership.membership_type_id", fact="count(membership.person_id)", totals=True, )) configure( tablename, create_next=URL(f="person", args="address", vars={"membership.id": "[id]"}), deduplicate=self.member_duplicate, extra_fields=( "start_date", "membership_paid", ), filter_widgets=filter_widgets, list_fields=list_fields, onaccept=self.member_onaccept, report_options=report_options, # Default summary summary=[ { "name": "addform", "common": True, "widgets": [{ "method": "create" }], }, { "name": "table", "label": "Table", "widgets": [{ "method": "datatable" }] }, { "name": "report", "label": "Report", "widgets": [{ "method": "report", "ajax_init": True }] }, { "name": "map", "label": "Map", "widgets": [{ "method": "map", "ajax_init": True }], }, ], update_realm=True, ) # Components self.add_components( tablename, # Contact Information pr_contact=( # Email { "name": "email", "link": "pr_person", "joinby": "id", "key": "pe_id", "fkey": "pe_id", "pkey": "person_id", "filterby": "contact_method", "filterfor": ("EMAIL", ), }, # Phone { "name": "phone", "link": "pr_person", "joinby": "id", "key": "pe_id", "fkey": "pe_id", "pkey": "person_id", "filterby": "contact_method", "filterfor": ( "SMS", "HOME_PHONE", "WORK_PHONE", ), }, ), ) # --------------------------------------------------------------------- # Pass names back to global scope (s3.*) # return dict()
def model(self): T = current.T db = current.db add_component = self.add_component configure = self.configure crud_strings = current.response.s3.crud_strings define_table = self.define_table NONE = current.messages["NONE"] # --------------------------------------------------------------------- # Event Types / Disaster Types # tablename = "event_event_type" table = self.define_table( tablename, Field("name", notnull=True, length=64, label=T("Name")), s3_comments(), *s3_meta_fields()) crud_strings[tablename] = Storage( title_create=T("Add Event Type"), title_display=T("Event Type Details"), title_list=T("Event Types"), title_update=T("Edit Event Type"), title_search=T("Search Event Types"), title_upload=T("Import Event Types"), subtitle_create=T("Add New Event Type"), label_list_button=T("List Event Types"), label_create_button=T("Add Event Type"), label_delete_button=T("Remove Event Type from this event"), msg_record_created=T("Event Type added"), msg_record_modified=T("Event Type updated"), msg_record_deleted=T("Event Type removed"), msg_list_empty=T("No Event Types currently registered")) represent = S3Represent(lookup=tablename) event_type_id = S3ReusableField( "event_type_id", table, sortby="name", requires=IS_NULL_OR( IS_ONE_OF(db, "event_event_type.id", represent, orderby="event_event_type.name", sort=True)), represent=represent, label=T("Event Type"), ondelete="RESTRICT", # Uncomment these to use an Autocomplete & not a Dropdown #widget = S3AutocompleteWidget() #comment = DIV(_class="tooltip", # _title="%s|%s" % (T("Event Type"), # T("Enter some characters to bring up a list of possible matches"))) ) configure(tablename, deduplicate=self.event_type_duplicate) # --------------------------------------------------------------------- # Events / Disasters # # Events can be a way of grouping related Incidents or used standalone # # --------------------------------------------------------------------- tablename = "event_event" table = define_table( tablename, Field( "name", notnull=True, # Name could be a code length=64, # Mayon compatiblity label=T("Name")), event_type_id(), Field( "exercise", "boolean", represent=lambda opt: "√" if opt else NONE, #comment = DIV(_class="tooltip", # _title="%s|%s" % (T("Exercise"), # Should! # T("Exercises mean all screens have a watermark & all notifications have a prefix."))), label=T("Exercise?")), s3_datetime( name="zero_hour", label=T("Zero Hour"), default="now", comment=DIV(_class="tooltip", _title="%s|%s" % (T("Zero Hour"), T("The time at which the Event started."))), ), Field("closed", "boolean", default=False, represent=s3_yes_no_represent, label=T("Closed")), s3_comments(), *s3_meta_fields()) # CRUD strings ADD_EVENT = T("New Event") crud_strings[tablename] = Storage( title_create=ADD_EVENT, title_display=T("Event Details"), title_list=T("Events"), title_update=T("Edit Event"), title_search=T("Search Events"), subtitle_create=T("Add New Event"), label_list_button=T("List Events"), label_create_button=ADD_EVENT, label_delete_button=T("Delete Event"), msg_record_created=T("Event added"), msg_record_modified=T("Event updated"), msg_record_deleted=T("Event deleted"), msg_list_empty=T("No Events currently registered")) represent = S3Represent(lookup=tablename) event_id = S3ReusableField( "event_id", table, sortby="name", requires=IS_NULL_OR( IS_ONE_OF(db, "event_event.id", represent, filterby="closed", filter_opts=[False], orderby="event_event.name", sort=True)), represent=represent, label=T("Event"), ondelete="CASCADE", # Uncomment these to use an Autocomplete & not a Dropdown #widget = S3AutocompleteWidget() #comment = DIV(_class="tooltip", # _title="%s|%s" % (T("Event"), # T("Enter some characters to bring up a list of possible matches"))) ) configure(tablename, orderby=~table.zero_hour, list_orderby=~table.zero_hour, update_onaccept=self.event_update_onaccept, deduplicate=self.event_duplicate, list_fields=[ "id", "name", "event_type_id$name", (T("Location"), "location.name"), "zero_hour", "exercise", "closed", "comments", ]) # Components # Incidents add_component("event_incident", event_event="event_id") # Locations add_component("gis_location", event_event=Storage(link="event_event_location", joinby="event_id", key="location_id", actuate="hide")) # Requests add_component("req_req", event_event="event_id") # Tags add_component("event_event_tag", event_event=dict(joinby="event_id", name="tag")) # --------------------------------------------------------------------- # Event Locations (link table) # tablename = "event_event_location" table = define_table( tablename, event_id(), self.gis_location_id( widget=S3LocationAutocompleteWidget(), requires=IS_LOCATION(), represent=self.gis_location_lx_represent, comment=S3AddResourceLink( c="gis", f="location", label=T("Add Location"), title=T("Location"), tooltip= T("Enter some characters to bring up a list of possible matches" )), ), *s3_meta_fields()) # --------------------------------------------------------------------- # Event Tags # - Key-Value extensions # - can be used to identify a Source # - can be used to add extra attributes (e.g. Area, Population) # - can link Events to other Systems, such as: # * GLIDE (http://glidenumber.net/glide/public/about.jsp) # * Mayon # * WebEOC # - can be a Triple Store for Semantic Web support # tablename = "event_event_tag" table = define_table( tablename, event_id(), # key is a reserved word in MySQL Field("tag", label=T("Key")), Field("value", label=T("Value")), s3_comments(), *s3_meta_fields()) configure(tablename, deduplicate=self.event_event_tag_deduplicate) # --------------------------------------------------------------------- # Pass names back to global scope (s3.*) # return Storage(event_event_id=event_id, )