Coverage for cc_modules/cc_ipuse.py : 93%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1#!/usr/bin/env python
3"""
4camcops_server/cc_modules/cc_ipuse.py
6===============================================================================
8 Copyright (C) 2012-2020 Rudolf Cardinal (rudolf@pobox.com).
10 This file is part of CamCOPS.
12 CamCOPS is free software: you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation, either version 3 of the License, or
15 (at your option) any later version.
17 CamCOPS is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with CamCOPS. If not, see <https://www.gnu.org/licenses/>.
25===============================================================================
27IP Use flags that determine the contexts in which CamCOPS is to be used (and
28hence the tasks that will be permitted).
30"""
32from sqlalchemy.sql.schema import Column
33from sqlalchemy.sql.sqltypes import Boolean, Integer
35from cardinal_pythonlib.reprfunc import auto_repr, auto_str
37from camcops_server.cc_modules.cc_sqlalchemy import Base
40_DEFAULT_APPLICABILITY = False
43class IpContexts(object):
44 """
45 String constants, used as form parameter names etc.
46 """
47 CLINICAL = "clinical"
48 COMMERCIAL = "commercial"
49 EDUCATIONAL = "educational"
50 RESEARCH = "research"
53class IpUse(Base):
54 __tablename__ = "_security_ip_use"
56 CONTEXTS = (
57 IpContexts.CLINICAL,
58 IpContexts.COMMERCIAL,
59 IpContexts.EDUCATIONAL,
60 IpContexts.RESEARCH,
61 )
62 _DEFAULT = False
64 id = Column(
65 "id", Integer,
66 primary_key=True,
67 autoincrement=True,
68 index=True,
69 comment="IP Use ID"
70 )
72 clinical = Column(
73 "clinical", Boolean,
74 nullable=False,
75 default=_DEFAULT,
76 comment="Applicable to a clinical context"
77 )
78 commercial = Column(
79 "commercial", Boolean,
80 nullable=False,
81 default=_DEFAULT,
82 comment="Applicable to a commercial context"
83 )
84 educational = Column(
85 "educational", Boolean,
86 nullable=False,
87 default=_DEFAULT,
88 comment="Applicable to an educational context"
89 )
90 research = Column(
91 "research", Boolean,
92 nullable=False,
93 default=_DEFAULT,
94 comment="Applicable to a research context"
95 )
97 def __init__(self,
98 clinical: bool = _DEFAULT_APPLICABILITY,
99 commercial: bool = _DEFAULT_APPLICABILITY,
100 educational: bool = _DEFAULT_APPLICABILITY,
101 research: bool = _DEFAULT_APPLICABILITY) -> None:
102 """
103 We provide __init__() so we can create a default object without
104 touching the database.
105 """
106 self.clinical = clinical
107 self.commercial = commercial
108 self.educational = educational
109 self.research = research
111 def __repr__(self) -> str:
112 return auto_repr(self)
114 def __str__(self) -> str:
115 return auto_str(self)