Skip to content
Snippets Groups Projects
Commit 7b444faa authored by Swen Vermeul's avatar Swen Vermeul
Browse files

added all date-containing attributes for all entities

parent e96f37cf
No related branches found
No related tags found
No related merge requests found
from pandas import DataFrame, Series from pandas import DataFrame, Series
from tabulate import tabulate from tabulate import tabulate
from .definitions import openbis_definitions, fetch_option from .definitions import openbis_definitions, fetch_option
from .utils import parse_jackson, check_datatype, split_identifier, format_timestamp, is_identifier, is_permid, nvl from .utils import parse_jackson, check_datatype, split_identifier, format_timestamp, is_identifier, is_permid, nvl, extract_person
from .attachment import Attachment from .attachment import Attachment
import copy import copy
...@@ -87,9 +87,17 @@ class AttrHolder(): ...@@ -87,9 +87,17 @@ class AttrHolder():
elif attr in ["tags"]: elif attr in ["tags"]:
self.add_tags(data[attr]) self.add_tags(data[attr])
elif attr.endswith('Date'):
self.__dict__['_'+attr] = format_timestamp(data.get(attr))
elif attr in ['registrator', 'modifier', 'dataProducer']:
self.__dict__['_'+attr] = extract_person(data.get(attr))
else: else:
self.__dict__['_' + attr] = data.get(attr, None) self.__dict__['_' + attr] = data.get(attr, None)
def _new_attrs(self, method_name=None): def _new_attrs(self, method_name=None):
"""Returns the Python-equivalent JSON request when a new object is created. """Returns the Python-equivalent JSON request when a new object is created.
It is used internally by the save() method of a newly created object. It is used internally by the save() method of a newly created object.
...@@ -345,11 +353,6 @@ class AttrHolder(): ...@@ -345,11 +353,6 @@ class AttrHolder():
}) })
return ras return ras
elif int_name in ['_registrator', '_modifier', '_dataProducer']:
return self.__dict__[int_name].get('userId', None)
elif int_name in ['_registrationDate', '_modificationDate', '_accessDate', '_dataProductionDate']:
return format_timestamp(self.__dict__[int_name])
# if the attribute contains a list, # if the attribute contains a list,
# return a list of either identifiers, codes or # return a list of either identifiers, codes or
...@@ -839,6 +842,17 @@ class AttrHolder(): ...@@ -839,6 +842,17 @@ class AttrHolder():
file_list.append(filename) file_list.append(filename)
return file_list return file_list
def all(self):
"""Return all attributes of an entity in a dict
"""
attrs = {}
for attr in self._allowed_attrs:
if attr == 'attachments':
continue
attrs[attr] = getattr(self, attr)
return attrs
def _repr_html_(self): def _repr_html_(self):
def nvl(val, string=''): def nvl(val, string=''):
if val is None: if val is None:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment