-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtranslator.py
210 lines (161 loc) · 6.18 KB
/
translator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
from uuid import uuid4
from libres.db.models.timestamp import TimestampMixin
from sqlalchemy import Column, Text, Enum, Date, Integer, Boolean, Float
from sqlalchemy.orm import backref, relationship
from onegov.core.orm import Base
from onegov.core.orm.mixins import ContentMixin, dict_property, meta_property
from onegov.core.orm.types import UUID
from onegov.file import AssociatedFiles
from onegov.gis import CoordinatesMixin
from onegov.search import ORMSearchable
from onegov.translator_directory.constants import ADMISSIONS, GENDERS
from onegov.translator_directory.models.certificate import (
certificate_association_table
)
from onegov.translator_directory.models.language import (
mother_tongue_association_table, spoken_association_table,
written_association_table, monitoring_association_table
)
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from collections.abc import Sequence
from onegov.user import User
from .certificate import LanguageCertificate
from .language import Language
# TODO rename to ts (text search)
class ESMixin(ORMSearchable):
es_properties = {
'last_name': {'type': 'text'},
'first_name': {'type': 'text'},
'email': {'type': 'text'}
}
es_public = False
@property
def lead(self):
return ', '.join({
*(la.name for la in self.written_languages or []),
*(la.name for la in self.spoken_languages or [])
})
class Translator(Base, TimestampMixin, AssociatedFiles, ContentMixin,
CoordinatesMixin, ESMixin):
__tablename__ = 'translators'
id = Column(UUID, primary_key=True, default=uuid4)
state = Column(
Enum(
'proposed',
'published',
name='translator_state'
),
nullable=False,
default='published'
)
first_name = Column(Text, nullable=False)
last_name = Column(Text, nullable=False)
# Personal-Nr.
pers_id = Column(Integer)
# Zulassung / admission
admission = Column(
Enum(*ADMISSIONS, name='admission_state'),
nullable=False,
default='uncertified'
)
# Quellensteuer
withholding_tax = Column(Boolean, default=False)
# Selbständig
self_employed = Column(Boolean, default=False)
gender = Column(Enum(*GENDERS, name='gender'))
date_of_birth = Column(Date)
nationality = Column(Text)
# Fields concerning address
address = Column(Text)
zip_code = Column(Text)
city = Column(Text)
# distance calculated from address to a fix point via api, im km
drive_distance = Column(Float(precision=2))
# AHV-Nr.
social_sec_number = Column(Text)
# Bank information
bank_name = Column(Text)
bank_address = Column(Text)
account_owner = Column(Text)
iban = Column(Text)
email = Column(Text, unique=True)
# the user account related to this translator
user: 'relationship[User]' = relationship(
'User',
primaryjoin='foreign(Translator.email) == User.username',
uselist=False,
backref=backref('translator', uselist=False, passive_deletes='all')
)
tel_mobile = Column(Text,)
tel_private = Column(Text)
tel_office = Column(Text)
availability = Column(Text)
confirm_name_reveal = Column(Boolean, default=False)
# The translator applies to be in the directory and gets a decision
date_of_application = Column(Date)
date_of_decision = Column(Date)
# Language Information
mother_tongues: 'relationship[list[Language]]' = relationship(
"Language",
secondary=mother_tongue_association_table,
backref='mother_tongues'
)
# Arbeitssprache - Wort
spoken_languages: 'relationship[list[Language]]' = relationship(
"Language", secondary=spoken_association_table, backref="speakers"
)
# Arbeitssprache - Schrift
written_languages: 'relationship[list[Language]]' = relationship(
"Language", secondary=written_association_table, backref='writers')
# Arbeitssprache - Kommunikationsüberwachung
monitoring_languages: 'relationship[list[Language]]' = relationship(
"Language", secondary=monitoring_association_table, backref='monitors')
# Nachweis der Voraussetzungen
proof_of_preconditions = Column(Text)
# Referenzen Behörden
agency_references = Column(Text)
# Ausbildung Dolmetscher
education_as_interpreter = Column(Boolean, default=False, nullable=False)
certificates: 'relationship[list[LanguageCertificate]]' = relationship(
'LanguageCertificate',
secondary=certificate_association_table,
backref='owners')
# Bemerkungen
comments = Column(Text)
# field for hiding to users except admins
for_admins_only = Column(Boolean, default=False, nullable=False)
# the below might never be used, but we import it if customer wants them
profession = Column(Text)
occupation = Column(Text)
other_certificates = Column(Text)
# Besondere Hinweise Einsatzmöglichkeiten
operation_comments = Column(Text)
# List of types of interpreting the interpreter can do
expertise_interpreting_types: 'dict_property[Sequence[str]]'
expertise_interpreting_types = meta_property(default=tuple)
# List of types of professional guilds
expertise_professional_guilds: 'dict_property[Sequence[str]]'
expertise_professional_guilds = meta_property(default=tuple)
expertise_professional_guilds_other: 'dict_property[Sequence[str]]'
expertise_professional_guilds_other = meta_property(default=tuple)
@property
def search_score(self):
return 4
@property
def expertise_professional_guilds_all(self):
return (
tuple(self.expertise_professional_guilds or ())
+ tuple(self.expertise_professional_guilds_other or ())
)
# If entry was imported, for the form and the expertise fields
imported = Column(Boolean, default=False, nullable=False)
@property
def title(self):
return f'{self.last_name}, {self.first_name}'
@property
def full_name(self):
return f'{self.first_name} {self.last_name}'
@property
def unique_categories(self):
return sorted({f.note for f in self.files})