View on GitHub


3 hrs
Test Coverage
# Copyright (c) 2019-2021 Alexander Todorov <>

# Licensed under the GPL 2.0:

from django.forms.models import model_to_dict
from modernrpc.core import rpc_method

from tcms.core.utils import form_errors_to_list
from import Classification
from import ClassificationForm
from tcms.rpc.decorators import permissions_required

def filter(query):  # pylint: disable=redefined-builtin
    .. function:: RPC Classification.filter(query)

        Perform a search and return the resulting list of classifications.

        :param query: Field lookups for :class:``
        :type query: dict
        :return: Serialized list of :class:`` objects
        :rtype: dict
    return list(Classification.objects.filter(**query).values("id", "name").distinct())

def create(values):
    .. function:: RPC Classification.create(values)

        Create a new Classification object and store it in the database.

        :param values: Field values for :class:``
        :type values: dict
        :return: Serialized :class:`` object
        :rtype: dict
        :raises ValueError: if input values don't validate
        :raises PermissionDenied: if missing *management.add_classification* permission
    form = ClassificationForm(values)

    if form.is_valid():
        classification =
        return model_to_dict(classification)

    raise ValueError(form_errors_to_list(form))