Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def cap_generate_bulletin_form(r, **attr):
- """
- Generate a PDF for a bullentin form
- """
- from s3.s3export import S3Exporter
- exporter = S3Exporter().pdf
- return exporter(r.resource,
- request=r,
- pdf_header = cap_bulletin_pdf_header,
- pdf_callback = cap_bulletin_pdf_callback,
- pdf_footer = cap_bulletin_pdf_footer,
- pdf_header_padding = 12,
- pdf_title="Warning Bulletin",
- pdf_hide_comments=True,
- **attr
- )
- # =============================================================================
- def cap_bulletin_pdf_header(r):
- record = r.record
- if record:
- T = current.T
- header = DIV(TABLE(TR(TH(IMG(_src="\%s\static\\themes\SAMBRO\img\\ndrrmc.png" % current.request.application),
- _display="inline-block"
- ),
- TH(DIV(
- P("<i>REPUBLIC OF THE PHILIPPINES</i>",
- _style= "font-family: Times New Roman, font-size: 23px",
- ),
- P(T("NATIONAL DISASTER RISK REDUCTION AND MANAGEMENT COUNCIL"),
- _style="display:inline-block",
- ),
- P("<br/>",
- _style="display:inline-block",
- ),
- P(T("National Disaster Risk Reduction and Management Center, Camp Aguinaldo, Quezon City, Philippines"),
- _style="display: inline-block",
- ),
- )),
- ),
- ),
- )
- return header
- return None
- # =============================================================================
- def cap_bulletin_pdf_callback(r):
- record = r.record
- if record:
- def get_formatted_value(value):
- if isinstance(value, list):
- nvalue = []
- for value_ in value:
- if value_:
- nvalue.append(value_)
- if len(nvalue):
- nvalue = ", ".join(nvalue)
- return nvalue
- else:
- return None
- else:
- return value
- T = current.T
- record = r.record
- resource = r.resource
- table = current.s3db.cap_alert
- fields = ["info.headline", "info.instruction"]
- # Extract the data
- data = resource.select(fields,
- raw_data=True)
- # Single row as we are filtering for particular alert_id
- row = data["rows"][0]
- instructions = row["cap_info.instruction"]
- if not isinstance(instructions, list):
- instructions = [instructions]
- instruction = ()
- for instruction_ in instructions:
- instruction += (instruction_,)
- body = DIV(P("NDRRMC UPDATE", _style="text-decoration: underline"),
- P("Severe Weather Bulletin No. %(id)s (%(msg_type)s) re %(event_type)s" % \
- {"id": record.id,
- "msg_type": record.msg_type,
- "event_type": table.event_type_id.represent(record.event_type_id)
- },
- ),
- P("Releasing Officer:"),
- BR(),
- BR(),
- P("..............................................."),
- P("Executive Director"),
- P("DATE: %s" % table.sent.represent(record.sent)),
- HR(),
- P("Source: PAGASA-DOST"),
- P("I. SITUATIONAL OVERVIEW"),
- P("%s" % get_formatted_value(row["cap_info.headline"])),
- TABLE(TR(TH("Location of the Center: (as of %s)" % ("10:00 am")),
- TH("Area Description"),
- ),
- TR(TH("Coordinates:"),
- TH("Polygon"),
- ),
- TR(TH("Strength:"),
- TH("Description"),
- ),
- TR(TH("Movement:"),
- TH("DESCRIPTION"),
- ),
- TR(TH("Forecast Positions/Outlook:"),
- TH("Description"))
- ),
- P("II. ACTION/S TAKEN"),
- TAG[""](instruction),
- )
- return body
- return None
- # =============================================================================
- def cap_bulletin_pdf_footer(r):
- record = r.record
- if record:
- T = current.T
- footer = DIV(HR(),
- P("Telefax: NDRRMC Opcen (+632) 911-1406; 912-2665; 912-5668; NDRRMC Secretariat (+632) 912-0441; 912-5947;"),
- P("Office of the Administrator, Office of Civil Defense (+632) 912-2424"),
- P("Email"))
- return footer
- return None
Advertisement
Add Comment
Please, Sign In to add comment