Example #1
0
def add_preview_file_to_comment(comment_id, person_id, task_id, revision=0):
    """
    Add a preview to comment preview list. Auto set the revision field
    (add 1 if it's a new preview, keep the preview revision in other cases).
    """
    comment = get_comment_raw(comment_id)
    news = News.get_by(comment_id=comment_id)
    task = Task.get(comment.object_id)
    project_id = str(task.project_id)
    position = 1
    if revision == 0 and len(comment.previews) == 0:
        revision = get_next_preview_revision(task_id)
    elif revision == 0:
        revision = comment.previews[0].revision
        position = get_next_position(task_id, revision)
    else:
        position = get_next_position(task_id, revision)
    preview_file = files_service.create_preview_file_raw(str(
        uuid.uuid4())[:13],
                                                         revision,
                                                         task_id,
                                                         person_id,
                                                         position=position)
    events.emit("preview-file:new", {
        "preview_file_id": preview_file.id,
        "comment_id": comment_id,
    },
                project_id=project_id)
    comment.previews.append(preview_file)
    comment.save()
    if news is not None:
        news.update({"preview_file_id": preview_file.id})
    events.emit("comment:update", {"comment_id": comment.id},
                project_id=project_id)
    return preview_file.serialize()
Example #2
0
 def test_delete_news_for_comment(self):
     self.generate_fixture_comment()
     news_service.create_news_for_task_and_comment(self.task_dict,
                                                   self.comment)
     news_service.delete_news_for_comment(self.comment["id"])
     news_list = News.get_all()
     self.assertEqual(len(news_list), 0)
Example #3
0
 def test_create_news(self):
     self.generate_fixture_comment()
     news = news_service.create_news(comment_id=self.comment["id"],
                                     author_id=self.comment["person_id"],
                                     task_id=self.comment["object_id"])
     news_again = News.get(news["id"])
     self.assertIsNotNone(news_again)
Example #4
0
def remove_preview_file(preview_file):
    """
    Remove all files related to given preview file, then remove the preview file
    entry from the database.
    """
    task = Task.get(preview_file.task_id)
    entity = Entity.get(task.entity_id)
    news = News.get_by(preview_file_id=preview_file.id)

    if entity.preview_file_id == preview_file.id:
        entity.update({"preview_file_id": None})

    if news is not None:
        news.update({"preview_file_id": None})

    if preview_file.extension == "png":
        clear_picture_files(preview_file.id)
    elif preview_file.extension == "mp4":
        clear_movie_files(preview_file.id)
    else:
        clear_generic_files(preview_file.id)

    preview_file.comments = []
    preview_file.save()
    preview_file.delete()
    return preview_file.serialize()
Example #5
0
 def test_create_news_for_task_and_comment(self):
     self.generate_fixture_comment()
     news_service.create_news_for_task_and_comment(self.task_dict,
                                                   self.comment)
     news_list = News.get_all()
     self.assertEqual(len(news_list), 1)
     self.assertEqual(str(news_list[0].author_id), self.user["id"])
     self.assertEqual(str(news_list[0].task_id), self.task_dict["id"])
     self.assertEqual(str(news_list[0].comment_id), self.comment["id"])
Example #6
0
def delete_news_for_comment(comment_id):
    """
    Delete all news related to comment. It's mandatory to be able to delete the
    comment afterwards.
    """
    news_list = News.get_all_by(comment_id=comment_id)
    for news in news_list:
        news.delete()
    return fields.serialize_list(news_list)
Example #7
0
 def test_news(self):
     news_dict = {
         "id": "2b63ba4a-695f-4d4d-b13c-ecf3991e64b7",
         "type": "News",
         "author_id": str(self.person.id),
         "comment_id": self.comment["id"],
         "task_id": str(self.task.id),
         "task_type_id": str(self.task_type.id),
         "task_status_id": str(self.task_status.id),
         "task_entity_id": str(self.asset.id),
         "preview_file_id": None,
         "preview_file_extension": None,
         "project_id": str(self.project.id),
         "project_name": "Caminandes",
         "created_at": "2019-08-25T23:05:05",
         "change": True,
         "episode_id": None
     }
     News.create_from_import(news_dict)
     news = News.get(news_dict["id"])
     self.assertEqual(str(news.comment_id), self.comment["id"])
Example #8
0
def remove_project(project_id):
    from zou.app.services import playlists_service

    tasks = Task.query.filter_by(project_id=project_id)
    for task in tasks:
        remove_task(task.id, force=True)

    query = EntityLink.query.join(Entity,
                                  EntityLink.entity_in_id == Entity.id).filter(
                                      Entity.project_id == project_id)
    for link in query:
        link.delete_no_commit()
    EntityLink.commit()

    query = EntityVersion.query.join(
        Entity, EntityVersion.entity_id == Entity.id).filter(
            Entity.project_id == project_id)
    for version in query:
        version.delete_no_commit()
    EntityLink.commit()

    playlists = Playlist.query.filter_by(project_id=project_id)
    for playlist in playlists:
        playlists_service.remove_playlist(playlist.id)

    ApiEvent.delete_all_by(project_id=project_id)
    Entity.delete_all_by(project_id=project_id)
    MetadataDescriptor.delete_all_by(project_id=project_id)
    Milestone.delete_all_by(project_id=project_id)
    ScheduleItem.delete_all_by(project_id=project_id)
    SearchFilter.delete_all_by(project_id=project_id)

    for news in News.query.join(Task).filter_by(project_id=project_id).all():
        news.delete_no_commit()
    News.commit()
    project = Project.get(project_id)
    project.delete()
    events.emit("project:delete", {"project_id": project.id})
    return project_id
Example #9
0
def delete_news_for_comment(comment_id):
    """
    Delete all news related to comment. It's mandatory to be able to delete the
    comment afterwards.
    """
    news_list = News.get_all_by(comment_id=comment_id)
    if len(news_list) > 0:
        task = tasks_service.get_task(news_list[0].task_id)
        for news in news_list:
            news.delete()
            events.emit("news:delete", {"news_id": news.id},
                        project_id=task["project_id"])
    return fields.serialize_list(news_list)
Example #10
0
def create_news(comment_id=None,
                author_id=None,
                task_id=None,
                preview_file_id=None,
                change=False,
                created_at=None):
    """
    Create a new news for given person and comment.
    """
    news = News.create(change=change,
                       author_id=author_id,
                       comment_id=comment_id,
                       preview_file_id=preview_file_id,
                       task_id=task_id,
                       created_at=created_at)
    return news.serialize()
Example #11
0
def add_preview_file_to_comment(comment_id, person_id, task_id, revision=0):
    """
    Add a preview to comment preview list. Auto set the revision field
    (add 1 if it's a new preview, keep the preview revision in other cases).
    """
    comment = get_comment_raw(comment_id)
    news = News.get_by(comment_id=comment_id)
    if revision == 0 and len(comment.previews) == 0:
        revision = get_next_preview_revision(task_id)
    elif revision == 0:
        revision = comment.previews[0].revision

    preview_file = files_service.create_preview_file_raw(
        str(uuid.uuid4())[:13], revision, task_id, person_id)
    comment.previews.append(preview_file)
    comment.save()

    if news is not None:
        news.update({"preview_file_id": preview_file.id})

    return preview_file.serialize()