def customise_org_organisation_resource(r, tablename): from s3 import S3SQLCustomForm, S3SQLInlineComponent, S3SQLInlineLink, s3_comments_widget s3db = current.s3db s3db.org_organisation_tag.value.widget = s3_comments_widget crud_form = S3SQLCustomForm( "name", "acronym", S3SQLInlineLink( "organisation_type", field="organisation_type_id", # Default 10 options just triggers which adds unnecessary complexity to a commonly-used form & commonly an early one (create Org when registering) filter=False, label=T("Type"), multiple=False, widget="multiselect", ), S3SQLInlineLink( "sector", columns=4, label=T("Sectors"), field="sector_id", ), S3SQLInlineLink( "service", columns=4, label=T("Services"), field="service_id", ), "country", "phone", "website", "logo", (T("About"), "comments"), S3SQLInlineComponent( "tag", label=T("Vision"), fields=[("", "value")], filterby={ "field": "tag", "options": "vision", }, multiple=False, ), ) s3db.configure( tablename, crud_form=crud_form, )
def customise_project_project_resource(r, tablename): from s3 import S3SQLCustomForm, S3SQLInlineLink crud_form = S3SQLCustomForm("organisation_id", "name", "description", "status_id", "start_date", "end_date", "calendar", "human_resource_id", S3SQLInlineLink("sector", label = T("Sectors"), field = "sector_id", cols = 3, ), "budget", "currency", "comments", ) current.s3db.configure(tablename, crud_form = crud_form, )
def customise_org_organisation_resource(r, tablename): from s3 import S3SQLCustomForm, S3SQLInlineComponent, S3SQLInlineLink crud_form = S3SQLCustomForm( "name", "acronym", S3SQLInlineLink( "organisation_type", field="organisation_type_id", label=T("Type"), multiple=False, #widget = "hierarchy", ), S3SQLInlineComponent( "tag", label=T("CAP OID"), multiple=False, fields=[("", "value")], filterby=dict( field="tag", options="cap_oid", ), ), "website", "comments", ) current.s3db.configure( "org_organisation", crud_form=crud_form, )
def customise_org_organisation_resource(r, tablename): s3db = current.s3db # Custom Components s3db.add_components( tablename, org_organisation_tag=( # On-call Duty Number { "name": "duty", "joinby": "organisation_id", "filterby": { "tag": "duty", }, "multiple": False, }, ), ) from s3 import S3SQLCustomForm, S3SQLInlineComponent, S3SQLInlineLink, \ IS_EMPTY_OR, IS_PHONE_NUMBER_MULTI, S3PhoneWidget, s3_phone_represent # Individual settings for specific tag components components_get = s3db.resource(tablename).components.get duty = components_get("duty") f = duty.table.value f.represent = s3_phone_represent, f.requires = IS_EMPTY_OR(IS_PHONE_NUMBER_MULTI()) f.widget = S3PhoneWidget() crud_form = S3SQLCustomForm( "name", "acronym", S3SQLInlineLink( "organisation_type", field="organisation_type_id", # Default 10 options just triggers which adds unnecessary complexity to a commonly-used form & commonly an early one (create Org when registering) filter=False, label=T("Type"), multiple=False, widget="multiselect", ), "country", (T("Reception Phone #"), "phone"), S3SQLInlineComponent( "duty", label=T("On-call Duty Number"), fields=[("", "value")], multiple=False, ), "website", "logo", "comments", ) s3db.configure( tablename, crud_form=crud_form, )
def customise_dc_response_resource(r, tablename): if r.controller in ( "event", "hrm", # Training Event Evaluations ): return s3db = current.s3db template_name = r.get_vars.get("~.template_id$name") if template_name: ttable = s3db.dc_template template = current.db(ttable.name == template_name).select( ttable.id, limitby=(0, 1), ).first() if template: f = s3db.dc_response.template_id f.default = template.id f.readable = f.writable = False current.response.s3.crud_strings[tablename] = Storage( label_create=T("Create %s") % template_name, title_display=T("%s Details") % template_name, title_list=T("%ss") % template_name, title_update=T("Edit %s") % template_name, #title_upload = T("Import %ss") % template_name, label_list_button=T("List %ss") % template_name, label_delete_button=T("Delete %s") % template_name, msg_record_created=T("%s added") % template_name, msg_record_modified=T("%s updated") % template_name, msg_record_deleted=T("%s deleted") % template_name, msg_list_empty=T("No %ss currently registered") % template_name) from s3 import S3DateFilter, S3LocationFilter, S3OptionsFilter, S3SQLCustomForm, S3SQLInlineLink crud_form = S3SQLCustomForm( S3SQLInlineLink( "event", field="event_id", #label = type_label, multiple=False, ), "template_id", "date", "location_id", "organisation_id", "person_id", "comments", ) s3db.configure( tablename, crud_form=crud_form, )
def customise_org_service_location_resource(r, tablename): table = current.s3db.org_service_location # Hide site_id field = table.site_id field.readable = field.writable = False # Enable location_id from s3 import S3LocationSelector field = table.location_id field.readable = field.writable = True #field.widget = S3LocationSelector(levels = ["L1", "L2", "L3", "L4"], # show_postcode = False, # show_map = False, # ) # Custom CRUD form from s3 import S3SQLCustomForm, S3SQLInlineLink crud_form = S3SQLCustomForm( "organisation_id", "location_id", S3SQLInlineLink( "service", label=T("Services"), field="service_id", ), #"description", "status", "start_date", #"end_date", "comments", ) # List fields list_fields = [ "organisation_id", "location_id", "service_location_service.service_id", #"description", "status", "start_date", #"end_date", "comments", ] # Configure current.s3db.configure( "org_service_location", crud_form=crud_form, list_fields=list_fields, )
def customise_project_location_resource(r, tablename): s3db = current.s3db table = s3db.project_location # Allow editing of names field = table.name field.readable = field.writable = True # Hide percentage field (not needed) field = table.percentage field.readable = field.writable = False # Use location selector from s3 import S3LocationSelector field = table.location_id field.widget = S3LocationSelector(show_address=True) # List fields list_fields = [ "project_id", "name", "location_id", "location_id$addr_street", "activity_type_location.activity_type_id", ] # CRUD Form from s3 import S3SQLCustomForm crud_form = S3SQLCustomForm( "project_id", "name", "location_id", S3SQLInlineLink( "activity_type", field="activity_type_id", multiple=True, ), "comments", ) # Reconfigure resource s3db.configure( "project_location", crud_form=crud_form, list_fields=list_fields, create_next=None, onaccept=None, )
def customise_project_project_resource(r, tablename): from s3 import S3LocationSelector, S3Represent, S3TextFilter, S3OptionsFilter, S3LocationFilter s3db = current.s3db table = s3db.project_project table.code.label = "SOF" s3db.project_location.location_id.widget = S3LocationSelector( levels=("L1", "L2", "L3"), show_map=False, ) # Always SC otable = s3db.org_organisation org = current.db(otable.name == SAVE).select(otable.id, cache=s3db.cache, limitby=(0, 1)).first() try: SCI = org.id except: current.log.error("Cannot find org %s - prepop not done?" % SAVE) else: f = table.organisation_id f.default = SCI org_represent = s3db.org_OrganisationRepresent(acronym=False, show_link=True) s3db.project_organisation.organisation_id.represent = org_represent try: s3db.project_donor_organisation.organisation_id.represent = org_represent except: # Table not present on Activities tab pass from s3 import S3SQLCustomForm, S3SQLInlineComponent, S3SQLInlineLink # @ToDo: Inherit Locations from Disaster? crud_form = S3SQLCustomForm( S3SQLInlineLink( "programme", label=T("Program"), field="programme_id", multiple=False, ), "name", "code", "status_id", "start_date", "end_date", "budget", "currency", S3SQLInlineComponent( "location", label=T("Locations"), fields=["location_id"], ), S3SQLInlineComponent( "organisation", name="donor", label=T("Donor(s)"), fields=["organisation_id"], ), # @ToDo: Set Metadata on File: Org, Location, Disaster, Date S3SQLInlineComponent( "document", name="concept_note", label=T("Concept Note"), fields=["file"], multiple=False, ), # @ToDo: Be able to retrieve the correct document #S3SQLInlineComponent("document", # name = "log_frame", # label = T("Log Frame"), # fields = ["file"], # multiple = False, # ), "comments", ) filter_widgets = [ S3TextFilter( [ "name", "code", #"description", ], label=T("Search"), comment=T("Search for a Project by name or code"), ), S3OptionsFilter( "status_id", label=T("Status"), cols=3, ), S3OptionsFilter( "donor.organisation_id", label=T("Donor"), hidden=True, ), S3LocationFilter( "location.location_id", levels=("L1", "L2", "L3"), hidden=True, ), S3OptionsFilter( "programme_project.programme_id", label=T("Program"), hidden=True, ), #S3OptionsFilter("sector_project.sector_id", # label = T("Sector"), # location_filter = True, # none = True, # hidden = True, # ), ] list_fields = [ "status_id", "code", "name", (T("Donors"), "donor.organisation_id"), (T("Locations"), "location.location_id"), "start_date", "end_date", "budget", "currency", (T("Program"), "programme.name"), ] s3db.configure( "project_project", crud_form=crud_form, filter_widgets=filter_widgets, list_fields=list_fields, )
def customise_org_organisation_resource(r, tablename): from gluon.html import DIV, INPUT from s3 import s3_comments_widget, \ S3LocationSelector, \ S3MultiSelectWidget, \ S3SQLCustomForm, \ S3SQLInlineComponent, \ S3SQLVerticalSubFormLayout s3db = current.s3db # Filtered component to access phone number and email s3db.add_components( tablename, org_facility={ "name": "main_facility", "joinby": "organisation_id", "filterby": { "main_facility": True, }, }, ) s3db.org_organisation_location.location_id.widget = S3LocationSelector( levels=("L2", "L3"), show_map=False, labels=False, ) crud_fields = [ "name", "acronym", S3SQLInlineLink( "organisation_type", field="organisation_type_id", label=T("Type"), multiple=False, ), S3SQLInlineLink( "service", label=T("Services"), field="service_id", ), S3SQLInlineComponent( "facility", label=T("Main Facility"), fields=[ "name", "phone1", "phone2", "email", "location_id", ], layout=S3SQLVerticalSubFormLayout, filterby={ "field": "main_facility", "options": True, }, multiple=False, ), "website", S3SQLInlineComponent( "contact", name="twitter", label=T("Twitter"), multiple=False, fields=[("", "value")], filterby=dict( field="contact_method", options="TWITTER", ), ), S3SQLInlineComponent( "contact", name="facebook", label=T("Facebook"), multiple=False, fields=[("", "value")], filterby=dict( field="contact_method", options="FACEBOOK", ), ), "comments", ] crud_form = S3SQLCustomForm(*crud_fields) from s3 import S3LocationFilter, S3OptionsFilter, S3TextFilter #, S3HierarchyFilter filter_widgets = [ S3TextFilter( ["name", "acronym"], label=T("Search"), comment= T("Search by organization name or acronym. You can use * as wildcard." ), _class="filter-search", ), S3LocationFilter( "org_facility.location_id", label=T("Location"), #hidden = True, ), S3OptionsFilter( "organisation_organisation_type.organisation_type_id", label=T("Type"), #hidden = True, ), S3OptionsFilter("service_organisation.service_id", #hidden = True, ), ] list_fields = [ "name", (T("Type"), "organisation_organisation_type.organisation_type_id"), (T("Services"), "service.name"), (T("Adresse"), "main_facility.location_id"), (T("Phone #"), "main_facility.phone1"), (T("Email"), "main_facility.email"), (T("Facebook"), "facebook.value"), "website", (T("Last Updated"), "modified_on"), ] s3db.configure( tablename, crud_form=crud_form, filter_widgets=filter_widgets, list_fields=list_fields, )
def customise_org_facility_resource(r, tablename): from s3 import S3SQLCustomForm, S3SQLInlineLink, \ S3LocationSelector, S3LocationFilter, S3TextFilter s3db = current.s3db s3db.org_facility.location_id.widget = S3LocationSelector( levels=("L1", "L2", "L3", "L4"), required_levels=("L1", "L2", "L3"), show_address=True, show_postcode=True, show_map=True, ) # Geocoder current.response.s3.scripts.append( "/%s/static/themes/RLP/js/geocoderPlugin.js" % r.application) text_fields = [ "name", #"code", "comments", "organisation_id$name", "organisation_id$acronym", "location_id$L1", "location_id$L2", "location_id$L3", "location_id$L4", ] filter_widgets = [ S3TextFilter( text_fields, label=T("Search"), #_class = "filter-search", ), S3LocationFilter( "location_id", #label = T("Location"), levels=("L1", "L2", "L3", "L4"), ), ] crud_fields = [ "name", S3SQLInlineLink( "facility_type", label=T("Facility Type"), field="facility_type_id", widget="groupedopts", cols=3, ), "organisation_id", "location_id", (T("Telephone"), "phone1"), (T("Opening Hours"), "opening_times"), "obsolete", "comments", ] list_fields = [ "name", #"site_facility_type.facility_type_id", "location_id$L1", "location_id$L2", "location_id$L3", "location_id$L4", "location_id$addr_street", "location_id$addr_postcode", (T("Telephone"), "phone1"), (T("Opening Hours"), "opening_times"), "organisation_id", #"obsolete", #"comments", ] s3db.configure( tablename, crud_form=S3SQLCustomForm(*crud_fields), filter_widgets=filter_widgets, list_fields=list_fields, )
def customise_org_organisation_resource(r, tablename): s3db = current.s3db # Simplify form table = s3db.org_organisation field = table.comments from gluon import DIV field.comment = DIV( _class="tooltip", _title="%s|%s" % (T("About"), T("Describe the organisation, e.g. mission, history and other relevant details" ))) if not current.auth.is_logged_in(): field = table.logo field.readable = field.writable = False # User can create records since we need this during registration, # but we don't want to let the user do this from the list view s3db.configure( "org_organisation", listadd=False, ) # Custom filters to match the information provided from s3 import S3LocationFilter, S3OptionsFilter, S3TextFilter filter_widgets = [ S3TextFilter( [ "name", "acronym", #"website", #"comments", ], label=T("Search"), comment= T("Search by organization name or acronym. You can use * as wildcard." ), ), #S3OptionsFilter("sector_organisation.sector_id", # ), S3OptionsFilter( "organisation_organisation_type.organisation_type_id", label=T("Type"), ), #S3LocationFilter("organisation_location.location_id", # label = T("Areas Served"), # levels = ("L1", "L2", "L3", "L4"), # #hidden = True, # ), ] # CRUD Form from s3 import S3SQLCustomForm, \ S3SQLInlineComponent, \ S3SQLInlineLink, \ S3SQLVerticalSubFormLayout multitype = settings.get_org_organisation_types_multiple() crud_form = S3SQLCustomForm( "name", "acronym", S3SQLInlineLink( "organisation_type", field="organisation_type_id", filter=False, label=T("Type"), multiple=multitype, ), "country", S3SQLInlineLink( "sector", cols=3, label=T("Sectors"), field="sector_id", #required = True, ), (T("About"), "comments"), "website", S3SQLInlineComponent( "facility", label=T("Main Facility"), fields=[ "name", "phone1", "phone2", "email", "location_id", ], layout=S3SQLVerticalSubFormLayout, filterby={ "field": "main_facility", "options": True, }, multiple=False, ), ) s3db.configure( "org_organisation", filter_widgets=filter_widgets, crud_form=crud_form, )
def customise_req_need_resource(r, tablename): s3db = current.s3db tablename = "req_need" # Custom Filtered Components s3db.add_components( tablename, req_need_tag=( # Verified { "name": "verified", "joinby": "need_id", "filterby": { "tag": "verified", }, "multiple": False, }, )) # Individual settings for specific tag components from gluon import IS_EMPTY_OR, IS_IN_SET components_get = r.resource.components.get verified = components_get("verified") f = verified.table.value f.requires = IS_EMPTY_OR(IS_IN_SET((True, False))) auth = current.auth if auth.s3_has_role("ADMIN"): f.default = True else: user = auth.user if user and user.organisation_id: f.default = True else: f.default = False f.writable = False from s3 import S3LocationFilter, S3OptionsFilter, S3SQLCustomForm, S3SQLInlineComponent, S3SQLInlineLink crud_form = S3SQLCustomForm( S3SQLInlineLink( "event", field="event_id", label=T("Disaster"), multiple=False, #required = True, ), "location_id", "date", "priority", S3SQLInlineLink( "sector", field="sector_id", filter=False, label=T("Sector"), multiple=False, ), "summary", S3SQLInlineComponent( "verified", name="verified", label=T("Verified"), fields=[ ("", "value"), ], multiple=False, ), "status", "comments", ) filter_widgets = [ S3OptionsFilter("event.event_type_id"), S3OptionsFilter( "event__link.event_id" ), # @ToDo: Filter this list dynamically based on Event Type S3OptionsFilter("sector__link.sector_id"), S3LocationFilter( "location_id", # These levels are for SHARE/LK levels=("L2", "L3", "L4"), ), S3OptionsFilter( "status", cols=3, label=T("Status"), ), S3OptionsFilter( "verified.value", cols=2, label=T("Verified"), ), ] s3db.configure( tablename, crud_form=crud_form, filter_widgets=filter_widgets, list_fields=[ (T("Disaster"), "event__link.event_id"), # These levels/Labels are for SHARE/LK (T("District"), "location_id$L2"), (T("DS"), "location_id$L3"), (T("GN"), "location_id$L4"), "date", "priority", "summary", "sector__link.sector_id", (T("Status"), "status"), (T("Verified"), "verified.value"), ], )
def customise_project_activity_resource(r, tablename): s3db = current.s3db tablename = "project_activity" # Custom Filtered Components s3db.add_components( tablename, project_activity_organisation=( # Agency { "name": "agency", "joinby": "activity_id", "filterby": { "role": 1, }, #"multiple": False, }, # Partners { "name": "partner", "joinby": "activity_id", "filterby": { "role": 2, }, #"multiple": False, }, # Donors { "name": "donor", "joinby": "activity_id", "filterby": { "role": 3, }, #"multiple": False, }, ), project_activity_tag=( # Modality { "name": "modality", "joinby": "activity_id", "filterby": { "tag": "modality", }, "multiple": False, }, # Number { "name": "number", "joinby": "activity_id", "filterby": { "tag": "number", }, "multiple": False, }, )) # Individual settings for specific tag components from gluon import IS_EMPTY_OR, IS_IN_SET, IS_INT_IN_RANGE components_get = r.resource.components.get donor = components_get("donor") donor.table.organisation_id.default = None partner = components_get("partner") partner.table.organisation_id.default = None modality = components_get("modality") modality.table.value.requires = IS_EMPTY_OR( IS_IN_SET(("Cash", "In-kind"))) number = components_get("number") number.table.value.requires = IS_EMPTY_OR(IS_INT_IN_RANGE()) s3db.project_activity_data.unit.requires = IS_EMPTY_OR( IS_IN_SET(("People", "Households"))) from s3 import S3LocationFilter, S3OptionsFilter, S3SQLCustomForm, S3SQLInlineComponent, S3SQLInlineLink crud_form = S3SQLCustomForm( S3SQLInlineLink( "event", field="event_id", label=T("Disaster"), multiple=False, #required = True, ), S3SQLInlineComponent( "agency", name="agency", label=T("Agency"), fields=[ ("", "organisation_id"), ], #multiple = False, required=True, ), # @ToDo: MultiSelectWidget is nicer UI but S3SQLInlineLink # requires the link*ed* table as component (not the # link table as applied here) and linked components # cannot currently be filtered by link table fields # (=> should solve the latter rather than the former) # @ToDo: Fix Create Popups S3SQLInlineComponent( "partner", name="partner", label=T("Implementing Partner"), fields=[ ("", "organisation_id"), ], ), S3SQLInlineComponent( "donor", name="donor", label=T("Donor"), fields=[ ("", "organisation_id"), ], ), "location_id", S3SQLInlineLink( "sector", field="sector_id", filter=False, label=T("Sector"), multiple=False, ), (T("Relief Items/Activity"), "name"), S3SQLInlineComponent( "modality", name="modality", label=T("Modality"), fields=[ ("", "value"), ], multiple=False, ), S3SQLInlineComponent( "number", name="number", label=T("Number of Items/Kits/Activities"), fields=[ ("", "value"), ], multiple=False, ), (T("Activity Date (Planned/Start Date)"), "date"), (T("Activity Date (Completion Date)"), "end_date"), S3SQLInlineComponent( "activity_data", label="", fields=[ (T("People / Households"), "unit"), (T("Total Number People/HH Targeted"), "target_value"), (T("Total Number Of People/HH Reache"), "value"), ], multiple=False, ), (T("Activity Status"), "status_id"), "comments", ) filter_widgets = [ S3OptionsFilter("event.event_type_id"), S3OptionsFilter( "event__link.event_id" ), # @ToDo: Filter this list dynamically based on Event Type S3OptionsFilter("sector_activity.sector_id"), S3LocationFilter( "location_id", # These levels are for SHARE/LK levels=("L2", "L3", "L4"), ), S3OptionsFilter( "status_id", cols=4, label=T("Status"), ), ] s3db.configure( tablename, crud_form=crud_form, filter_widgets=filter_widgets, list_fields=[ (T("Disaster"), "event__link.event_id"), (T("Agency"), "agency.organisation_id"), (T("Implementing Partner"), "partner.organisation_id"), (T("Donor"), "donor.organisation_id"), (T("District"), "location_id$L1"), (T("DS Division"), "location_id$L2"), (T("GN Division"), "location_id$L3"), (T("Sector"), "sector_activity.sector_id"), (T("Relief Items/Activity"), "name"), (T("Modality"), "modality.value"), (T("Number of Items/Kits/Activities"), "number.value"), (T("Activity Date (Planned/Start Date)"), "date"), (T("Activity Date (Completion Date)"), "end_date"), (T("People / Households"), "activity_data.unit"), (T("Total Number People/HH Targeted"), "activity_data.target_value"), (T("Total Number Of People/HH Reached"), "activity_data.value"), (T("Activity Status"), "status_id"), "comments", ], )
def customise_org_organisation_resource(r, tablename): s3db = current.s3db tablename = "org_organisation" # Custom Components for Verified s3db.add_components( tablename, org_organisation_tag=( # Request Number { "name": "req_number", "joinby": "organisation_id", "filterby": { "tag": "req_number", }, "multiple": False, }, # Vision { "name": "vision", "joinby": "organisation_id", "filterby": { "tag": "vision", }, "multiple": False, }, ), ) from s3 import S3SQLCustomForm, S3SQLInlineComponent, S3SQLInlineLink, s3_comments_widget # Individual settings for specific tag components components_get = r.resource.components.get vision = components_get("vision") vision.table.value.widget = s3_comments_widget crud_form = S3SQLCustomForm( "name", "acronym", S3SQLInlineLink( "organisation_type", field="organisation_type_id", # Default 10 options just triggers which adds unnecessary complexity to a commonly-used form & commonly an early one (create Org when registering) filter=False, label=T("Type"), multiple=False, widget="multiselect", ), S3SQLInlineLink( "sector", columns=4, field="sector_id", label=T("Sectors"), ), #S3SQLInlineLink("service", # columns = 4, # field = "service_id", # label = T("Services"), # ), "country", "phone", "website", "logo", (T("About"), "comments"), S3SQLInlineComponent( "vision", label=T("Vision"), fields=[("", "value")], multiple=False, ), S3SQLInlineComponent( "req_number", label=T("Request Number"), fields=[("", "value")], multiple=False, ), ) s3db.configure( tablename, crud_form=crud_form, )
def customise_project_project_resource(r, tablename): s3db = current.s3db table = s3db.project_project # Make project description mandatory field = table.description from gluon import IS_NOT_EMPTY field.requires = IS_NOT_EMPTY( error_message=T("Enter a project description"), ) if r.interactive: # Custom filter widgets LEAD_ROLE = settings.get_project_organisation_lead_role() org_label = settings.get_project_organisation_roles()[LEAD_ROLE] from s3 import S3DateFilter, \ S3LocationFilter, \ S3OptionsFilter, \ S3TextFilter filter_widgets = [ S3TextFilter( [ "name", "description", ], label=T("Search"), comment=T("Search for a Project by name or description."), ), S3LocationFilter("location.location_id", ), S3OptionsFilter( "sector_project.sector_id", label=T("Sector"), location_filter=True, none=True, ), S3OptionsFilter( "hazard_project.hazard_id", label=T("Hazard"), help_field=s3db.project_hazard_help_fields, cols=4, hidden=True, ), S3OptionsFilter( "status_id", label=T("Status"), cols=4, hidden=True, ), S3DateFilter( "start_date", hidden=True, ), S3DateFilter( "end_date", hidden=True, ), S3OptionsFilter( "organisation_id", label=org_label, hidden=True, ), ] # Custom CRUD form from s3 import S3SQLCustomForm, \ S3SQLInlineComponent, \ S3SQLInlineLink crud_form = S3SQLCustomForm( "organisation_id", "name", "description", "status_id", "start_date", "end_date", "budget", "currency", S3SQLInlineLink( "hazard", label=T("Hazards"), field="hazard_id", help_field=s3db.project_hazard_help_fields, cols=4, translate=True, ), S3SQLInlineLink( "sector", label=T("Sectors"), field="sector_id", cols=4, translate=True, ), "objectives", "human_resource_id", S3SQLInlineComponent( "document", fields=[ (T("Title"), "name"), "file", ], filterby={ "field": "file", "options": "", "invert": True, }, label=T("Files"), name="file", ), S3SQLInlineComponent( "document", fields=[ (T("Title"), "name"), "url", ], filterby={ "field": "url", "options": None, "invert": True, }, label=T("Links"), name="url", ), "comments", ) s3db.configure( "project_project", crud_form=crud_form, filter_widgets=filter_widgets, ) # Custom list fields list_fields = [ "name", "location.location_id", "organisation_id", (T("Sectors"), "sector_project.sector_id"), (T("Hazards"), "hazard_project.hazard_id"), "status_id", "start_date", "end_date", ] s3db.configure( "project_project", list_fields=list_fields, )
def customise_org_organisation_resource(r, tablename): s3db = current.s3db # Use comments field for org description table = s3db.org_organisation field = table.comments from gluon import DIV field.comment = DIV( _class="tooltip", _title="%s|%s" % (T("About"), T("Describe the organisation, e.g. mission, history and other relevant details" ))) if not current.auth.is_logged_in(): field = table.logo field.readable = field.writable = False # User can create records since we need this during registration, # but we don't want to let the user do this from the list view s3db.configure( "org_organisation", listadd=False, ) # Custom filters to match the information provided from s3 import S3LocationFilter, \ S3OptionsFilter, \ S3TextFilter, \ s3_get_filter_opts filter_widgets = [ S3TextFilter( [ "name", "acronym", #"website", #"comments", ], label=T("Search"), comment= T("Search by organization name or acronym. You can use * as wildcard." ), ), S3OptionsFilter( "organisation_organisation_type.organisation_type_id", label=T("Type"), ), S3OptionsFilter( "service_location.service_location_service.service_id", options=s3_get_filter_opts( "org_service", translate=True, ), ), S3OptionsFilter( "sector_organisation.sector_id", options=s3_get_filter_opts( "org_sector", translate=True, ), hidden=True, ), ] # CRUD Form from s3 import S3SQLCustomForm, \ S3SQLInlineComponent, \ S3SQLInlineLink, \ S3SQLVerticalSubFormLayout multitype = settings.get_org_organisation_types_multiple() crud_form = S3SQLCustomForm( "name", "acronym", S3SQLInlineLink( "organisation_type", field="organisation_type_id", filter=False, label=T("Type"), multiple=multitype, ), "country", S3SQLInlineLink( "sector", cols=3, label=T("Sectors"), field="sector_id", #required = True, ), (T("About"), "comments"), "website", S3SQLInlineComponent( "contact", name="email", label=T("Email"), #multiple = False, fields=[ ("", "value"), ], filterby=[ { "field": "contact_method", "options": "EMAIL", }, ], ), S3SQLInlineComponent( "facility", label=T("Main Office"), fields=[ "name", "phone1", "phone2", #"email", "location_id", ], layout=S3SQLVerticalSubFormLayout, filterby={ "field": "main_facility", "options": True, }, multiple=False, ), S3SQLInlineComponent( "document", fields=[ (T("Title"), "name"), "file", ], filterby={ "field": "file", "options": "", "invert": True, }, label=T("Files"), name="file", ), S3SQLInlineComponent( "document", fields=[ (T("Title"), "name"), "url", ], filterby={ "field": "url", "options": None, "invert": True, }, label=T("Links"), name="url", ), ) s3db.configure( "org_organisation", filter_widgets=filter_widgets, crud_form=crud_form, )
def customise_project_activity_resource(r, tablename): s3db = current.s3db if r.tablename == "project_project": # crud_form needs modifying to filter sectors by project's from s3 import S3SQLCustomForm, S3SQLInlineComponent, S3SQLInlineLink # Limit Sectors to those for the Project table = s3db.project_sector_project query = (table.project_id == r.id) & \ (table.deleted == False) rows = current.db(query).select(table.sector_id) sector_ids = [row.sector_id for row in rows] crud_form = S3SQLCustomForm( "name", "status_id", S3SQLInlineLink( "sector", field="sector_id", label=T("Sectors"), filterby="id", options=sector_ids, widget="groupedopts", ), S3SQLInlineLink( "activity_type", field="activity_type_id", label=T("Activity Types"), widget="groupedopts", ), "location_id", "date", "end_date", S3SQLInlineComponent( "distribution", fields=[ "parameter_id", "value", (T("Intended Impact"), "comments"), ], label=T("Distributed Supplies"), ), "person_id", "comments", ) s3db.configure( tablename, crud_form=crud_form, ) list_fields = s3db.get_config(tablename, "list_fields") list_fields.insert( 3, (T("Distributions"), "distribution.parameter_id")) # Done automatically from settings now #list_fields.insert(2, (T("Sectors"), "sector_activity.sector_id")) #list_fields.insert(3, (T("Activity Types"), "activity_activity_type.activity_type_id")) elif r.tablename == "project_activity": # Modify list_fields for desired Report format list_fields = [ ("CSO", "project_id$organisation_id"), (T("Activity"), "name"), (T("Intended Impact"), "distribution.comments"), (T("Location"), "location_id"), ] s3db.configure( tablename, deletable=False, editable=False, insertable=False, list_fields=list_fields, )
def prep(r): # Call standard prep result = standard_prep(r) if callable(standard_prep) else True s3db = current.s3db auth = current.auth #settings = current.deployment_settings # Add invite-method for ORG_GROUP_ADMIN role from .helpers import rlpptm_InviteUserOrg s3db.set_method( "org", "organisation", method="invite", action=rlpptm_InviteUserOrg, ) resource = r.resource get_vars = r.get_vars mine = get_vars.get("mine") if mine == "1": # Filter to managed orgs managed_orgs = auth.get_managed_orgs() if managed_orgs is True: query = None elif managed_orgs is None: query = FS("id") == None else: query = FS("pe_id").belongs(managed_orgs) if query: resource.add_filter(query) else: # Filter by org_group_membership org_group_id = get_vars.get("g") if org_group_id: if isinstance(org_group_id, list): query = FS("group.id").belongs(org_group_id) else: query = FS("group.id") == org_group_id resource.add_filter(query) if not r.component: if r.interactive: from s3 import S3SQLCustomForm, \ S3SQLInlineComponent, \ S3SQLInlineLink crud_fields = [ "name", "acronym", # TODO Activate after correct type prepop #S3SQLInlineLink( # "organisation_type", # field = "organisation_type_id", # search = False, # label = T("Type"), # multiple = settings.get_org_organisation_types_multiple(), # widget = "multiselect", # ), #"country", S3SQLInlineComponent( "contact", fields=[("", "value")], filterby={ "field": "contact_method", "options": "EMAIL", }, label=T("Email"), multiple=False, name="email", ), "phone", #"website", #"year", "logo", "comments", ] if auth.s3_has_role("ORG_GROUP_ADMIN"): crud_fields.insert( 0, S3SQLInlineLink( "group", field="group_id", label=T("Organisation Group"), multiple=False, )) r.resource.configure( crud_form=S3SQLCustomForm(*crud_fields), ) return result