Пример #1
0
    def test_serialize_orm_array(self):
        person = Person(
            id=uuid.uuid4(),
            first_name="Jhon",
            last_name="Doe"
        )
        person2 = Person(
            id=uuid.uuid4(),
            first_name="Emma",
            last_name="Peel"
        )
        task = Task(
            id=uuid.uuid4(),
            name="Test Task",
            assignees=[person, person2]
        )

        is_id = str(person.id) in fields.serialize_orm_arrays(task.assignees)
        self.assertTrue(is_id)
        is_id = str(person2.id) in fields.serialize_orm_arrays(task.assignees)
        self.assertTrue(is_id)
        is_id = str(person.id) in fields.serialize_value(task.assignees)
        self.assertTrue(is_id)
        is_id = str(person2.id) in fields.serialize_value(task.assignees)
        self.assertTrue(is_id)
Пример #2
0
def acknowledge_comment(comment_id):
    """
    Add current user to the list of people who acknowledged given comment.
    If he's already present, remove it.
    """
    comment = tasks_service.get_comment_raw(comment_id)
    task = tasks_service.get_task(str(comment.object_id))
    project_id = task["project_id"]
    current_user = persons_service.get_current_user_raw()
    current_user_id = str(current_user.id)

    acknowledgements = fields.serialize_orm_arrays(comment.acknowledgements)
    is_already_ack = current_user_id in acknowledgements

    if is_already_ack:
        _unack_comment(project_id, comment, current_user)
    else:
        _ack_comment(project_id, comment, current_user)
    comment.save()
    return comment.serialize(relations=True)