コード例 #1
0
ファイル: entity.py プロジェクト: stefaneichert/openAtlas
 def update(entity: Entity) -> None:
     from openatlas.util.util import sanitize
     sql = """
         UPDATE model.entity SET
         (name, description, begin_from, begin_to, begin_comment, end_from, end_to, end_comment) 
             = (%(name)s, %(description)s, %(begin_from)s, %(begin_to)s, %(begin_comment)s, 
             %(end_from)s, %(end_to)s, %(end_comment)s)
         WHERE id = %(id)s;"""
     g.cursor.execute(sql, {
         'id': entity.id, 'name': entity.name,
         'begin_from': DateMapper.datetime64_to_timestamp(entity.begin_from),
         'begin_to': DateMapper.datetime64_to_timestamp(entity.begin_to),
         'end_from': DateMapper.datetime64_to_timestamp(entity.end_from),
         'end_to': DateMapper.datetime64_to_timestamp(entity.end_to),
         'begin_comment': entity.begin_comment, 'end_comment': entity.end_comment,
         'description': sanitize(entity.description, 'description')})
     debug_model['div sql'] += 1
コード例 #2
0
 def update(link_: Link) -> None:
     sql = """
         UPDATE model.link SET (property_code, domain_id, range_id, description, type_id,
             begin_from, begin_to, begin_comment, end_from, end_to, end_comment) =
             (%(property_code)s, %(domain_id)s, %(range_id)s, %(description)s, %(type_id)s,
              %(begin_from)s, %(begin_to)s, %(begin_comment)s, %(end_from)s, %(end_to)s,
              %(end_comment)s)
         WHERE id = %(id)s;"""
     g.execute(sql, {'id': link_.id,
                     'property_code': link_.property.code,
                     'domain_id': link_.domain.id,
                     'range_id': link_.range.id,
                     'type_id': link_.type.id if link_.type else None,
                     'description': link_.description,
                     'begin_from': DateMapper.datetime64_to_timestamp(link_.begin_from),
                     'begin_to': DateMapper.datetime64_to_timestamp(link_.begin_to),
                     'begin_comment': link_.begin_comment,
                     'end_from': DateMapper.datetime64_to_timestamp(link_.end_from),
                     'end_to': DateMapper.datetime64_to_timestamp(link_.end_to),
                     'end_comment': link_.end_comment})
コード例 #3
0
ファイル: link.py プロジェクト: craws/OpenAtlas
 def update(link):
     sql = """
         UPDATE model.link SET (property_code, domain_id, range_id, description, type_id,
             begin_from, begin_to, begin_comment, end_from, end_to, end_comment) =
             (%(property_code)s, %(domain_id)s, %(range_id)s, %(description)s, %(type_id)s,
              %(begin_from)s, %(begin_to)s, %(begin_comment)s, %(end_from)s, %(end_to)s,
              %(end_comment)s)
         WHERE id = %(id)s;"""
     g.cursor.execute(sql, {'id': link.id,
                            'property_code': link.property.code,
                            'domain_id': link.domain.id,
                            'range_id': link.range.id,
                            'type_id': link.type.id if link.type else None,
                            'description': link.description,
                            'begin_from': DateMapper.datetime64_to_timestamp(link.begin_from),
                            'begin_to': DateMapper.datetime64_to_timestamp(link.begin_to),
                            'begin_comment': link.begin_comment,
                            'end_from':  DateMapper.datetime64_to_timestamp(link.end_from),
                            'end_to':  DateMapper.datetime64_to_timestamp(link.end_to),
                            'end_comment':  link.end_comment})
     debug_model['link sql'] += 1
コード例 #4
0
 def update(entity: Entity) -> None:
     from openatlas.util.util import sanitize
     sql = """
         UPDATE model.entity SET
         (name, description, begin_from, begin_to, begin_comment, end_from, end_to, end_comment) 
             = (%(name)s, %(description)s, %(begin_from)s, %(begin_to)s, %(begin_comment)s, 
             %(end_from)s, %(end_to)s, %(end_comment)s)
         WHERE id = %(id)s;"""
     g.execute(
         sql, {
             'id': entity.id,
             'name': entity.name,
             'begin_from': DateMapper.datetime64_to_timestamp(
                 entity.begin_from),
             'begin_to': DateMapper.datetime64_to_timestamp(
                 entity.begin_to),
             'end_from': DateMapper.datetime64_to_timestamp(
                 entity.end_from),
             'end_to': DateMapper.datetime64_to_timestamp(entity.end_to),
             'begin_comment': entity.begin_comment,
             'end_comment': entity.end_comment,
             'description': sanitize(entity.description, 'description')
         })
コード例 #5
0
 def insert(code, name, system_type=None, description=None, date=None):
     if not name and not date:  # pragma: no cover
         logger.log('error', 'database', 'Insert entity without name and date')
         return  # Something went wrong so don't insert
     sql = """
         INSERT INTO model.entity (name, system_type, class_code, description, value_timestamp)
         VALUES (%(name)s, %(system_type)s, %(code)s, %(description)s, %(value_timestamp)s)
         RETURNING id;"""
     params = {
         'name': name.strip(),
         'code': code,
         'system_type': system_type.strip() if system_type else None,
         'description': description.strip() if description else None,
         'value_timestamp':  DateMapper.datetime64_to_timestamp(date) if date else None}
     g.cursor.execute(sql, params)
     debug_model['div sql'] += 1
     return EntityMapper.get_by_id(g.cursor.fetchone()[0])
コード例 #6
0
 def insert(code, name, system_type=None, description=None, date=None):
     if not name and not date:  # pragma: no cover
         logger.log('error', 'database',
                    'Insert entity without name and date')
         return  # Something went wrong so don't insert
     sql = """
         INSERT INTO model.entity (name, system_type, class_code, description, value_timestamp)
         VALUES (%(name)s, %(system_type)s, %(code)s, %(description)s, %(value_timestamp)s)
         RETURNING id;"""
     params = {
         'name':
         str(date) if date else name.strip(),
         'code':
         code,
         'system_type':
         system_type.strip() if system_type else None,
         'description':
         description.strip() if description else None,
         'value_timestamp':
         DateMapper.datetime64_to_timestamp(date) if date else None
     }
     g.cursor.execute(sql, params)
     return EntityMapper.get_by_id(g.cursor.fetchone()[0])
コード例 #7
0
ファイル: util.py プロジェクト: neural-oracle/OpenAtlas
def format_date(value, format_='medium'):
    if not value:
        return ''
    if isinstance(value, numpy.datetime64):
        return DateMapper.datetime64_to_timestamp(value)
    return dates.format_date(value, format=format_, locale=session['language'])
コード例 #8
0
def format_date(value):
    if type(value) is numpy.datetime64:
        return DateMapper.datetime64_to_timestamp(value)
    return value.date().isoformat() if value else ''
コード例 #9
0
def format_date(value, format_='medium'):
    if not value:
        return ''
    if type(value) is numpy.datetime64:
        return DateMapper.datetime64_to_timestamp(value)
    return dates.format_date(value, format=format_, locale=session['language'])