From 7b444faa1ffd0cb6c3578198745a278c9712bf4f Mon Sep 17 00:00:00 2001 From: vermeul <swen@ethz.ch> Date: Fri, 22 Mar 2019 11:25:24 +0100 Subject: [PATCH] added all date-containing attributes for all entities --- pybis/src/python/pybis/attribute.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/pybis/src/python/pybis/attribute.py b/pybis/src/python/pybis/attribute.py index 5aa03895375..20bfaedf922 100644 --- a/pybis/src/python/pybis/attribute.py +++ b/pybis/src/python/pybis/attribute.py @@ -1,7 +1,7 @@ from pandas import DataFrame, Series from tabulate import tabulate 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 import copy @@ -87,9 +87,17 @@ class AttrHolder(): elif attr in ["tags"]: 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: self.__dict__['_' + attr] = data.get(attr, None) + + def _new_attrs(self, method_name=None): """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. @@ -345,11 +353,6 @@ class AttrHolder(): }) 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, # return a list of either identifiers, codes or @@ -839,6 +842,17 @@ class AttrHolder(): file_list.append(filename) 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 nvl(val, string=''): if val is None: -- GitLab