Kirill Simonov avatar Kirill Simonov committed de8a882

Fixed :csv and :html formatters to properly handle the `as` decorator.

Comments (0)

Files changed (4)

src/htsql/fmt/html.py

         yield "</table>\n"
 
     def serialize_content(self, product):
-        caption = entitle(product.profile.segment.binding.base)
-        headers = [entitle(element)
-                   for element in product.profile.segment.elements]
-        width = len(product.profile.segment.elements)
-        domains = [element.domain
-                   for element in product.profile.segment.elements]
+        segment = product.profile.binding.segment
+        caption = entitle(segment.base)
+        headers = [entitle(element) for element in segment.elements]
+        width = len(segment.elements)
+        domains = [element.domain for element in segment.elements]
         tool = HTMLFormatter(self)
         formats = [Format(self, domain, tool) for domain in domains]
         colspan = " colspan=\"%s\"" % width if width > 1 else ""

src/htsql/fmt/spreadsheet.py

 from .format import Format, Formatter, Renderer
 from ..domain import (Domain, BooleanDomain, NumberDomain, FloatDomain,
                       StringDomain, EnumDomain, DateDomain)
+from .entitle import entitle
 import csv
 import cStringIO
 
     def generate_body(self, product):
         if not product:
             return
-        titles = [str(element.syntax)
+        titles = [entitle(element.binding)
                   for element in product.profile.segment.elements]
         domains = [element.domain
                    for element in product.profile.segment.elements]

test/input/pgsql.yaml

     - uri: /school
       headers:
         Accept: text/html
+    # Test how `as` interact with various formatters.
+    - uri: /(school as 'School Record'){code as 'Code name',
+                                        name as 'Long name'}
+      headers:
+        Accept: text/csv
+    - uri: /(school as 'School Record'){code as 'Code name',
+                                        name as 'Long name'}
+      headers:
+        Accept: text/plain
+    - uri: /(school as 'School Record'){code as 'Code name',
+                                        name as 'Long name'}
+      headers:
+        Accept: text/html
 

test/output/pgsql.yaml

         </table>
         </body>
         </html>
+    - uri: /(school as 'School Record'){code as 'Code name', name as 'Long name'}
+      status: 200 OK
+      headers:
+      - [Content-Type, text/csv; charset=UTF-8]
+      body: "Code name,Long name\r\nart,School of Art and Design\r\nbus,School of
+        Business\r\nedu,College of Education\r\negn,School of Engineering\r\nla,\"School
+        of Arts, Letters, and the Humanities\"\r\nmart,School of Modern Art\r\nmus,Musical
+        School\r\nns,School of Natural Sciences\r\nsc,School of Continuing Studies\r\n"
+    - uri: /(school as 'School Record'){code as 'Code name', name as 'Long name'}
+      status: 200 OK
+      headers:
+      - [Content-Type, text/plain; charset=UTF-8]
+      body: |2
+         | School Record                                |
+        -+----------------------------------------------+-
+         | Code name | Long name                        |
+        -+-----------+----------------------------------+-
+         | art       | School of Art and Design         |
+         | bus       | School of Business               |
+         | edu       | College of Education             |
+         | egn       | School of Engineering            |
+         | la        | School of Arts, Letters, and the |
+         :           : Humanities                       :
+         | mart      | School of Modern Art             |
+         | mus       | Musical School                   |
+         | ns        | School of Natural Sciences       |
+         | sc        | School of Continuing Studies     |
+                                                 (9 rows)
+
+         ----
+         /(school as 'School Record'){code as 'Code name',name as 'Long name'}
+         SELECT "school"."code", "school"."name" FROM "ad"."school" AS "school" ORDER BY 1 ASC
+    - uri: /(school as 'School Record'){code as 'Code name', name as 'Long name'}
+      status: 200 OK
+      headers:
+      - [Content-Type, text/html; charset=UTF-8]
+      body: |
+        <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+        <html>
+        <head>
+        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+        <title>/(school as 'School Record'){code as 'Code name',name as 'Long name'}</title>
+        <style type="text/css">
+        body { font-family: sans-serif; font-size: 90%; color: #515151; background: #ffffff }
+        a:link, a:visited { color: #1f4884; text-decoration: none }
+        a:hover { text-decoration: underline }
+        table { border-collapse: collapse; margin: 0.5em auto; width: 100% }
+        table, tr { border-style: solid; border-width: 0 }
+        td, th { padding: 0.2em 0.5em; vertical-align: top; text-align: left }
+        div.tab { position: relative; left: -1px; margin-right: 60%; padding: 0.2em 0.5em; background: #ffffff; border-style: solid; border-width: 5px 1px 0; border-top-left-radius: 10px; border-top-right-radius: 10px; -moz-border-radius-topleft: 10px; -moz-border-radius-topright: 10px; -webkit-border-top-left-radius: 10px; -webkit-border-top-right-radius: 10px }
+        table.page { border: 0; padding: 1em; width: auto }
+        tr.content { padding: 1em 1em 0.5em }
+        tr.footer { padding: 0 1em 1em; text-align: left; font-style: italic }
+        table.chart .number { text-align: right }
+        tr.caption { font-size: 105%; background: transparent }
+        tr.caption th { padding: 0 }
+        div.tab { border-color: #6f9ad3 #c3c3c3 }
+        tr.header { background: #dae3ea; border-color: #c3c3c3; border-width: 1px 1px 0 }
+        tr.odd { background: #ffffff; border-color: #c3c3c3; border-width: 0 1px }
+        tr.even { background: #f2f2f2; border-color: #c3c3c3; border-width: 0 1px }
+        tr.odd:hover, tr.even:hover { background: #ffe3bd }
+        tr.total { background: transparent;border-color: #c3c3c3; border-width: 1px 0 0 }
+        tr.total td { text-align: right; font-size: 75%; font-style: italic; padding: 0.3em 0.5em 0 }
+        table.void { text-align: center; border-color: #c3c3c3; border-width: 1px 0 }
+        </style>
+        </head>
+        <body>
+        <table class="page" summary="/(school as 'School Record'){code as 'Code name',name as 'Long name'}">
+        <tr>
+        <td class="content">
+        <table class="chart" summary="School Record">
+        <tr class="caption"><th colspan="2"><div class="tab">School Record</div></th></tr>
+        <tr class="header"><th>Code name</th><th>Long name</th></tr>
+        <tr class="odd"><td>art</td><td>School of Art and Design</td></tr>
+        <tr class="even"><td>bus</td><td>School of Business</td></tr>
+        <tr class="odd"><td>edu</td><td>College of Education</td></tr>
+        <tr class="even"><td>egn</td><td>School of Engineering</td></tr>
+        <tr class="odd"><td>la</td><td>School of Arts, Letters, and the Humanities</td></tr>
+        <tr class="even"><td>mart</td><td>School of Modern Art</td></tr>
+        <tr class="odd"><td>mus</td><td>Musical School</td></tr>
+        <tr class="even"><td>ns</td><td>School of Natural Sciences</td></tr>
+        <tr class="odd"><td>sc</td><td>School of Continuing Studies</td></tr>
+        <tr class="total"><td colspan="2">(9 rows)</td></tr></table></td>
+        </tr>
+        <tr><td class="footer">/(school as 'School Record'){code as 'Code name',name as 'Long name'}</td></tr>
+        </table>
+        </body>
+        </html>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.