19.1.58. camcops_server.cc_modules.webview¶
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/>.
Quick tutorial on Pyramid views:
The configurator registers routes, and routes have URLs associated with them. Those URLs can be templatized, e.g. to accept numerical parameters. The configurator associates view callables (“views” for short) with routes, and one method for doing that is an automatic scan via Venusian for views decorated with @view_config().
All views take a Request object and return a Response or raise an exception that Pyramid will translate into a Response.
Having matched a route, Pyramid uses its “view lookup” process to choose one from potentially several views. For example, a single route might be associated with:
@view_config(route_name="myroute") def myroute_default(req: Request) -> Response: pass @view_config(route_name="myroute", method="POST") def myroute_post(req: Request) -> Response: pass
In this example, POST requests will go to the second; everything else will go to the first. Pyramid’s view lookup rule is essentially: if multiple views match, choose the one with the most specifiers.
Specifiers include:
route_name=ROUTENAME the route request_method="POST" requires HTTP GET, POST, etc. request_param="XXX" ... requires the presence of a GET/POST variable with this name in the request.params dictionary request_param="XXX=YYY" ... requires the presence of a GET/POST variable called XXX whose value is YYY, in the request.params dictionary match_param="XXX=YYY" .. requires the presence of this key/value pair in request.matchdict, which contains parameters from the URL
Getting parameters
request.params ... parameters from HTTP GET or POST, including both the query string (as in http://somewhere/path?key=value) and the body (e.g. POST). request.matchdict ... parameters from the URL, via URL dispatch; see https://docs.pylonsproject.org/projects/pyramid/en/latest/narr/urldispatch.html#urldispatch-chapter # noqa
Regarding rendering:
There might be some simplicity benefits from converting to a template system like Mako. On the downside, that would entail a bit more work; likely a minor performance hit (relative to plain Python string rendering); and a loss of type checking. The type checking is also why we prefer:
html = " ... {param_blah} ...".format(param_blah=PARAM.BLAH)
to
html = " ... {PARAM.BLAH} ...".format(PARAM=PARAM)
as in the first situation, PyCharm will check that “BLAH” is present in “PARAM”, and in the second it won’t. Automatic checking is worth a lot.
-
camcops_server.cc_modules.webview.
account_locked
(req: camcops_server.cc_modules.cc_request.CamcopsRequest, locked_until: pendulum.datetime.DateTime) → pyramid.response.Response[source]¶ HTML given when account locked out. Returned by login_view() only.
-
camcops_server.cc_modules.webview.
add_special_note
(req: camcops_server.cc_modules.cc_request.CamcopsRequest) → Dict[str, Any][source]¶ Add a special note to a task (after confirmation).
-
camcops_server.cc_modules.webview.
assert_may_edit_user
(req: camcops_server.cc_modules.cc_request.CamcopsRequest, user: camcops_server.cc_modules.cc_user.User) → None[source]¶ Checks that the requesting user (req.user) is allowed to edit the other user (user). Raises HTTPBadRequest otherwise.
-
camcops_server.cc_modules.webview.
bad_request
(req: camcops_server.cc_modules.cc_request.CamcopsRequest) → Dict[str, Any][source]¶ NOTE that this view only gets used from
raise HTTPBadRequest("message")
and not
return HTTPBadRequest("message")
… so always raise it.
-
camcops_server.cc_modules.webview.
change_other_password
(req: camcops_server.cc_modules.cc_request.CamcopsRequest) → pyramid.response.Response[source]¶ For administrators, to change another’s password.
-
camcops_server.cc_modules.webview.
choose_tracker_or_ctv
(req: camcops_server.cc_modules.cc_request.CamcopsRequest, as_ctv: bool) → Dict[str, Any][source]¶ HTML form for tracker selection.
-
camcops_server.cc_modules.webview.
crash
(req: camcops_server.cc_modules.cc_request.CamcopsRequest) → pyramid.response.Response[source]¶ Deliberately raises an exception.
-
camcops_server.cc_modules.webview.
delete_patient
(req: camcops_server.cc_modules.cc_request.CamcopsRequest) → pyramid.response.Response[source]¶ Completely delete all data from a patient (after confirmation), within a specific group.
-
camcops_server.cc_modules.webview.
developer_page
(req: camcops_server.cc_modules.cc_request.CamcopsRequest) → Dict[str, Any][source]¶ Shows developer menu.
-
camcops_server.cc_modules.webview.
erase_task
(req: camcops_server.cc_modules.cc_request.CamcopsRequest) → pyramid.response.Response[source]¶ Wipe all data from a task (after confirmation).
Leaves the task record as a placeholder.
-
camcops_server.cc_modules.webview.
forcibly_finalize
(req: camcops_server.cc_modules.cc_request.CamcopsRequest) → pyramid.response.Response[source]¶ Force-finalize all live (_era == ERA_NOW) records from a device. Available to group administrators if all those records are within their groups (otherwise, it’s a superuser operation).
This is a superuser permission, since we can’t guarantee to know what group the device relates to.
-
camcops_server.cc_modules.webview.
introspect
(req: camcops_server.cc_modules.cc_request.CamcopsRequest) → pyramid.response.Response[source]¶ Provide formatted source code.
-
camcops_server.cc_modules.webview.
login_failed
(req: camcops_server.cc_modules.cc_request.CamcopsRequest) → pyramid.response.Response[source]¶ HTML given after login failure. Returned by login_view() only.
-
camcops_server.cc_modules.webview.
logout
(req: camcops_server.cc_modules.cc_request.CamcopsRequest) → Dict[str, Any][source]¶ Logs a session out.
Main HTML menu.
-
camcops_server.cc_modules.webview.
offer_introspection
(req: camcops_server.cc_modules.cc_request.CamcopsRequest) → pyramid.response.Response[source]¶ Page to offer CamCOPS server source code.
-
camcops_server.cc_modules.webview.
offer_report
(req: camcops_server.cc_modules.cc_request.CamcopsRequest) → pyramid.response.Response[source]¶ Offer configuration options for a single report, or (following submission) redirect to serve that report
-
camcops_server.cc_modules.webview.
offer_sql_dump
(req: camcops_server.cc_modules.cc_request.CamcopsRequest) → pyramid.response.Response[source]¶ Form for SQL research dump selection.
-
camcops_server.cc_modules.webview.
offer_terms
(req: camcops_server.cc_modules.cc_request.CamcopsRequest) → pyramid.response.Response[source]¶ HTML offering terms/conditions and requesting acknowledgement.
-
camcops_server.cc_modules.webview.
offer_tsv_dump
(req: camcops_server.cc_modules.cc_request.CamcopsRequest) → pyramid.response.Response[source]¶ Form for basic research dump selection.
Offer a menu of reports.
-
camcops_server.cc_modules.webview.
serve_report
(req: camcops_server.cc_modules.cc_request.CamcopsRequest) → pyramid.response.Response[source]¶ Serve a configured report.
-
camcops_server.cc_modules.webview.
serve_task
(req: camcops_server.cc_modules.cc_request.CamcopsRequest) → pyramid.response.Response[source]¶ Serves an individual task.
-
camcops_server.cc_modules.webview.
simple_failure
(req: camcops_server.cc_modules.cc_request.CamcopsRequest, msg: str, extra_html: str = '') → pyramid.response.Response[source]¶ Simple failure message.
-
camcops_server.cc_modules.webview.
simple_success
(req: camcops_server.cc_modules.cc_request.CamcopsRequest, msg: str, extra_html: str = '') → pyramid.response.Response[source]¶ Simple success message.
-
camcops_server.cc_modules.webview.
static_bugfix_deform_missing_glyphs
(req: camcops_server.cc_modules.cc_request.CamcopsRequest) → pyramid.response.Response[source]¶ Hack for a missing-file bug in deform==2.0.4:
-
camcops_server.cc_modules.webview.
view_ddl
(req: camcops_server.cc_modules.cc_request.CamcopsRequest) → pyramid.response.Response[source]¶ Inspect table definitions with field comments.