Add Groupable methods has_ancestor, _descendant, _parent.
This commit is contained in:
		
							parent
							
								
									5712d6dabd
								
							
						
					
					
						commit
						97cc023866
					
				
					 1 changed files with 12 additions and 0 deletions
				
			
		|  | @ -182,6 +182,9 @@ class GroupableMixin(metaclass=abc.ABCMeta): | |||
|         parents = set(self.group_getter_many(parent_ids)) | ||||
|         return parents | ||||
| 
 | ||||
|     def has_ancestor(self, ancestor): | ||||
|         return ancestor in self.walk_parents() | ||||
| 
 | ||||
|     def has_any_child(self): | ||||
|         query = f'SELECT 1 FROM {self.group_table} WHERE parentid == ? LIMIT 1' | ||||
|         row = self.photodb.sql_select_one(query, [self.id]) | ||||
|  | @ -198,6 +201,15 @@ class GroupableMixin(metaclass=abc.ABCMeta): | |||
|         row = self.photodb.sql_select_one(query, [self.id, member.id]) | ||||
|         return row is not None | ||||
| 
 | ||||
|     def has_descendant(self, descendant): | ||||
|         return self in descendant.walk_parents() | ||||
| 
 | ||||
|     def has_parent(self, parent): | ||||
|         self.assert_same_type(parent) | ||||
|         query = f'SELECT 1 FROM {self.group_table} WHERE parentid == ? AND memberid == ?' | ||||
|         row = self.photodb.sql_select_one(query, [parent.id, self.id]) | ||||
|         return row is not None | ||||
| 
 | ||||
|     @abc.abstractmethod | ||||
|     def remove_child(self, member): | ||||
|         if not self.has_child(member): | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue