Coverage for cc_modules/cc_ipuse.py: 93%
29 statements
« prev ^ index » next coverage.py v6.5.0, created at 2022-11-08 23:14 +0000
« prev ^ index » next coverage.py v6.5.0, created at 2022-11-08 23:14 +0000
1#!/usr/bin/env python
3"""
4camcops_server/cc_modules/cc_ipuse.py
6===============================================================================
8 Copyright (C) 2012, University of Cambridge, Department of Psychiatry.
9 Created by Rudolf Cardinal (rnc1001@cam.ac.uk).
11 This file is part of CamCOPS.
13 CamCOPS is free software: you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
18 CamCOPS is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with CamCOPS. If not, see <https://www.gnu.org/licenses/>.
26===============================================================================
28IP Use flags that determine the contexts in which CamCOPS is to be used (and
29hence the tasks that will be permitted).
31"""
33from sqlalchemy.sql.schema import Column
34from sqlalchemy.sql.sqltypes import Boolean, Integer
36from cardinal_pythonlib.reprfunc import auto_repr, auto_str
38from camcops_server.cc_modules.cc_sqlalchemy import Base
41_DEFAULT_APPLICABILITY = False
44class IpContexts(object):
45 """
46 String constants, used as form parameter names etc.
47 """
49 CLINICAL = "clinical"
50 COMMERCIAL = "commercial"
51 EDUCATIONAL = "educational"
52 RESEARCH = "research"
55class IpUse(Base):
56 __tablename__ = "_security_ip_use"
58 CONTEXTS = (
59 IpContexts.CLINICAL,
60 IpContexts.COMMERCIAL,
61 IpContexts.EDUCATIONAL,
62 IpContexts.RESEARCH,
63 )
64 _DEFAULT = False
66 id = Column(
67 "id",
68 Integer,
69 primary_key=True,
70 autoincrement=True,
71 index=True,
72 comment="IP Use ID",
73 )
75 clinical = Column(
76 "clinical",
77 Boolean,
78 nullable=False,
79 default=_DEFAULT,
80 comment="Applicable to a clinical context",
81 )
82 commercial = Column(
83 "commercial",
84 Boolean,
85 nullable=False,
86 default=_DEFAULT,
87 comment="Applicable to a commercial context",
88 )
89 educational = Column(
90 "educational",
91 Boolean,
92 nullable=False,
93 default=_DEFAULT,
94 comment="Applicable to an educational context",
95 )
96 research = Column(
97 "research",
98 Boolean,
99 nullable=False,
100 default=_DEFAULT,
101 comment="Applicable to a research context",
102 )
104 def __init__(
105 self,
106 clinical: bool = _DEFAULT_APPLICABILITY,
107 commercial: bool = _DEFAULT_APPLICABILITY,
108 educational: bool = _DEFAULT_APPLICABILITY,
109 research: bool = _DEFAULT_APPLICABILITY,
110 ) -> None:
111 """
112 We provide __init__() so we can create a default object without
113 touching the database.
114 """
115 self.clinical = clinical
116 self.commercial = commercial
117 self.educational = educational
118 self.research = research
120 def __repr__(self) -> str:
121 return auto_repr(self)
123 def __str__(self) -> str:
124 return auto_str(self)