From 6040ffc07b7f1cad74f08d696ae393d9196765e0 Mon Sep 17 00:00:00 2001 From: Gaurav Mittal Date: Wed, 11 Feb 2015 02:59:03 +0530 Subject: [PATCH] Link Tables --- modules/s3db/msg.py | 41 ++++++++++++++-- modules/s3db/req.py | 112 ++++++++++++++++++++++++++++++-------------- 2 files changed, 114 insertions(+), 39 deletions(-) diff --git a/modules/s3db/msg.py b/modules/s3db/msg.py index 85a58ec373..e80121e5fd 100644 --- a/modules/s3db/msg.py +++ b/modules/s3db/msg.py @@ -910,6 +910,7 @@ class S3ParsingModel(S3Model): "msg_parser_disable", "msg_parser_enable_interactive", "msg_parser_disable_interactive", + "msg_keyword_incident_type", ) def model(self): @@ -1001,12 +1002,46 @@ def model(self): tablename = "msg_keyword" define_table(tablename, Field("keyword", - label = T("Keyword"), + label=T("Keyword"), ), - # @ToDo: Move this to a link table - self.event_incident_type_id(), *s3_meta_fields()) + self.add_components(tablename, + msg_keyword_incident_type={"link": "msg_keyword_incident_type", + "joinby": "msg_keyword_id", + "key": "incident_type_id", + } + ) + + crud_form = S3SQLCustomForm("keyword", + S3SQLInlineLink("keyword_incident_type", + label=T("Incident"), + field="incident_type_id")) + self.configure(tablename, + list_fields=["keyword", + "keyword_incident_type.incident_type_id", + ], + crud_form=crud_form) + + # --------------------------------------------------------------------- + # Link Table: Message Keyword <> Event Incident Type + # + tablename = "msg_keyword_incident_type" + + msg_keyword_represent = S3Represent(lookup="msg_keyword") + + define_table(tablename, + Field("msg_keyword_id", self.msg_keyword, + represent=msg_keyword_represent, + requires=IS_ONE_OF(current.db, "msg_keyword.id", + msg_keyword_represent, + sort=True + ) + ), + self.event_incident_type_id(), + *s3_meta_fields() + ) + # --------------------------------------------------------------------- # Senders for Message Parsing # - whitelist / blacklist / prioritise diff --git a/modules/s3db/req.py b/modules/s3db/req.py index fa9841387a..2a7eba4455 100644 --- a/modules/s3db/req.py +++ b/modules/s3db/req.py @@ -72,6 +72,7 @@ class S3RequestModel(S3Model): "req_prep", "req_tabs", "req_priority_opts", + "req_req_event", ) def model(self): @@ -178,13 +179,6 @@ def model(self): tablename = "req_req" self.define_table(tablename, super_link("doc_id", "doc_entity"), - # @ToDo: Replace with Link Table - self.event_event_id( - default = session.s3.event, - ondelete = "SET NULL", - readable = False, - writable = False, - ), Field("type", "integer", label = T("Request Type"), represent = lambda opt: \ @@ -474,7 +468,7 @@ def model(self): "date_required", "site_id", "requester_id", - #"event_id", + #"req_event.event_id", # @ToDo: Vary by deployment_setting (easy) # @ToDo: Allow a single column to support different components based on type # @ToDo: Include Qty too (Computed VF in component?) @@ -499,6 +493,34 @@ def model(self): if use_commit: list_fields.append((T("Committed By"), "commit.site_id")) + crud_form = S3SQLCustomForm(S3SQLInlineLink( + "req_event", + label=False, + field = "event_id", + ), + "type", + "date", + "priority", + "site_id", + "purpose", + "is_template", + "date_required", + "date_required_until", + "requester_id", + "assigned_to_id", + "approved_by_id", + "request_for_id", + "transport_req", + "security_req", + "date_recv", + "recv_by_id", + "commit_status", + "transit_status", + "fulfil_status", + "closed", + "comments", + ) + self.configure(tablename, context = {"event": "event_id", "location": "site_id$location_id", @@ -525,6 +547,7 @@ def model(self): totals = True, ) ), + crud_form = crud_form, ) # Custom Methods @@ -546,34 +569,51 @@ def model(self): action=self.req_form) # Components - add_components(tablename, - # Documents - req_document = "req_id", - # Requested Items - req_req_item = {"joinby": "req_id", - "multiple": multiple_req_items, - }, - # Requested Skills - req_req_skill = {"joinby": "req_id", - "multiple": multiple_req_items, - }, - # Commitment - req_commit = "req_id", - # Item Categories - supply_item_category = {"link": "req_req_item_category", - "joinby": "req_id", - "key": "item_category_id", - }, - - **{# Scheduler Jobs (for recurring requests) - S3Task.TASK_TABLENAME: {"name": "job", - "joinby": "req_id", - "link": "req_job", - "key": "scheduler_task_id", - "actuate": "replace", - }, - } - ) + self.add_components(tablename, + # Documents + req_document = "req_id", + # Requested Items + req_req_item = {"joinby": "req_id", + "multiple": multiple_req_items, + }, + # Requested Skills + req_req_skill = {"joinby": "req_id", + "multiple": multiple_req_items, + }, + # Request Event + req_req_event = {"joinby": "req_id", + "link": "req_req_event", + "key": "event_id", + }, + # Commitment + req_commit = "req_id", + # Item Categories + supply_item_category = {"link": "req_req_item_category", + "joinby": "req_id", + "key": "item_category_id", + }, + **{# Scheduler Jobs (for recurring requests) + S3Task.TASK_TABLENAME: {"name": "job", + "joinby": "req_id", + "link": "req_job", + "key": "scheduler_task_id", + "actuate": "replace", + }, + } + ) + + # --------------------------------------------------------------------- + # Link Table: Request <> Event + tablename = "req_req_event" + self.define_table(tablename, + req_id(empty=False), + self.event_event_id(default = session.s3.event, + ondelete = "SET NULL", + readable = False, + writable = False, + ), + *s3_meta_fields() + ) # --------------------------------------------------------------------- # Pass names back to global scope (s3.*)