def custom_prep(r): # Call standard prep if callable(standard_prep): result = standard_prep(r) if not result: return False s3.crud_strings["project_member"] = Storage(msg_record_created=None, msg_record_deleted=None) if r.interactive: is_deployment = False stable = s3db.project_sector_project otable = s3db.org_sector # Edit the end_date label of "project_milestone" table milestone_table = s3db.project_milestone milestone_table.date.label = T("End Date") # Check if current record is Deployment if r.id: # Viewing details of project_project record query = (stable.project_id == r.id) & \ (otable.id == stable.sector_id) rows = db(query).select(otable.name) for row in rows: if row.name == "Deployment": is_deployment = True request_sector = r.get_vars.get("sector.name") # Viewing Projects/Deployments Page if request_sector and "Deployment" in request_sector: is_deployment = True if is_deployment: # Change the CRUD strings and labels s3db[tablename].name.label = T("Deployment Name") s3.crud_strings[tablename] = Storage( label_create=T("Create Deployment"), title_display=T("Deployment Details"), title_list=T("Deployments"), title_update=T("Edit Deployment"), title_report=T("Deployment Report"), 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 updated"), msg_record_deleted=T("Deployment deleted"), msg_list_empty=T("No Deployments currently registered")) # Set the method for deployment page s3db.set_method(r.controller, r.function, method="deployment", action=deployment_page) if not r.component: # Viewing project/deployment's Basic Details from s3.s3forms import S3SQLCustomForm, S3SQLInlineComponent, S3SQLInlineLink if is_deployment: # Bring back to the Deployments page if record deleted delete_next = URL(c="project", f="project", vars={"sector.name": "None,Deployment"}) # Get sector_id for Deployment row = db(otable.name == "Deployment").select( otable.id, limitby=(0, 1)).first() # Modify the CRUD form crud_form = S3SQLCustomForm( "organisation_id", "name", "sector_project.sector_id", "description", "status_id", "start_date", "end_date", "calendar", S3SQLInlineComponent("location", label=T("Countries"), fields=["location_id"], orderby="location_id$name", render_list=True), S3SQLInlineLink( "hazard", label=T("Hazard"), field="hazard_id", ), S3SQLInlineLink( "theme", label=T("Type"), field="theme_id", ), "human_resource_id", # Files S3SQLInlineComponent("document", name="file", label=T("Files"), fields=[(T("Type"), "name"), "file"], filterby=dict( field="file", options="", invert=True, )), # Links S3SQLInlineComponent("document", name="url", label=T("Links"), fields=[(T("Type"), "name"), "url"], filterby=dict( field="url", options=None, invert=True, )), S3SQLInlineComponent("image", fields=["", "file"], filterby=dict( field="file", options="", invert=True, )), "comments", ) location_id = s3db.project_location.location_id # Limit to just Countries location_id.requires = s3db.gis_country_requires # Use dropdown, not AC location_id.widget = None else: # Bring back to the Projects page if record deleted delete_next = URL(c="project", f="project", vars={"sector.name": "None,Project"}) # Get sector_id for Project row = db(otable.name == "Project").select( otable.id, limitby=(0, 1)).first() # Modify the CRUD form crud_form = S3SQLCustomForm( "organisation_id", "name", "sector_project.sector_id", "description", "status_id", "start_date", "end_date", "calendar", "human_resource_id", "comments", ) # Set the default sector try: stable.sector_id.default = row.id except: current.log.error("Pre-Populate", "Sectors not prepopulated") # Remove Add Sector button stable.sector_id.comment = None s3db.configure( tablename, crud_form=crud_form, delete_next=delete_next, ) return True
def customise_project_task_resource(r, tablename): """ Customise project_task resource - CRUD Form Runs after controller customisation But runs before prep """ s3db = current.s3db db = current.db T = current.T crud_strings = current.response.s3.crud_strings crud_strings["project_member"] = Storage(msg_record_created=None, msg_record_deleted=None) if r.interactive: trimmed_task = False get_vars = r.get_vars ADD_TASK = T("Create Task") # Check if it is a bug report if get_vars.get("bug"): tagname = "bug" trimmed_task = True ADD_TASK = T("Report a Bug") # Check if it is a feature request elif get_vars.get("featureRequest"): tagname = "feature request" trimmed_task = True ADD_TASK = T("Request a Feature") # Check if it is a support task elif get_vars.get("support"): tagname = "support" trimmed_task = True ADD_TASK = T("Request Support") from s3.s3forms import S3SQLCustomForm, S3SQLInlineLink, S3SQLInlineComponent if trimmed_task: # Show a trimmed view of creating task crud_fields = [ "name", "description", S3SQLInlineLink( "tag", label=T("Tag"), field="tag_id", ), "priority", "status", S3SQLInlineComponent( "document", label=T("Attachment"), fields=["", "file"], ), ] crud_strings["project_task"]["label_create"] = ADD_TASK tagtable = s3db.project_tag query = (tagtable.deleted != True) & \ (tagtable.name == tagname) row = db(query).select(tagtable.id, limitby=(0, 1)).first() # Set the tag try: s3db.project_task_tag.tag_id.default = row.id except: current.log.error("Pre-Populate", "Tags not prepopulated") else: # Show all fields for creating the task crud_fields = [ S3SQLInlineComponent( "task_milestone", label=T("Milestone"), fields=[("", "milestone_id")], multiple=False, ), "name", "description", S3SQLInlineComponent( "task_tag", label=T("Tags"), fields=[("", "tag_id")], ), "priority", "status", S3SQLInlineComponent( "member", label=T("Members"), fields=[("", "person_id")], readonly=True, ), "source", "date_due", "time_estimated", S3SQLInlineComponent( "document", label=T("Attachment"), fields=["", "file"], ), S3SQLInlineComponent( "time", label=T("Time Log"), fields=["date", "person_id", "hours", "comments"], orderby="date"), "time_actual", ] if r.tablename == "project_task": # Add the project field if it is not under the component crud_fields.insert( 0, S3SQLInlineComponent( "task_project", label=T("Project"), fields=[("", "project_id")], multiple=False, )) crud_form = S3SQLCustomForm(*crud_fields) s3db.configure( tablename, crud_form=crud_form, )
def custom_prep(r): # Call standard prep if callable(standard_prep): result = standard_prep(r) else: result = True if r.interactive or r.representation == "aadata": list_fields = [ "id", "name", "acronym", "organisation_organisation_type.organisation_type_id", (T("Services"), "service.name"), (T("Neighborhoods Served"), "location.name"), ] s3db.configure("org_organisation", list_fields=list_fields) if r.interactive: from s3.s3forms import S3SQLCustomForm, S3SQLInlineLink, S3SQLInlineComponent, S3SQLInlineComponentMultiSelectWidget s3db.pr_address.comments.label = "" s3db.pr_contact.value.label = "" s3db.doc_document.url.label = "" crud_form = S3SQLCustomForm( "name", "acronym", S3SQLInlineLink( "organisation_type", field="organisation_type_id", label=T("Type"), multiple=False, #widget = "hierarchy", ), S3SQLInlineComponentMultiSelectWidget( "service", label=T("Services"), field="service_id", cols=4, ), S3SQLInlineComponentMultiSelectWidget( "group", label=T("Network"), field="group_id", cols=3, ), S3SQLInlineComponent( "address", label=T("Address"), multiple=False, # This is just Text - put into the Comments box for now # Ultimately should go into location_id$addr_street fields=["comments"], ), #S3SQLInlineComponentCheckbox( S3SQLInlineComponentMultiSelectWidget( "location", label=T("Neighborhoods Served"), field="location_id", filterby=dict(field="level", options="L4"), # @ToDo: GroupedCheckbox Widget or Hierarchical MultiSelectWidget cols=5, ), "phone", S3SQLInlineComponent("contact", name="phone2", label=T("Phone2"), multiple=False, fields=["value"], filterby=dict(field="contact_method", options="WORK_PHONE")), S3SQLInlineComponent("contact", name="email", label=T("Email"), multiple=False, fields=["value"], filterby=dict(field="contact_method", options="EMAIL")), "website", S3SQLInlineComponent("contact", name="rss", label=T("RSS"), multiple=False, fields=["value"], filterby=dict(field="contact_method", options="RSS")), S3SQLInlineComponent("document", name="iCal", label="iCAL", multiple=False, fields=[ "url", ], filterby=dict(field="name", options="iCal")), S3SQLInlineComponent("document", name="data", label=T("Data"), multiple=False, fields=[ "url", ], filterby=dict(field="name", options="Data")), 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", ) from s3.s3filter import S3LocationFilter, S3OptionsFilter, S3TextFilter filter_widgets = [ S3TextFilter( ["name", "acronym"], label=T("Name"), _class="filter-search", ), S3OptionsFilter( "group_membership.group_id", label=T("Network"), represent="%(name)s", #hidden = True, ), S3LocationFilter( "organisation_location.location_id", label=T("Neighborhood"), levels=["L3", "L4"], #hidden = True, ), S3OptionsFilter( "service_organisation.service_id", label=T("Service"), #hidden = True, ), S3OptionsFilter( "organisation_organisation_type.organisation_type_id", label=T("Type"), #hidden = True, ), ] s3db.configure( "org_organisation", crud_form=crud_form, filter_widgets=filter_widgets, ) return result