def values(self, dict_): '''parameters: - @data (dict) set object properties (static and dynamic), it's possible to set all dynamic properties with date string with __useDate__ key @data need to have "type_id" key or "FK_@@tablename@@Type" key ''' self.previousState = self.values.copy() if dict_.get('ID', None): del dict_['ID'] if self.fk_table_type_name not in dict_ and 'type_id' not in dict_ and not self.type_id: raise Exception('object type not exists') if 'type_name' in dict_: self.type_name = dict_.get('type_name') else: type_id = dict_.get(self.fk_table_type_name, None) or dict_.get( 'type_id', None) or self.type_id self._type = self.session.query(self.TypeClass).get(type_id) useDate = parser(dict_.get('__useDate__', None)) for prop, value in dict_.items(): self.setValue(prop, value, useDate) if self.hasLinkedField: useDateLinked = useDate or self.linkedFieldDate() self.updateLinkedField(dict_, useDate=useDateLinked)
def values(self, dict_): myDict = copy.deepcopy(dict_) '''parameters: - data (dict) set object properties (static and dynamic), it's possible to set all dynamic properties with date string with __useDate__ key''' self.newPosition = MonitoredSitePosition() self.positionChanged = False self.previousState = self.values if myDict.get('ID', None): del myDict['ID'] if self.fk_table_type_name not in myDict and 'type_id' not in myDict and not self.type_id: raise Exception('object type not exists') else: type_id = myDict.get(self.fk_table_type_name, None) or myDict.get( 'type_id', None) if self.type_id: type_id = self.type_id self._type = self.session.query(self.TypeClass).get(type_id) useDate = parser(myDict.get('__useDate__', None)) or self.linkedFieldDate() for prop, value in myDict.items(): self.setValue(prop, value, useDate) self.setPosition(myDict) self.updateLinkedField(myDict, useDate=useDate)
def setValue(self, propertyName, value, useDate=None): ''' Set object properties (static and dynamic) - value can have two forms: { value: value date: date } or value ''' # extract value and date from dict value if isinstance(value, dict) and "date" in value: useDate = parser(value.get("date")) value = value.get("value", None) HasStaticProperties.setValue(self, propertyName, value) if not hasattr(self, propertyName) and propertyName not in self.__table__.c: self.setDynamicValue(propertyName, parser(value), useDate) self.__values__[propertyName] = value
def setValue(self, propertyName, value): ''' @propertyName :: string, @value :: string, integer, float, ... every type Database compliant ''' #check if propertyName corresponding to a column if not hasattr(self, propertyName): if propertyName in self.__table__.c: print(propertyName) print(self.__table__.c) propertyName = class_mapper( inspect(self).class_).get_property_by_column( self.__table__.c[propertyName]).key else: return setattr(self, propertyName, parser(value)) self.__values__[propertyName] = value
def buildMetaDataInfoFromErdData(self): metaDataInfo = {} metaDataInfo['monitoredSite'] = {} metaDataInfo['image'] = {} metaDataInfo['user'] = {} metaDataInfo['session'] = {} metaDataInfo['misc'] = {} user = self.session.query(User).get( self.request.authenticated_userid['iss']) metaDataInfo['user']['TUse_FirstName'] = user.Firstname metaDataInfo['user']['TUse_LastName'] = user.Lastname # print(self.request) metaDataInfo['image']['photoId'] = 0 metaDataInfo['image']['name'] = self.request.POST['resumableFilename'] metaDataInfo['image']['fkSensor'] = int(self.request.POST['id']) metaDataInfo['image']['dateTimeOriginalPhoto'] = '' metaDataInfo['image']['dateInsertSQL'] = '' metaDataInfo['image']['lastTransformationDate'] = '' metaDataInfo['image']['dateTimeCreationPhoto'] = '' metaDataInfo['image']['lastDateWriteInPhoto'] = '' metaDataInfo['image']['shootId'] = -1 metaDataInfo['session']['startDate'] = str( self.request.POST['startDate']) metaDataInfo['session']['endDate'] = str(self.request.POST['endDate']) metaDataInfo['misc']['regionAnPlaceMonitoredSite'] = '' metaDataInfo['misc']['projectName'] = '' monitoredSite = self.session.query(MonitoredSite).get( self.request.POST['monitoredSiteId']) sitePosition = monitoredSite.GetLastPositionWithDate( parser(str(self.request.POST['endDate']))) metaDataInfo['monitoredSite']['Name'] = monitoredSite.Name metaDataInfo['monitoredSite']['LAT'] = sitePosition['LAT'] metaDataInfo['monitoredSite']['LON'] = sitePosition['LON'] metaDataInfo['monitoredSite']['Precision'] = sitePosition['Precision'] metaDataInfo['monitoredSite']['ELE'] = sitePosition['ELE'] return metaDataInfo