Ejemplo n.º 1
0
 def __init__(self,
              row: dict[str, Any],
              domain: Optional[Entity] = None,
              range_: Optional[Entity] = None) -> None:
     from openatlas.models.entity import Entity
     from openatlas.util.util import format_date_part
     self.id = row['id']
     self.description = row['description']
     self.property = g.properties[row['property_code']]
     self.domain = domain if domain else Entity.get_by_id(row['domain_id'])
     self.range = range_ if range_ else Entity.get_by_id(row['range_id'])
     self.type = g.types[row['type_id']] if row['type_id'] else None
     self.types: dict[Entity, None] = {}
     if 'type_id' in row and row['type_id']:
         self.types[g.types[row['type_id']]] = None
     if 'begin_from' in row:
         self.begin_from = timestamp_to_datetime64(row['begin_from'])
         self.begin_to = timestamp_to_datetime64(row['begin_to'])
         self.begin_comment = row['begin_comment']
         self.end_from = timestamp_to_datetime64(row['end_from'])
         self.end_to = timestamp_to_datetime64(row['end_to'])
         self.end_comment = row['end_comment']
         self.first = format_date_part(self.begin_from, 'year') \
             if self.begin_from else None
         self.last = format_date_part(self.end_from, 'year') \
             if self.end_from else None
         self.last = format_date_part(self.end_to, 'year') \
             if self.end_to else self.last
Ejemplo n.º 2
0
    def __init__(self, data: dict[str, Any]) -> None:

        self.id = data['id']
        self.name = data['name']
        self.description = data['description']
        self.created = data['created']
        self.modified = data['modified']
        self.cidoc_class = g.cidoc_classes[data['cidoc_class_code']]
        self.class_ = g.classes[data['openatlas_class_name']]
        self.reference_systems: list[Link] = []
        self.origin_id: Optional[int] = None  # When coming from another entity
        self.image_id: Optional[int] = None  # Profile image
        self.linked_places: list[Entity] = []  # Related places for map
        self.location: Optional[Entity] = None  # Respective location if place
        self.info_data: dict[str, Union[str, list[str], None]]

        self.standard_type = None
        self.types: dict[Type, str] = {}
        if 'types' in data and data['types']:
            for item in data['types']:  # f1 = type id, f2 = value
                type_ = g.types[item['f1']]
                if type_.class_.name == 'type_anthropology':
                    continue
                self.types[type_] = item['f2']
                if type_.category == 'standard':
                    self.standard_type = type_

        self.aliases: dict[int, str] = {}
        if 'aliases' in data and data['aliases']:
            for alias in data['aliases']:  # f1 = alias id, f2 = alias name
                self.aliases[alias['f1']] = alias['f2']
            self.aliases = {
                k: v
                for k, v in sorted(self.aliases.items(),
                                   key=lambda item_: item_[1])
            }

        # Dates
        self.begin_from = None
        self.begin_to = None
        self.begin_comment = None
        self.end_from = None
        self.end_to = None
        self.end_comment = None
        self.first = None
        self.last = None
        if 'begin_from' in data:
            self.begin_from = timestamp_to_datetime64(data['begin_from'])
            self.begin_to = timestamp_to_datetime64(data['begin_to'])
            self.begin_comment = data['begin_comment']
            self.end_from = timestamp_to_datetime64(data['end_from'])
            self.end_to = timestamp_to_datetime64(data['end_to'])
            self.end_comment = data['end_comment']
            self.first = format_date_part(self.begin_from, 'year') \
                if self.begin_from else None
            self.last = format_date_part(self.end_from, 'year') \
                if self.end_from else None
            self.last = format_date_part(self.end_to, 'year') \
                if self.end_to else self.last
Ejemplo n.º 3
0
def populate_dates(form: FlaskForm, item: Union[Entity, Link]) -> None:
    if item.begin_from:
        form.begin_year_from.data = format_date_part(item.begin_from, 'year')
        form.begin_month_from.data = format_date_part(item.begin_from, 'month')
        form.begin_day_from.data = format_date_part(item.begin_from, 'day')
        form.begin_comment.data = item.begin_comment
        if item.begin_to:
            form.begin_year_to.data = format_date_part(item.begin_to, 'year')
            form.begin_month_to.data = format_date_part(item.begin_to, 'month')
            form.begin_day_to.data = format_date_part(item.begin_to, 'day')
    if item.end_from:
        form.end_year_from.data = format_date_part(item.end_from, 'year')
        form.end_month_from.data = format_date_part(item.end_from, 'month')
        form.end_day_from.data = format_date_part(item.end_from, 'day')
        form.end_comment.data = item.end_comment
        if item.end_to:
            form.end_year_to.data = format_date_part(item.end_to, 'year')
            form.end_month_to.data = format_date_part(item.end_to, 'month')
            form.end_day_to.data = format_date_part(item.end_to, 'day')