def customise_event_incident_report_resource(r, tablename): s3db = current.s3db table = s3db.event_incident_report table.name.label = T("Description") # ImageCrop widget doesn't currently work within an Inline Form from gluon.validators import IS_IMAGE image_field = s3db.doc_image.file image_field.requires = IS_IMAGE() image_field.widget = None from s3 import S3SQLCustomForm, S3SQLInlineComponent crud_form = S3SQLCustomForm( S3SQLInlineComponent( "image", label=T("Photo"), fields=[ ("", "file"), ], ), "name", "location_id", ) list_fields = [ "location_id", "name", ] s3db.configure( "event_incident_report", crud_form=crud_form, list_fields=list_fields, )
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