14.2.60. camcops_server.cc_modules.cc_html

camcops_server/cc_modules/cc_html.py


Copyright (C) 2012-2019 Rudolf Cardinal (rudolf@pobox.com).

This file is part of CamCOPS.

CamCOPS is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

CamCOPS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with CamCOPS. If not, see <http://www.gnu.org/licenses/>.


Basic HTML creation functions.

camcops_server.cc_modules.cc_html.answer(x: Any, default: str = '?', default_for_blank_strings: bool = False, formatter_answer: Callable[str, str] = <function bold_webify>, formatter_blank: Callable[str, str] = <function italic>) → str[source]

Formats answer in bold, or the default value if None.

Avoid the word “None” for the default, e.g. “Score indicating likelihood of abuse: None”… may be misleading! Prefer “?” instead.

camcops_server.cc_modules.cc_html.bold(x: str) → str[source]

Applies HTML bold.

camcops_server.cc_modules.cc_html.bold_webify(x: str) → str[source]

Webifies the string, then makes it bold.

camcops_server.cc_modules.cc_html.div(content: str, div_class: str = '') → str[source]

Make simple HTML div.

camcops_server.cc_modules.cc_html.get_correct_incorrect_none(x: Any) → Union[str, NoneType][source]

Returns None if x is None, “Correct” if it’s truthy, or “Incorrect” if it’s falsy.

camcops_server.cc_modules.cc_html.get_data_url(mimetype: str, data: Union[bytes, memoryview]) → str[source]

Takes data (in binary format) and returns a data URL as per RFC 2397 (https://tools.ietf.org/html/rfc2397), such as:

data:MIMETYPE;base64,B64_ENCODED_DATA
camcops_server.cc_modules.cc_html.get_embedded_img_tag(mimetype: str, data: Union[bytes, memoryview]) → str[source]

Takes a binary image and its MIME type, and produces an HTML tag of the form:

<img src="DATA_URL">
camcops_server.cc_modules.cc_html.get_present_absent(req: CamcopsRequest, x: Any) → str[source]

‘Present’ if x else ‘Absent’

camcops_server.cc_modules.cc_html.get_present_absent_none(req: CamcopsRequest, x: Any) → Union[str, NoneType][source]

Returns ‘Present’ for True, ‘Absent’ for False, or None for None.

camcops_server.cc_modules.cc_html.get_present_absent_unknown(req: CamcopsRequest, x: str) → str[source]

Returns ‘Present’ for True, ‘Absent’ for False, or ‘?’ for None.

camcops_server.cc_modules.cc_html.get_ternary(x: Any, value_true: Any = True, value_false: Any = False, value_none: Any = None) → Any[source]

Returns value_none if x is None, value_true if it’s truthy, or value_false if it’s falsy.

camcops_server.cc_modules.cc_html.get_true_false(req: CamcopsRequest, x: Any) → str[source]

‘True’ if x else ‘False’

camcops_server.cc_modules.cc_html.get_true_false_none(req: CamcopsRequest, x: Any) → Union[str, NoneType][source]

Returns ‘True’ for True, ‘False’ for False, or None for None.

camcops_server.cc_modules.cc_html.get_true_false_unknown(req: CamcopsRequest, x: Any) → str[source]

Returns ‘True’ for True, ‘False’ for False, or ‘?’ for None.

camcops_server.cc_modules.cc_html.get_yes_no(req: CamcopsRequest, x: Any) → str[source]

‘Yes’ if x else ‘No’

camcops_server.cc_modules.cc_html.get_yes_no_none(req: CamcopsRequest, x: Any) → Union[str, NoneType][source]

Returns ‘Yes’ for True, ‘No’ for False, or None for None.

camcops_server.cc_modules.cc_html.get_yes_no_unknown(req: CamcopsRequest, x: Any) → str[source]

Returns ‘Yes’ for True, ‘No’ for False, or ‘?’ for None.

camcops_server.cc_modules.cc_html.heading_spanning_two_columns(s: str) → str[source]

HTML table heading row spanning 2 columns.

camcops_server.cc_modules.cc_html.identity(x: Any) → Any[source]

Returns argument unchanged.

camcops_server.cc_modules.cc_html.italic(x: str) → str[source]

Applies HTML italic.

camcops_server.cc_modules.cc_html.sub(x: str) → str[source]

Applies HTML subscript.

camcops_server.cc_modules.cc_html.subheading_spanning_four_columns(s: str, th_not_td: bool = False) → str[source]

HTML table subheading row spanning 4 columns.

camcops_server.cc_modules.cc_html.subheading_spanning_three_columns(s: str, th_not_td: bool = False) → str[source]

HTML table subheading row spanning 3 columns.

camcops_server.cc_modules.cc_html.subheading_spanning_two_columns(s: str, th_not_td: bool = False) → str[source]

HTML table subheading row spanning 2 columns.

camcops_server.cc_modules.cc_html.sup(x: str) → str[source]

Applies HTML superscript.

camcops_server.cc_modules.cc_html.table(content: str, table_class: str = '') → str[source]

Make simple HTML table.

camcops_server.cc_modules.cc_html.table_row(columns: List[str], classes: List[str] = None, colspans: List[str] = None, colwidths: List[str] = None, default: str = '', heading: bool = False) → str[source]

Make HTML table row.

Parameters:
  • columns – contents of HTML table columns
  • classes – optional CSS classes, one for each column
  • colspanscolspan values for each column
  • colwidthswidth values for each column
  • default – content to use if a column value is None
  • heading – use <th> rather than <td> for contents?
Returns:

the <tr>...</tr> string

camcops_server.cc_modules.cc_html.td(contents: Any, td_class: str = '', td_width: str = '') → str[source]

Make simple HTML table data <td>...</td> cell.

camcops_server.cc_modules.cc_html.th(contents: Any, th_class: str = '', th_width: str = '') → str[source]

Make simple HTML table header <th>...</th> cell.

camcops_server.cc_modules.cc_html.tr(*args, tr_class: str = '', literal: bool = False) → str[source]

Make simple HTML table data row.

Parameters:
  • *args – Set of columns data.
  • literal – Treat elements as literals with their own <td> ... </td>, rather than things to be encapsulated.
  • tr_class – table row class
camcops_server.cc_modules.cc_html.tr_qa(q: str, a: Any, default: str = '?', default_for_blank_strings: bool = False) → str[source]

Make HTML two-column data row (<tr>...</tr>), with the right-hand column formatted as an answer.

camcops_server.cc_modules.cc_html.tr_span_col(x: str, cols: int = 2, tr_class: str = '', td_class: str = '', th_not_td: bool = False) → str[source]

HTML table data row spanning several columns.

Parameters:
  • x – Data.
  • cols – Number of columns to span.
  • tr_class – CSS class to apply to tr.
  • td_class – CSS class to apply to td.
  • th_not_td – make it a th, not a td.