Source code for tcms.rpc.api.version

# -*- coding: utf-8 -*-

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

from import VersionForm
from import Version
from tcms.rpc.decorators import permissions_required

[docs] @permissions_required("management.view_version") @rpc_method(name="Version.filter") def filter(query): # pylint: disable=redefined-builtin """ .. function:: RPC Version.filter(query) Search and returns the resulting list of versions. :param query: Field lookups for :class:`` :type query: dict :return: List of serialized :class:`` objects :rtype: list(dict) """ return list( Version.objects.filter(**query) .values("id", "value", "product", "product__name") .order_by("product", "id") .distinct() )
[docs] @permissions_required("management.add_version") @rpc_method(name="Version.create") def create(values): """ .. function:: RPC Version.create(values) Add new version. :param values: Field values for :class:`` :type values: dict :return: Serialized :class:`` object :rtype: dict :raises ValueError: if input data validation fails :raises PermissionDenied: if missing *management.add_version* permission Example:: # Add version for specified product: >>> Version.create({'value': 'devel', 'product': 272}) {'id': '1106', 'value': 'devel', 'product': 272} """ form = VersionForm(values) if form.is_valid(): version = return model_to_dict(version) raise ValueError(list(form.errors.items()))