-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathtext.py
More file actions
executable file
·39 lines (32 loc) · 1.72 KB
/
text.py
File metadata and controls
executable file
·39 lines (32 loc) · 1.72 KB
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
from typing import Optional
from regula.documentreader.webclient.ext.models.text_field import TextField
from regula.documentreader.webclient.gen.models import LCID, Text as GenText
class Text(GenText):
def get_field(self, field_type: int, lcid: int = None) -> Optional[TextField]:
result = None
for field in self.field_list:
if field.field_type == field_type:
if lcid is not None and field.lcid == lcid:
return TextField.from_json(field.to_json())
elif lcid is None and field.lcid == LCID.LATIN:
return TextField.from_json(field.to_json())
elif lcid is None and result is None:
result = field
return TextField.from_json(result.to_json())
def get_field_value(self, field_type: int, lcid: int = None) -> Optional[str]:
field = self.get_field(field_type, lcid)
return field.value if field else None
def get_field_by_name(self, field_name: str, lcid: int = None) -> Optional[TextField]:
result = None
for field in self.field_list:
if field.field_name == field_name:
if lcid is not None and field.lcid == lcid:
return TextField.from_json(field.to_json())
elif lcid is None and field.lcid == LCID.LATIN:
return TextField.from_json(field.to_json())
elif lcid is None and result is None:
result = field
return TextField.from_json(result.to_json())
def get_field_value_by_name(self, field_name: str, lcid: int = None) -> Optional[str]:
field = self.get_field_by_name(field_name, lcid)
return field.value if field else None