Skip to content

Commit

Permalink
Link Tables
Browse files Browse the repository at this point in the history
  • Loading branch information
gauravmittal1995 committed Feb 10, 2015
1 parent 552f933 commit 6040ffc
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 39 deletions.
41 changes: 38 additions & 3 deletions modules/s3db/msg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
112 changes: 76 additions & 36 deletions modules/s3db/req.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class S3RequestModel(S3Model):
"req_prep",
"req_tabs",
"req_priority_opts",
"req_req_event",
)

def model(self):
Expand Down Expand Up @@ -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: \
Expand Down Expand Up @@ -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?)
Expand All @@ -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",
Expand All @@ -525,6 +547,7 @@ def model(self):
totals = True,
)
),
crud_form = crud_form,
)

# Custom Methods
Expand All @@ -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.*)
Expand Down

0 comments on commit 6040ffc

Please sign in to comment.