Beispiel #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.forms.date import format_date
     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.nodes[row['type_id']] if row['type_id'] else None
     self.nodes: Dict['Entity', None] = {}
     if 'type_id' in row and row['type_id']:
         self.nodes[g.nodes[row['type_id']]] = None
     if 'begin_from' in row:
         self.begin_from = Date.timestamp_to_datetime64(row['begin_from'])
         self.begin_to = Date.timestamp_to_datetime64(row['begin_to'])
         self.begin_comment = row['begin_comment']
         self.end_from = Date.timestamp_to_datetime64(row['end_from'])
         self.end_to = Date.timestamp_to_datetime64(row['end_to'])
         self.end_comment = row['end_comment']
         self.first = format_date(self.begin_from,
                                  'year') if self.begin_from else None
         self.last = format_date(self.end_from,
                                 'year') if self.end_from else None
         self.last = format_date(self.end_to,
                                 'year') if self.end_to else self.last
Beispiel #2
0
    def __init__(self, data: Dict[str, Any]) -> None:

        self.id = data['id']
        self.standard_type = None
        self.nodes: Dict['Node', str] = {}

        if 'nodes' in data and data['nodes']:
            for item in data['nodes']:
                node = g.nodes[item['f1']]  # f1 = node id, f2 = value
                self.nodes[node] = item['f2']
                if node.root and g.nodes[node.root[-1]].standard:
                    self.standard_type = node

        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])
            }
        self.name = data['name']
        self.description = data['description']
        self.created = data['created']
        self.modified = data['modified']
        self.cidoc_class = g.cidoc_classes[data['class_code']]
        self.class_ = g.classes[data['system_class']]
        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 a place
        self.info_data: Dict[str, Union[str, List[str], None]]

        # 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(self.begin_from, 'year') \
                if self.begin_from else None
            self.last = format_date(self.end_from, 'year') \
                if self.end_from else None
            self.last = format_date(self.end_to, 'year') \
                if self.end_to else self.last
Beispiel #3
0
    def __init__(self, data: Dict[str, Any]) -> None:

        self.id = data['id']
        self.nodes: Dict['Node', str] = {}

        if 'nodes' in data and data['nodes']:
            for node in data['nodes']:
                self.nodes[g.nodes[node['f1']]] = node['f2']  # f1 = node id, f2 = value
        self.aliases: Dict[int, str] = {}
        if 'aliases' in data and data['aliases']:
            for alias in data['aliases']:
                self.aliases[alias['f1']] = alias['f2']  # f1 = alias id, f2 = alias name
            self.aliases = {k: v for k, v in sorted(self.aliases.items(), key=lambda item: item[1])}
        self.name = data['name']
        self.description = data['description']
        self.created = data['created']
        self.modified = data['modified']
        self.cidoc_class = g.cidoc_classes[data['class_code']]
        self.class_ = g.classes[data['system_class']]
        self.reference_systems: List[Link] = []  # Links to external reference systems
        self.origin_id: Optional[int] = None  # For navigation 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 entity is a place
        self.info_data: Dict[str, Union[str, List[str], None]]  # Used for detail views

        # 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 = Date.timestamp_to_datetime64(data['begin_from'])
            self.begin_to = Date.timestamp_to_datetime64(data['begin_to'])
            self.begin_comment = data['begin_comment']
            self.end_from = Date.timestamp_to_datetime64(data['end_from'])
            self.end_to = Date.timestamp_to_datetime64(data['end_to'])
            self.end_comment = data['end_comment']
            self.first = format_date(self.begin_from, 'year') if self.begin_from else None
            self.last = format_date(self.end_from, 'year') if self.end_from else None
            self.last = format_date(self.end_to, 'year') if self.end_to else self.last