def custom_prep(r): # Call standard prep if callable(standard_prep): result = standard_prep(r) if not result: return False s3db = current.s3db # Hack to provide additional languages for L10n location names # without activating them in the GUI l10n_languages = dict(settings.L10n.languages) l10n_languages["ky"] = "Kyrgyz" l10n_languages["ru"] = "Russian" l10n_languages["hy"] = "Armenian" l10n_languages["az"] = "Azerbaijani" l10n_languages["ka"] = "Georgian" l10n_languages["kk"] = "Kazakh" l10n_languages["tg"] = "Tajik" l10n_languages["tk"] = "Turkmen" l10n_languages["uk"] = "Ukraine" l10n_languages["uz"] = "Uzbek" from s3 import IS_ISO639_2_LANGUAGE_CODE s3db.gis_location_name.language.requires = IS_ISO639_2_LANGUAGE_CODE( select=l10n_languages) if r.interactive or r.representation == "aadata": if r.vars.get("location.level__ne"): s3.crud_strings["gis_location"] = Storage( title_list=T("Administrative Areas"), ) else: s3.crud_strings["gis_location"] = Storage( #label_create = T("Record Disaster"), #title_display = T("Disaster Details"), title_list=T("Locations")) # Remove level column & filter list_fields = s3db.get_config("gis_location", "list_fields") list_fields.remove("level") filter_widgets = s3db.get_config("gis_location", "filter_widgets") # NB Fragile: dependent on filters defined in gis/location controller filter_widgets.pop(1) if r.method != "import": table = s3db.gis_location # Custom filtered components for custom list_fields s3db.add_components( "gis_location", gis_location_name={ "name": "name_ru", "joinby": "location_id", "filterby": "language", "filterfor": ("ru", ), }, gis_location_tag=( { "name": "pcode", "joinby": "location_id", "filterby": "tag", "filterfor": ("PCode", ), }, { "name": "lat_lon_source", "joinby": "location_id", "filterby": "tag", "filterfor": ("LatLon Source", ), }, { "name": "lat_lon_date", "joinby": "location_id", "filterby": "tag", "filterfor": ("LatLon Date", ), }, ), ) from s3 import S3MultiSelectWidget, S3SQLCustomForm, S3SQLInlineComponent table.parent.widget = S3MultiSelectWidget(multiple=False) crud_form = S3SQLCustomForm( "name", #"name_ru.name_l10n", S3SQLInlineComponent( "name_ru", label=T("Russian Name"), multiple=False, fields=[("", "name_l10n")], ), "level", S3SQLInlineComponent( "pcode", label=T("PCode"), multiple=False, fields=[("", "value")], ), S3SQLInlineComponent( "lat_lon_source", label=T("Lat/Lon Source"), multiple=False, fields=[("", "value")], ), S3SQLInlineComponent( "lat_lon_date", label=T("Lat/Lon Date"), multiple=False, fields=[("", "value")], ), #"pcode.value", "parent", ) NONE = current.messages["NONE"] levels = current.gis.get_location_hierarchy() table.level.represent = lambda l: levels[l] if l else NONE #field = table.inherited #field.label = T("Mapped?") #field.represent = lambda v: T("No") if v else T("Yes") filter_widgets = s3db.get_config("gis_location", "filter_widgets") # Remove L2 & L3 filters # NB Fragile: dependent on filters defined in gis/location controller filter_widgets.pop() filter_widgets.pop() s3db.configure( "gis_location", crud_form=crud_form, filter_widgets=filter_widgets, list_fields=[ "name", # @ToDo: Investigate whether we can support this style & hence not need to define custom components #(T("Russian Name"), "name.name_l10n?location_name.language=ru"), #("PCode", "tag.value?location_tag.tag=PCode"), (T("Russian Name"), "name_ru.name_l10n"), "level", ("PCode", "pcode.value"), "L0", "L1", "L2", "inherited", ]) return True
def customise_deploy_mission_controller(**attr): db = current.db s3db = current.s3db s3 = current.response.s3 MEMBER = T("Member") from gluon.html import DIV hr_comment = \ DIV(_class="tooltip", _title="%s|%s" % (MEMBER, current.messages.AUTOCOMPLETE_HELP)) table = s3db.deploy_mission table.code.label = T("Appeal Code") table.event_type_id.label = T("Disaster Type") table.organisation_id.readable = table.organisation_id.writable = False # Restrict Location to just Countries from s3 import S3Represent, S3MultiSelectWidget field = table.location_id field.label = current.messages.COUNTRY field.requires = s3db.gis_country_requires field.widget = S3MultiSelectWidget(multiple=False) field.represent = S3Represent(lookup="gis_location", translate=True) rtable = s3db.deploy_response rtable.human_resource_id.label = MEMBER rtable.human_resource_id.comment = hr_comment _customise_assignment_fields() # Report options report_fact = [(T("Number of Missions"), "count(id)"), (T("Number of Countries"), "count(location_id)"), (T("Number of Disaster Types"), "count(event_type_id)"), (T("Number of Responses"), "sum(response_count)"), (T("Number of Deployments"), "sum(hrquantity)"), ] report_axis = ["code", "location_id", "event_type_id", "status", ] report_options = Storage(rows = report_axis, cols = report_axis, fact = report_fact, defaults = Storage(rows = "location_id", cols = "event_type_id", fact = "sum(hrquantity)", totals = True, ), ) s3db.configure("deploy_mission", report_options = report_options, ) # CRUD Strings s3.crud_strings["deploy_assignment"] = Storage( label_create = T("New Deployment"), title_display = T("Deployment Details"), title_list = T("Deployments"), title_update = T("Edit Deployment Details"), title_upload = T("Import Deployments"), label_list_button = T("List Deployments"), label_delete_button = T("Delete Deployment"), msg_record_created = T("Deployment added"), msg_record_modified = T("Deployment Details updated"), msg_record_deleted = T("Deployment deleted"), msg_list_empty = T("No Deployments currently registered")) # Custom prep standard_prep = s3.prep def custom_prep(r): # Call standard prep if callable(standard_prep): result = standard_prep(r) else: result = True if r.interactive and not current.auth.s3_has_role("RDRT_ADMIN"): # Limit write-access to these fields to RDRT Admins: fields = ("name", "event_type_id", "location_id", "code", "status", ) table = r.resource.table for f in fields: if f in table: table[f].writable = False #if not r.component and r.method == "create": # # Org is always IFRC # otable = s3db.org_organisation # query = (otable.name == "International Federation of Red Cross and Red Crescent Societies") # organisation = db(query).select(otable.id, # limitby = (0, 1), # ).first() # if organisation: # r.table.organisation_id.default = organisation.id return result s3.prep = custom_prep return attr
def formfields(): """ Generate the form fields for the registration form @returns: a tuple (formfields, required_fields, subheadings) - formfields = list of form fields - required_fields = list of field names of required fields - subheadings = list of tuples (position, heading) to insert into the form """ T = current.T request = current.request db = current.db s3db = current.s3db auth = current.auth auth_settings = auth.settings auth_messages = auth.messages utable = auth_settings.table_user passfield = auth_settings.password_field occupation_type_represent = S3Represent( lookup="pr_occupation_type", multiple=True, ) # Instantiate Consent Tracker consent = s3db.auth_Consent(processing_types=["SHARE"]) # Last name is required utable.last_name.requires = IS_NOT_EMPTY( error_message=T("input required")) ltable = s3db.gis_location # Form fields formfields = [utable.first_name, utable.last_name, s3_date("date_of_birth", label = T("Date of Birth"), future = -156, empty = False, ), # -------------------------------------------- utable.email, utable[passfield], # Password Verification Field Field("password_two", "password", label = auth_messages.verify_password, requires = IS_EXPR("value==%s" % \ repr(request.vars.get(passfield)), error_message = auth_messages.mismatched_password, ), comment = DIV(_class = "tooltip", _title = "%s|%s" % (auth_messages.verify_password, T("Enter the same password again"), ), ), ), # -------------------------------------------- Field("home_phone", label = T("Phone"), requires = IS_EMPTY_OR(IS_PHONE_NUMBER_MULTI()), ), Field("mobile_phone", label = T("Mobile Phone"), requires = IS_EMPTY_OR(IS_PHONE_NUMBER_SINGLE()), ), #Field("office_phone", # label = T("Office Phone"), # requires = IS_EMPTY_OR(IS_PHONE_NUMBER_MULTI()), # ), # -------------------------------------------- s3db.gis_location_id("location_id", widget = S3LocationSelector( show_address = False, show_postcode = False, show_map = False, ), ), Field("addr_street", label = ltable.addr_street.label, ), Field("addr_postcode", label = ltable.addr_postcode.label, requires = IS_NOT_EMPTY(), ), # -------------------------------------------- Field("occupation_type_ids", "list:reference pr_occupation_type", label = T("Occupation Type"), requires = IS_EMPTY_OR(IS_ONE_OF(db, "pr_occupation_type.id", occupation_type_represent, multiple=True, )), represent = occupation_type_represent, widget = S3MultiSelectWidget(), comment = DIV(_class = "tooltip", _title = "%s|%s" % (T("Occupation Type"), T("Select all that apply"), ), ), ), Field("occupation", label = T("Occupation / Speciality"), comment = DIV(_class = "tooltip", _title = "%s|%s" % (T("Occupation / Speciality"), T("Specify your exact job designation"), ), ), ), # -------------------------------------------- s3_date("start_date", label = T("Available from"), default = "now", past = 0, set_min = "#auth_user_start_date", ), s3_date("end_date", label = T("Available until"), past = 0, set_max = "#auth_user_start_date", ), Field("hours_per_week", "integer", label = T("Hours per Week"), requires = IS_EMPTY_OR(IS_INT_IN_RANGE(1, 60)), comment = DIV(_class = "tooltip", _title = "%s|%s" % (T("Hours per Week"), T("Specify the maximum number of weekly hours"), ), ), ), Field("schedule", "text", label = T("Availability Schedule"), widget = s3_comments_widget, comment = DIV(_class = "tooltip", _title = "%s|%s" % (T("Availability Schedule"), T("Specify days/hours like: Monday 10-12; Tuesday 10-12 and 14-19; Friday 13-15"), ), ), ), s3db.hrm_multi_skill_id( label = T("Skills / Resources"), widget = S3GroupedOptionsWidget(cols = 1, size = None, help_field = "comments", ), ), # -------------------------------------------- Field("comments", "text", label = T("Comments"), widget = s3_comments_widget, ), # -------------------------------------------- Field("consent", label = T("Consent"), widget = consent.widget, ), ] # Required fields required_fields = [ "first_name", "last_name", ] # Subheadings subheadings = ( (3, T("User Account")), (6, T("Contact Information")), (8, T("Address")), (11, T("Occupation")), (13, T("Availability and Resources")), (18, T("Comments")), (19, T("Privacy")), ) return formfields, required_fields, subheadings
def customise_gis_location_controller(**attr): """ Customise org_organisation resource - CRD Strings - List Fields - Form - Filter - Report Runs after controller customisation But runs before prep """ s3db = current.s3db # Custom filtered components for custom list_fields s3db.add_components("gis_location", gis_location_name = {"name": "name_ru", "joinby": "location_id", "filterby": "language", "filterfor": ("ru",), }, gis_location_tag = {"name": "pcode", "joinby": "location_id", "filterby": "tag", "filterfor": ("PCode",), }, gis_location_lat_lon_source = {"name": "lat_lon_source", "joinby": "location_id", "filterby": "tag", "filterfor": ("LatLon Source",), }, gis_location_lat_lon_date = {"name": "lat_lon_date", "joinby": "location_id", "filterby": "tag", "filterfor": ("LatLon Date",), }, ) from s3 import S3MultiSelectWidget, S3SQLCustomForm, S3SQLInlineComponent s3db.gis_location.parent.widget = S3MultiSelectWidget(multiple=False) crud_form = S3SQLCustomForm("name", #"name_ru.name_l10n", S3SQLInlineComponent( "name_ru", label = T("Russian Name"), multiple = False, fields = [("", "name_l10n")], ), "level", S3SQLInlineComponent( "pcode", label = T("PCode"), multiple = False, fields = [("", "value")], ), S3SQLInlineComponent( "lat_lon_source", label = T("Lat/Lon Source"), multiple = False, fields = [("", "value")], ), S3SQLInlineComponent( "lat_lon_date", label = T("Lat/Lon Date"), multiple = False, fields = [("", "value")], ), #"pcode.value", "parent", ) s3db.gis_location.level.represent = lambda level: current.gis.get_location_hierarchy(level) if level else current.messages.NONE field = s3db.gis_location.inherited field.label = T("Mapped?") field.represent = lambda inherited: T("No") if inherited else T("Yes") filter_widgets = s3db.get_config("gis_location", "filter_widgets") # Remove L2 & L3 filters # NB Fragile: dependent on filters defined in gis/location controller filter_widgets.pop() filter_widgets.pop() s3db.configure("gis_location", crud_form = crud_form, filter_widgets = filter_widgets, list_fields = ["name", # @ToDo: Investigate whether we can support this style & hence not need to define custom components #(T("Russian Name"), "name.name_l10n?location_name.language=ru"), #("PCode", "tag.value?location_tag.tag=PCode"), (T("Russian Name"), "name_ru.name_l10n"), "level", ("PCode", "pcode.value"), "L0", "L1", "L2", "inherited", ] ) return attr