Guest User

Untitled

a guest
Jul 19th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.45 KB | None | 0 0
  1. def cap_generate_bulletin_form(r, **attr):
  2.     """
  3.        Generate a PDF for a bullentin form
  4.    """
  5.  
  6.     from s3.s3export import S3Exporter
  7.     exporter = S3Exporter().pdf
  8.     return exporter(r.resource,
  9.                     request=r,
  10.                     pdf_header = cap_bulletin_pdf_header,
  11.                     pdf_callback = cap_bulletin_pdf_callback,
  12.                     pdf_footer = cap_bulletin_pdf_footer,
  13.                     pdf_header_padding = 12,
  14.                     pdf_title="Warning Bulletin",
  15.                     pdf_hide_comments=True,
  16.                     **attr
  17.                     )
  18.  
  19. # =============================================================================
  20. def cap_bulletin_pdf_header(r):
  21.  
  22.     record = r.record
  23.     if record:
  24.         T = current.T
  25.         header = DIV(TABLE(TR(TH(IMG(_src="\%s\static\\themes\SAMBRO\img\\ndrrmc.png" % current.request.application),
  26.                                  _display="inline-block"
  27.                                  ),
  28.                               TH(DIV(
  29.                                  P("<i>REPUBLIC OF THE PHILIPPINES</i>",
  30.                                    _style= "font-family: Times New Roman, font-size: 23px",
  31.                                    ),
  32.                                  P(T("NATIONAL DISASTER RISK REDUCTION AND MANAGEMENT COUNCIL"),
  33.                                    _style="display:inline-block",
  34.                                    ),
  35.                                  P("<br/>",
  36.                                    _style="display:inline-block",
  37.                                    ),
  38.                                  P(T("National Disaster Risk Reduction and Management Center, Camp Aguinaldo, Quezon City, Philippines"),
  39.                                    _style="display: inline-block",
  40.                                    ),
  41.                                  )),
  42.                               ),
  43.                            ),
  44.                      )
  45.  
  46.         return header
  47.     return None
  48.  
  49. # =============================================================================
  50. def cap_bulletin_pdf_callback(r):
  51.  
  52.     record = r.record
  53.     if record:
  54.         def get_formatted_value(value):
  55.             if isinstance(value, list):
  56.                 nvalue = []
  57.                 for value_ in value:
  58.                     if value_:
  59.                         nvalue.append(value_)
  60.                 if len(nvalue):
  61.                     nvalue = ", ".join(nvalue)
  62.                     return nvalue
  63.                 else:
  64.                     return None
  65.             else:
  66.                 return value
  67.  
  68.         T = current.T
  69.         record = r.record
  70.         resource = r.resource
  71.  
  72.         table = current.s3db.cap_alert
  73.         fields = ["info.headline", "info.instruction"]
  74.         # Extract the data
  75.         data = resource.select(fields,
  76.                                raw_data=True)
  77.         # Single row as we are filtering for particular alert_id
  78.         row = data["rows"][0]
  79.  
  80.         instructions = row["cap_info.instruction"]
  81.         if not isinstance(instructions, list):
  82.             instructions = [instructions]
  83.  
  84.         instruction = ()
  85.         for instruction_ in instructions:
  86.             instruction += (instruction_,)
  87.  
  88.         body = DIV(P("NDRRMC UPDATE", _style="text-decoration: underline"),
  89.                    P("Severe Weather Bulletin No. %(id)s (%(msg_type)s) re %(event_type)s" % \
  90.                      {"id": record.id,
  91.                       "msg_type": record.msg_type,
  92.                       "event_type": table.event_type_id.represent(record.event_type_id)
  93.                       },
  94.                      ),
  95.                      P("Releasing Officer:"),
  96.                      BR(),
  97.                      BR(),
  98.                      P("..............................................."),
  99.                      P("Executive Director"),
  100.                      P("DATE: %s" % table.sent.represent(record.sent)),
  101.                      HR(),
  102.                      P("Source: PAGASA-DOST"),
  103.                      P("I. SITUATIONAL OVERVIEW"),
  104.                      P("%s" % get_formatted_value(row["cap_info.headline"])),
  105.                      TABLE(TR(TH("Location of the Center: (as of %s)" % ("10:00 am")),
  106.                               TH("Area Description"),
  107.                               ),
  108.                            TR(TH("Coordinates:"),
  109.                               TH("Polygon"),
  110.                               ),
  111.                            TR(TH("Strength:"),
  112.                               TH("Description"),
  113.                               ),
  114.                            TR(TH("Movement:"),
  115.                               TH("DESCRIPTION"),
  116.                               ),
  117.                            TR(TH("Forecast Positions/Outlook:"),
  118.                               TH("Description"))
  119.                            ),
  120.                    P("II. ACTION/S TAKEN"),
  121.                    TAG[""](instruction),
  122.                    )
  123.  
  124.         return body
  125.     return None
  126.  
  127. # =============================================================================
  128. def cap_bulletin_pdf_footer(r):
  129.  
  130.     record = r.record
  131.     if record:
  132.         T = current.T
  133.         footer = DIV(HR(),
  134.                      P("Telefax: NDRRMC Opcen (+632) 911-1406; 912-2665; 912-5668; NDRRMC Secretariat (+632) 912-0441; 912-5947;"),
  135.                      P("Office of the Administrator, Office of Civil Defense (+632) 912-2424"),
  136.                      P("Email"))
  137.         return footer
  138.     return None
Advertisement
Add Comment
Please, Sign In to add comment