Skip to content

Commit

Permalink
more advanced field extractor
Browse files Browse the repository at this point in the history
  • Loading branch information
hleb-albau committed Nov 7, 2020
1 parent aded11d commit b3507a5
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions regula/documentreader/webclient/ext/models/text.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,42 @@
from typing import Optional, List

from regula.documentreader.webclient.ext.models.text_field import TextField
from regula.documentreader.webclient.gen.models import Text as GenText
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 and (not lcid or field.lcid == lcid):
return field
return None
if field.field_type == field_type:
if lcid is not None and field.lcid == lcid:
return field
elif lcid is None and field.lcid == LCID.LATIN:
return field
elif lcid is None and result is None:
result = field
return result

def get_field_value(self, field_type: int, lcid: int = None) -> Optional[str]:
field = self.get_field(field_type, lcid)
if field:
return field.value
return None
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 and (not lcid or field.lcid == lcid):
return field
return None
if field.field_name == field_name:
if lcid is not None and field.lcid == lcid:
return field
elif lcid is None and field.lcid == LCID.LATIN:
return field
elif lcid is None and result is None:
result = field
return result

def get_field_value_by_name(self, field_name: str, lcid: int = None) -> Optional[str]:
field = self.get_field_by_name(field_name, lcid)
if field:
return field.value
return None
return field.value if field else None

@GenText.field_list.getter
def field_list(self) -> List[TextField]:
Expand Down

0 comments on commit b3507a5

Please sign in to comment.