fixes; work in progress: topics
This commit is contained in:
		
							parent
							
								
									f6308ff9bf
								
							
						
					
					
						commit
						dfc5cefcee
					
				
					 3 changed files with 21 additions and 8 deletions
				
			
		|  | @ -45,8 +45,8 @@ class Folder(Track): | |||
|         return self.container.storage.getItem(self.ref) | ||||
| 
 | ||||
|     def setTarget(self, target): | ||||
|         self.ref = target.uid | ||||
|         self.container.save(self) | ||||
|         self.set('ref', target.uid) | ||||
|         self.container.update(self) | ||||
| 
 | ||||
|     def __str__(self): | ||||
|         return '%s: %s; keys: %s' % (self.__class__.__name__, | ||||
|  |  | |||
|  | @ -119,10 +119,16 @@ class Container(object): | |||
|             return self.insert(track) | ||||
|         if self.insertOnChange and found.data != track.data: | ||||
|             return self.insert(track) | ||||
|         if found.data != track.data or found.timeStamp != track.timeStamp: | ||||
|         changed = False | ||||
|         if found.data != track.data: | ||||
|             found.update(track.data) | ||||
|             changed = True | ||||
|         if track.timeStamp is not None and found.timeStamp != track.timeStamp: | ||||
|             found.timeStamp = track.timeStamp | ||||
|             changed = True | ||||
|         if changed: | ||||
|             self.update(found) | ||||
|         track.trackId = found.trackId | ||||
|         return found.trackId | ||||
| 
 | ||||
|     def insert(self, track, withTrackId=False): | ||||
|  | @ -130,14 +136,15 @@ class Container(object): | |||
|         values = self.setupValues(track, withTrackId) | ||||
|         stmt = t.insert().values(**values).returning(t.c.trackid) | ||||
|         trackId = self.session.execute(stmt).first()[0] | ||||
|         track.trackId = trackId | ||||
|         self.storage.mark_changed() | ||||
|         return trackId | ||||
| 
 | ||||
|     def update(self, track): | ||||
|     def update(self, track, updateTimeStamp=False): | ||||
|         t = self.table | ||||
|         if updateTimeStamp or track.timeStamp is None: | ||||
|             track.timeStamp = datetime.now() | ||||
|         values = self.setupValues(track) | ||||
|         if track.timeStamp is None: | ||||
|             values['timestamp'] = datetime.now() | ||||
|         stmt = t.update().values(**values).where(t.c.trackid == track.trackId) | ||||
|         n = self.session.execute(stmt).rowcount | ||||
|         if n > 0: | ||||
|  |  | |||
|  | @ -96,11 +96,17 @@ def test_topic(self, config): | |||
|     storage = config.storageFactory(config.dbschema) | ||||
|     storage.dropTable('topics') | ||||
|     topics = storage.getContainer(topic.Topic) | ||||
|     types = storage.getContainer(concept.Type) | ||||
|     concept.storePredicate(storage, concept.defaultPredicate) | ||||
|     root = folder.Root(storage) | ||||
|     root['top']['topics'] = folder.Folder() | ||||
|     root['top']['topics'] = ftopics = folder.Folder() | ||||
|     ttopic = types.queryLast(name='topic') | ||||
|     self.assertEqual(ttopic.name, 'topic') | ||||
|     ftopics.setTarget(ttopic) | ||||
|     self.assertEqual(ftopics.ref, 'type-6') | ||||
| 
 | ||||
|     tp_itc = topic.Topic('itc') | ||||
|     tp_itc = topic.Topic('itc', data=dict( | ||||
|         title='ITC', description='Information and Communication Technology')) | ||||
|     topics.save(tp_itc) | ||||
| 
 | ||||
|     storage.commit() | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue