| 400 | |
| 401 | |
| 402 | class WorkingDirFileLink(Base): |
| 403 | __tablename__ = 'workingdir_file_link' |
| 404 | |
| 405 | """ |
| 406 | |
| 407 | Moved away from using association proxy seems to be fairly slow / limited |
| 408 | |
| 409 | TODO should we have project in here too |
| 410 | Now that we generally restrict directories to have a project? |
| 411 | """ |
| 412 | |
| 413 | working_dir_id = Column(Integer, ForeignKey('working_dir.id'), primary_key = True) |
| 414 | file_id = Column(Integer, ForeignKey('file.id'), primary_key = True) |
| 415 | |
| 416 | file = relationship("File") |
| 417 | |
| 418 | # Cache here for speed |
| 419 | type = Column(String()) # == file.type, ie "image", "video", etc.... wonder if should have type frame |
| 420 | committed = Column(Boolean) |
| 421 | |
| 422 | count = Column(Integer) |
| 423 | |
| 424 | created_time = Column(DateTime, default = datetime.datetime.utcnow) |
| 425 | last_time = Column(DateTime, onupdate = datetime.datetime.utcnow) |
| 426 | |
| 427 | # This is more for adding stuff |
| 428 | # Not for getting file directly |
| 429 | def file_link(session, working_dir_id, file_id): |
| 430 | file_link = session.query(WorkingDirFileLink).filter( |
| 431 | WorkingDirFileLink.working_dir_id == working_dir_id, |
| 432 | WorkingDirFileLink.file_id == file_id).first() |
| 433 | return file_link |
| 434 | |
| 435 | def remove(session, working_dir_id, file_id): |
| 436 | file_link = WorkingDirFileLink.file_link(session, working_dir_id, file_id) |
| 437 | |
| 438 | if file_link: |
| 439 | session.delete(file_link) |
| 440 | |
| 441 | def add(session, working_dir_id, file): |
| 442 | # need full file object |
| 443 | # for type and committed |
| 444 | file_link = WorkingDirFileLink(working_dir_id = working_dir_id, |
| 445 | file_id = file.id, |
| 446 | type = file.type, |
| 447 | committed = file.committed) |
| 448 | session.add(file_link) |
| 449 | |
| 450 | def commit(session, working_dir_id, file): |
| 451 | file_link = WorkingDirFileLink.file_link(session, working_dir_id, file.id) |
| 452 | file_link.committed = True |
| 453 | session.add(file_link) |
| 454 | |
| 455 | # TODO merge this with above too similar of function |
| 456 | # to only have "list" as extra thing |
| 457 | # CAREFUL LIST see above |
| 458 | def get_list_sub_query( |
| 459 | session, |