Skip to content
Snippets Groups Projects
Commit 8558c303 authored by Samuel GAIST's avatar Samuel GAIST Committed by Samuel GAIST
Browse files

[common][serializers] Use annotate_full_name method

parent 7512a6f1
No related branches found
No related tags found
No related merge requests found
This commit is part of merge request !327. Comments created here will be created in the context of that merge request.
......@@ -29,13 +29,11 @@
from django.contrib.auth.models import User
from django.utils import six
from django.db.models import CharField, Value as V
from django.db.models.functions import Concat
from rest_framework import serializers
from ..team.models import Team
from ..common.utils import ensure_html
from ..common.utils import annotate_full_name
from .models import Shareable, Versionable, Contribution
from .exceptions import ContributionCreationError
......@@ -364,16 +362,9 @@ class ContributionCreationSerializer(serializers.ModelSerializer):
if previous_version is not None:
try:
previous_object = self.Meta.model.objects.annotate(
fullname=Concat(
"author__username",
V("/"),
"name",
V("/"),
"version",
output_field=CharField(),
)
).get(fullname=previous_version)
previous_object = annotate_full_name(self.Meta.model).get(
full_name=previous_version
)
except self.Meta.model.DoesNotExist:
raise serializers.ValidationError(
"{} '{}' not found".format(
......@@ -398,16 +389,9 @@ class ContributionCreationSerializer(serializers.ModelSerializer):
raise serializers.ValidationError("A fork starts at 1")
try:
forked_of_object = self.Meta.model.objects.annotate(
fullname=Concat(
"author__username",
V("/"),
"name",
V("/"),
"version",
output_field=CharField(),
)
).get(fullname=fork_of)
forked_of_object = annotate_full_name(self.Meta.model).get(
full_name=fork_of
)
except self.Meta.model.DoesNotExist:
raise serializers.ValidationError(
"{} '{}' fork origin not found".format(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment