19.1.42. camcops_server.cc_modules.cc_string


Copyright (C) 2012-2018 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/>.


camcops_server.cc_modules.cc_string.all_extra_strings_as_dicts(config_filename: str) → Dict[str, Dict[str, str]][source]

Returns strings from the all the extra XML string files. Caching is now via a proper cache.

  • Returns a dictionary whose keys are tasknames,
    • and whose values are each a dictionary
      • whose keys are string names
      • and whose values are strings.

For example, result['phq9']['q5'] == "5. Poor appetite or overeating". There is also a top-level dictionary with the key APPSTRING_TASKNAME.

The extra string files look like this:

<?xml version="1.0" encoding="UTF-8"?>
<resources>
    <task name="TASK_1">
        <string name="NAME_1">VALUE</string>
        <string name="NAME_2">VALUE WITH\nNEWLINE</string>
        <!-- ... -->
    </task>
    <!-- ... -->
</resources>
camcops_server.cc_modules.cc_string.text_contents(e: xml.etree.ElementTree.Element, plain: bool = False, strip: bool = True) → str[source]

A normal string looks like

<string name="stringname">words words words</string>

and we extract its contents (“words words words”) with

e.text

However, for this:

<string name="stringname">words <b>bold words</b> words</string>

we want to extract “words <b>bold words</b> words” and that’s a little trickier.