Exemple #1
0
def get_output_files_for_output_type_and_asset_instance(
        asset_instance_id,
        temporal_entity_id,
        output_type_id,
        representation=None):
    """
    Get output files created for given asset instance and output type.
    """
    query = OutputFile.query \
        .filter(
            OutputFile.asset_instance_id == asset_instance_id,
            OutputFile.output_type_id == output_type_id,
            OutputFile.temporal_entity_id == temporal_entity_id
        ) \
        .order_by(desc(OutputFile.revision))

    if representation is not None:
        query = query.filter(OutputFile.representation == representation)

    output_files = query.all()
    return OutputFile.serialize_list(output_files)
Exemple #2
0
def remove_person(person_id, force=True):
    person = Person.get(person_id)
    if force:
        for comment in Comment.get_all_by(person_id=person_id):
            remove_comment(comment.id)
        Notification.delete_all_by(person_id=person_id)
        SearchFilter.delete_all_by(person_id=person_id)
        DesktopLoginLog.delete_all_by(person_id=person_id)
        LoginLog.delete_all_by(person_id=person_id)
        Subscription.delete_all_by(person_id=person_id)
        TimeSpent.delete_all_by(person_id=person_id)
        for project in Project.query.filter(Project.team.contains(person)):
            project.team = [
                member for member in project.team
                if str(member.id) != person_id
            ]
            project.save()
        for task in Task.query.filter(Task.assignees.contains(person)):
            task.assignees = [
                assignee for assignee in task.assignees
                if str(assignee.id) != person_id
            ]
            task.save()
        for task in Task.get_all_by(assigner_id=person_id):
            task.update({"assigner_id": None})
        for output_file in OutputFile.get_all_by(person_id=person_id):
            output_file.update({"person_id": None})
        for working_file in WorkingFile.get_all_by(person_id=person_id):
            output_file.update({"person_id": None})
        for task in WorkingFile.get_all_by(person_id=person_id):
            output_file.update({"person_id": None})

    try:
        person.delete()
    except IntegrityError:
        raise ModelWithRelationsDeletionException(
            "Some data are still linked to given person.ttt")

    return person.serialize_safe()
Exemple #3
0
    def generate_fixture_output_file(self,
                                     output_type=None,
                                     revision=1,
                                     name="main",
                                     representation="",
                                     asset_instance=None,
                                     temporal_entity_id=None,
                                     task=None):
        if output_type is None:
            output_type = self.output_type

        if task is None:
            task_type_id = self.task_type.id
            asset_id = self.asset.id
        else:
            task_type_id = task.task_type_id
            asset_id = task.entity_id

        if asset_instance is None:
            asset_instance_id = None
        else:
            asset_instance_id = asset_instance.id
            if temporal_entity_id is None:
                temporal_entity_id = self.scene.id

        self.output_file = OutputFile.create(
            comment="",
            revision=revision,
            task_type_id=task_type_id,
            entity_id=asset_id,
            person_id=self.person.id,
            file_status_id=self.file_status.id,
            output_type_id=output_type.id,
            asset_instance_id=asset_instance_id,
            representation=representation,
            temporal_entity_id=temporal_entity_id,
            name=name)
        return self.output_file
Exemple #4
0
def create_new_output_revision(entity_id,
                               working_file_id,
                               output_type_id,
                               person_id,
                               task_type_id,
                               revision=0,
                               representation="",
                               name="main",
                               comment="",
                               extension="",
                               nb_elements=1,
                               asset_instance_id=None,
                               temporal_entity_id=None):
    """
    Create a new ouput file for given entity. Output type, task type, author
    and source file are required.

    The revision is set as next revision available but it can be forced.
    An extension and a name can be set too.

    An asset instance can be given too. In that case, the output file is
    linked to the asset instance.

    The `temporal_entity_id` concerns only asset instance output files. It is
    here to describe if the output is generated in the context of a shot or in
    the context of a scene.
    """

    if revision < 1:
        try:
            output_file = get_last_output_revision(
                entity_id,
                output_type_id,
                task_type_id,
                name=name,
                asset_instance_id=asset_instance_id,
                temporal_entity_id=temporal_entity_id)

            revision = output_file["revision"] + 1
        except NoOutputFileException:
            revision = 1

    file_status_id = get_default_status()["id"]

    try:
        output_file = OutputFile.get_by(name=name,
                                        entity_id=entity_id,
                                        asset_instance_id=asset_instance_id,
                                        output_type_id=output_type_id,
                                        task_type_id=task_type_id,
                                        temporal_entity_id=temporal_entity_id,
                                        representation=representation,
                                        revision=revision)

        if output_file is None:
            output_file = OutputFile.create(
                name=name,
                comment=comment,
                extension=extension,
                representation=representation,
                revision=revision,
                entity_id=entity_id,
                asset_instance_id=asset_instance_id,
                person_id=person_id,
                source_file_id=working_file_id,
                output_type_id=output_type_id,
                file_status_id=file_status_id,
                task_type_id=task_type_id,
                nb_elements=nb_elements,
                temporal_entity_id=temporal_entity_id)
            events.emit("output_file:new", {"output_file_id": output_file.id})
        else:
            raise EntryAlreadyExistsException

    except IntegrityError:
        raise EntryAlreadyExistsException

    return output_file.serialize()
Exemple #5
0
class ApiDBTestCase(ApiTestCase):
    def setUp(self):
        """
        Reset database before each test.
        """
        super(ApiDBTestCase, self).setUp()

        from zou.app.utils import dbhelpers
        dbhelpers.drop_all()
        dbhelpers.create_all()
        self.log_in()

    def log_in(self):
        self.generate_fixture_user()
        self.post("auth/login", {
            "email": self.user.email,
            "password": "******"
        }, 200)

    def tearDown(self):
        """
        Delete database after each test.
        """
        from zou.app.utils import dbhelpers
        dbhelpers.drop_all()

    def generate_data(self, cls, number, **kwargs):
        """
        Generate random data for a given data model.
        """
        mixer.init_app(self.flask_app)
        return mixer.cycle(number).blend(cls, id=fields.gen_uuid, **kwargs)

    def generate_fixture_project_status(self):
        self.open_status = ProjectStatus(name="open", color="#FFFFFF")
        self.open_status.save()

    def generate_fixture_project_closed_status(self):
        self.closed_status = ProjectStatus(name="closed", color="#FFFFFF")
        self.closed_status.save()

    def generate_fixture_project(self):
        self.project = Project(name="Cosmos Landromat",
                               project_status_id=self.open_status.id)
        self.project.save()
        self.project.update(
            {"file_tree": file_tree.get_tree_from_file("simple")})

    def generate_fixture_project_closed(self):
        self.project_closed = Project(name="Old Project",
                                      project_status_id=self.closed_status.id)
        self.project_closed.save()

    def generate_fixture_project_standard(self):
        self.project_standard = Project(name="Big Buck Bunny",
                                        project_status_id=self.open_status.id)
        self.project_standard.save()
        self.project_standard.update(
            {"file_tree": file_tree.get_tree_from_file("standard")})

    def generate_fixture_entity(self):
        self.entity = Entity(name="Tree",
                             description="Description Tree",
                             project_id=self.project.id,
                             entity_type_id=self.entity_type.id)
        self.entity.save()

    def generate_fixture_entity_standard(self):
        self.entity_standard = Entity(name="Car",
                                      project_id=self.project_standard.id,
                                      entity_type_id=self.entity_type.id)
        self.entity_standard.save()

    def generate_fixture_sequence(self):
        if hasattr(self, "episode"):
            episode_id = self.episode.id
        else:
            episode_id = None

        self.sequence = Entity(name="S01",
                               project_id=self.project.id,
                               entity_type_id=self.sequence_type.id,
                               parent_id=episode_id)
        self.sequence.save()

    def generate_fixture_sequence_standard(self):
        self.sequence_standard = Entity(name="S01",
                                        project_id=self.project_standard.id,
                                        entity_type_id=self.sequence_type.id)
        self.sequence_standard.save()

    def generate_fixture_episode(self):
        self.episode = Entity(name="E01",
                              project_id=self.project.id,
                              entity_type_id=self.episode_type.id)
        self.episode.save()

    def generate_fixture_shot(self):
        self.shot = Entity(name="P01",
                           description="Description Shot 01",
                           data={
                               "fps": 25,
                               "frame_in": 0,
                               "frame_out": 100
                           },
                           project_id=self.project.id,
                           entity_type_id=self.shot_type.id,
                           parent_id=self.sequence.id)
        self.shot.save()
        self.shot_noseq = Entity(name="P01NOSEQ",
                                 project_id=self.project.id,
                                 entity_type_id=self.shot_type.id)
        self.shot_noseq.save()

    def generate_fixture_shot_standard(self):
        self.shot_standard = Entity(name="P01",
                                    description="Description Shot 01",
                                    data={
                                        "fps": 25,
                                        "frame_in": 0,
                                        "frame_out": 100
                                    },
                                    project_id=self.project_standard.id,
                                    entity_type_id=self.shot_type.id,
                                    parent_id=self.sequence_standard.id)
        self.shot_standard.save()

    def generate_fixture_user(self):
        self.user = Person(first_name="John",
                           last_name="Did",
                           email=u"*****@*****.**",
                           password=auth.encrypt_password("mypassword"))
        self.user.save()

    def generate_fixture_person(self):
        self.person = Person(first_name="John",
                             last_name="Doe",
                             email=u"*****@*****.**",
                             password=auth.encrypt_password("mypassword"))
        self.person.save()

    def generate_fixture_entity_type(self):
        self.entity_type = EntityType(name="Props")
        self.entity_type.save()
        self.shot_type = EntityType(name="Shot")
        self.shot_type.save()
        self.sequence_type = EntityType(name="Sequence")
        self.sequence_type.save()
        self.episode_type = EntityType(name="Episode")
        self.episode_type.save()

    def generate_fixture_department(self):
        self.department = Department(name="Modeling", color="#FFFFFF")
        self.department.save()
        self.department_animation = Department(name="Animation",
                                               color="#FFFFFF")
        self.department_animation.save()

    def generate_fixture_task_type(self):
        self.task_type = TaskType(name="Shaders",
                                  color="#FFFFFF",
                                  department_id=self.department.id)
        self.task_type.save()
        self.task_type_animation = TaskType(
            name="Animation",
            color="#FFFFFF",
            department_id=self.department_animation.id)
        self.task_type_animation.save()

    def generate_fixture_task_status(self):
        self.task_status = TaskStatus(name="Open",
                                      short_name="opn",
                                      color="#FFFFFF")
        self.task_status.save()

    def generate_fixture_task_status_wip(self):
        self.task_status_wip = TaskStatus(name="WIP",
                                          short_name="wip",
                                          color="#FFFFFF")
        self.task_status_wip.save()

    def generate_fixture_task_status_to_review(self):
        self.task_status_to_review = TaskStatus(name="To review",
                                                short_name="pndng",
                                                color="#FFFFFF")
        self.task_status_to_review.save()

    def generate_fixture_assigner(self):
        self.assigner = Person(first_name="Ema", last_name="Peel")
        self.assigner.save()

    def generate_fixture_task(self):
        start_date = fields.get_date_object("2017-02-20")
        due_date = fields.get_date_object("2017-02-28")
        real_start_date = fields.get_date_object("2017-02-22")
        self.task = Task(name="Super modeling",
                         project_id=self.project.id,
                         task_type_id=self.task_type.id,
                         task_status_id=self.task_status.id,
                         entity_id=self.entity.id,
                         assignees=[self.person],
                         assigner_id=self.assigner.id,
                         duration=50,
                         estimation=40,
                         start_date=start_date,
                         due_date=due_date,
                         real_start_date=real_start_date)
        self.task.save()

    def generate_fixture_task_standard(self):
        start_date = fields.get_date_object("2017-02-20")
        due_date = fields.get_date_object("2017-02-28")
        real_start_date = fields.get_date_object("2017-02-22")
        self.task_standard = Task(name="Super modeling",
                                  project_id=self.project_standard.id,
                                  task_type_id=self.task_type.id,
                                  task_status_id=self.task_status.id,
                                  entity_id=self.entity_standard.id,
                                  assignees=[self.person],
                                  assigner_id=self.assigner.id,
                                  duration=50,
                                  estimation=40,
                                  start_date=start_date,
                                  due_date=due_date,
                                  real_start_date=real_start_date)
        self.task_standard.save()

    def generate_fixture_shot_task(self):
        self.shot_task = Task(
            name="Super animation",
            project_id=self.project.id,
            task_type_id=self.task_type_animation.id,
            task_status_id=self.task_status.id,
            entity_id=self.shot.id,
            assignees=[self.person],
            assigner_id=self.assigner.id,
        )
        self.shot_task.save()

    def generate_fixture_shot_task_standard(self):
        self.shot_task_standard = Task(
            name="Super animation",
            project_id=self.project_standard.id,
            task_type_id=self.task_type_animation.id,
            task_status_id=self.task_status.id,
            entity_id=self.shot_standard.id,
            assignees=[self.person],
            assigner_id=self.assigner.id)
        self.shot_task_standard.save()

    def generate_fixture_file_status(self):
        self.file_status = FileStatus(name="To review", color="#FFFFFF")
        self.file_status.save()

    def generate_fixture_working_file(self):
        self.working_file = WorkingFile(name="S01_P01_modeling",
                                        comment="",
                                        revision=1,
                                        task_id=self.task.id,
                                        entity_id=self.entity.id,
                                        person_id=self.person.id)
        self.working_file.save()

    def generate_fixture_shot_working_file(self):
        self.working_file = WorkingFile(name="S01_P01_animation",
                                        comment="",
                                        revision=1,
                                        task_id=self.task.id,
                                        entity_id=self.shot.id,
                                        person_id=self.person.id)
        self.working_file.save()

    def generate_fixture_output_file(self):
        self.output_file = OutputFile(comment="",
                                      revision=1,
                                      task_id=self.task.id,
                                      entity_id=self.entity.id,
                                      person_id=self.person.id,
                                      file_status_id=self.file_status.id)
        self.output_file.save()

    def get_fixture_file_path(self, relative_path):
        current_path = os.getcwd()
        file_path_fixture = os.path.join(current_path, "test", "fixtures",
                                         relative_path)
        return file_path_fixture