コード例 #1
0
ファイル: tasks_service.py プロジェクト: NeroSouza/zou
def get_department(department_id):
    try:
        department = Department.get(department_id)
    except StatementError:
        raise DepartmentNotFoundException()

    if department is None:
        raise DepartmentNotFoundException()

    return department.serialize()
コード例 #2
0
def get_department(department_id):
    """
    Get department matching given id as a dictionary.
    """
    try:
        department = Department.get(department_id)
    except StatementError:
        raise DepartmentNotFoundException()

    if department is None:
        raise DepartmentNotFoundException()

    return department.serialize()
コード例 #3
0
def add_metadata_descriptor(project_id,
                            entity_type,
                            name,
                            choices,
                            for_client,
                            departments=[]):
    if not departments:
        departments = []

    try:
        departments_objects = [
            Department.get(department_id) for department_id in departments
            if department_id is not None
        ]
    except StatementError:
        raise DepartmentNotFoundException()

    descriptor = MetadataDescriptor.create(
        project_id=project_id,
        entity_type=entity_type,
        name=name,
        choices=choices,
        for_client=for_client,
        departments=departments_objects,
        field_name=slugify.slugify(name, separator="_"),
    )
    events.emit(
        "metadata-descriptor:new",
        {"metadata_descriptor_id": str(descriptor.id)},
        project_id=project_id,
    )
    clear_project_cache(project_id)
    return descriptor.serialize()
コード例 #4
0
 def update_data(self, data, instance_id):
     if "departments" in data:
         try:
             departments = []
             for department_id in data["departments"]:
                 department = Department.get(department_id)
                 if department is not None:
                     departments.append(department)
         except StatementError:
             raise DepartmentNotFoundException()
         data["departments"] = departments
     return data
コード例 #5
0
def update_metadata_descriptor(metadata_descriptor_id, changes):
    """
    Update metadata descriptor information for given id.
    """
    descriptor = get_metadata_descriptor_raw(metadata_descriptor_id)

    if "name" in changes and len(changes["name"]) > 0:
        changes["field_name"] = slugify.slugify(changes["name"])
        if descriptor.field_name != changes["field_name"]:
            query = Entity.query.filter(
                Entity.project_id == descriptor.project_id)
            if descriptor.entity_type == "Shot":
                shot_type = shots_service.get_shot_type()
                query = query.filter(Entity.entity_type_id == shot_type["id"])
            elif descriptor.entity_type == "Asset":
                query = query.filter(assets_service.build_asset_type_filter())
            elif descriptor.entity_type == "Edit":
                edit_type = edits_service.get_edit_type()
                query = query.filter(Entity.entity_type_id == edit_type["id"])

            entities = query.all()
            for entity in entities:
                metadata = fields.serialize_value(entity.data) or {}
                value = metadata.pop(descriptor.field_name, None)
                if value is not None:
                    metadata[changes["field_name"]] = value
                    entity.update_no_commit({"data": metadata})
            Entity.commit()

    if "departments" in changes:
        if not changes["departments"]:
            changes["departments"] = []

        try:
            departments_objects = [
                Department.get(department_id)
                for department_id in changes["departments"]
                if department_id is not None
            ]
        except StatementError:
            raise DepartmentNotFoundException()

        changes["departments"] = departments_objects

    descriptor.update(changes)
    events.emit(
        "metadata-descriptor:update",
        {"metadata_descriptor_id": str(descriptor.id)},
        project_id=descriptor.project_id,
    )
    clear_project_cache(str(descriptor.project_id))
    return descriptor.serialize()
コード例 #6
0
ファイル: person.py プロジェクト: tpolson/zou
 def update_data(self, data, instance_id):
     if "password" in data:
         del data["password"]
     if "departments" in data:
         try:
             departments = [
                 Department.get(department_id)
                 for department_id in data["departments"]
             ]
         except StatementError:
             raise DepartmentNotFoundException()
         data["departments"] = departments
     return data
コード例 #7
0
def create_person(
    email,
    password,
    first_name,
    last_name,
    phone="",
    role="user",
    desktop_login="",
    departments=[],
):
    """
    Create a new person entry in the database. No operation are performed on
    password, so encrypted password is expected.
    """
    if email is not None:
        email = email.strip()
    if not departments:
        departments = []

    try:
        departments_objects = [
            Department.get(department_id)
            for department_id in departments
            if department_id is not None
        ]
    except StatementError:
        raise DepartmentNotFoundException()

    person = Person.create(
        email=email,
        password=password,
        first_name=first_name,
        last_name=last_name,
        phone=phone,
        role=role,
        desktop_login=desktop_login,
        departments=departments_objects,
    )
    index_service.index_person(person)
    events.emit("person:new", {"person_id": person.id})
    clear_person_cache()
    return person.serialize(relations=True)