Beispiel #1
0
 def update(self, form: Optional[FlaskForm] = None) -> None:
     from openatlas.util.display import sanitize
     if form:  # e.g. imports have no forms
         self.save_nodes(form)
         if self.class_.name != 'object_location':
             self.set_dates(form)
             self.update_aliases(form)
         for field in ['name', 'description']:
             if hasattr(form, field):
                 setattr(self, field, getattr(form, field).data)
         if hasattr(form, 'name_inverse'):  # A directional node, e.g. actor actor relation
             self.name = form.name.data.replace('(', '').replace(')', '').strip()
             if form.name_inverse.data.strip():
                 inverse = form.name_inverse.data.replace('(', '').replace(')', '').strip()
                 self.name += ' (' + inverse + ')'
     if self.class_.name == 'type':
         self.name = sanitize(self.name, 'node')
     elif self.class_.name == 'object_location':
         self.name = 'Location of ' + self.name
         self.description = None
     Db.update({
         'id': self.id,
         'name': str(self.name).strip(),
         'begin_from': Date.datetime64_to_timestamp(self.begin_from),
         'begin_to': Date.datetime64_to_timestamp(self.begin_to),
         'end_from': Date.datetime64_to_timestamp(self.end_from),
         'end_to': Date.datetime64_to_timestamp(self.end_to),
         'begin_comment': str(self.begin_comment).strip() if self.begin_comment else None,
         'end_comment': str(self.end_comment).strip() if self.end_comment else None,
         'description': sanitize(self.description, 'text')})
Beispiel #2
0
 def update_gis(self, gis_data: dict[str, Any], new: bool) -> None:
     from openatlas.models.gis import Gis
     if not self.location:
         self.location = self.get_linked_entity_safe('P53')
     if not new:
         Db.update({
             'id': self.location.id,
             'name': f'Location of {str(self.name).strip()}',
             'begin_from': None,
             'begin_to': None,
             'end_from': None,
             'end_to': None,
             'begin_comment': None,
             'end_comment': None,
             'description': None})
         Gis.delete_by_entity(self.location)
     Gis.insert(self.location, gis_data)
Beispiel #3
0
 def update_attributes(self, attributes: dict[str, Any]) -> None:
     for key, value in attributes.items():
         setattr(self, key, value)
     Db.update({
         'id': self.id,
         'name': str(self.name).strip(),
         'begin_from': datetime64_to_timestamp(self.begin_from),
         'begin_to': datetime64_to_timestamp(self.begin_to),
         'end_from': datetime64_to_timestamp(self.end_from),
         'end_to': datetime64_to_timestamp(self.end_to),
         'begin_comment':
             str(self.begin_comment).strip() if self.begin_comment else None,
         'end_comment':
             str(self.end_comment).strip() if self.end_comment else None,
         'description':
             sanitize(self.description, 'text') if self.description else None
     })