| 3 | |
| 4 | |
| 5 | class Project_Directory_List(Base): |
| 6 | __tablename__ = 'project_directory_list' |
| 7 | |
| 8 | """ |
| 9 | |
| 10 | Not sure if name is right, could be |
| 11 | project_directory_map or project_to_directory |
| 12 | |
| 13 | """ |
| 14 | |
| 15 | working_dir_id = Column(Integer, ForeignKey('working_dir.id'), primary_key=True) |
| 16 | project_id = Column(Integer, ForeignKey('project.id'), primary_key=True) |
| 17 | |
| 18 | directory = relationship("WorkingDir") |
| 19 | |
| 20 | # cache of nickname, canoncial on directory itself |
| 21 | nickname = Column(String()) # Implies user selectable, real id is primary keys |
| 22 | |
| 23 | archived = Column(Boolean) |
| 24 | |
| 25 | project = relationship("Project") |
| 26 | |
| 27 | created_time = Column(DateTime, default=datetime.datetime.utcnow) |
| 28 | last_time = Column(DateTime, onupdate=datetime.datetime.utcnow) |
| 29 | |
| 30 | @staticmethod |
| 31 | def get_by_name(session, project_id, name): |
| 32 | query = session.query(Project_Directory_List).filter( |
| 33 | or_(Project_Directory_List.archived == False, Project_Directory_List.archived == None), |
| 34 | Project_Directory_List.nickname == name, |
| 35 | Project_Directory_List.project_id == project_id |
| 36 | ) |
| 37 | return query.first() |
| 38 | |
| 39 | def get_by_project( |
| 40 | session, |
| 41 | project_id, |
| 42 | exclude_archived=True, |
| 43 | kind="counts", |
| 44 | directory_ids_to_ignore_list: list = None, |
| 45 | nickname: str = None |
| 46 | ): |
| 47 | """ |
| 48 | Get counts or objects of class Project_Directory_List |
| 49 | |
| 50 | object.working_dir_id or object.project_id is available |
| 51 | object.directory (is working_dir_id while undergoing rename) |
| 52 | |
| 53 | archived is a cached value? source of truth should be on directory |
| 54 | itself? |
| 55 | |
| 56 | """ |
| 57 | |
| 58 | query = session.query(Project_Directory_List).filter( |
| 59 | Project_Directory_List.project_id == project_id) |
| 60 | |
| 61 | if nickname: |
| 62 | query = query.filter( |