Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added key default version in serializer Repository #612

Merged
merged 2 commits into from
Jul 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions bothub/api/v2/repository/serializers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import json
from os import access

from django.conf import settings
from django.shortcuts import get_object_or_404
Expand Down Expand Up @@ -45,11 +44,6 @@
RepositoryVersionLanguage,
)
from bothub.utils import classifier_choice

from ..translation.validators import (
CanContributeInRepositoryExampleValidator,
CanContributeInRepositoryTranslatedExampleValidator,
)
from .validators import (
APIExceptionCustom,
CanContributeInRepositoryValidator,
Expand All @@ -58,6 +52,10 @@
ExampleWithIntentOrEntityValidator,
IntentValidator,
)
from ..translation.validators import (
CanContributeInRepositoryExampleValidator,
CanContributeInRepositoryTranslatedExampleValidator,
)


class RequestRepositoryAuthorizationSerializer(serializers.ModelSerializer):
Expand Down Expand Up @@ -916,6 +914,7 @@ class Meta:
"use_name_entities",
"use_analyze_char",
"organization",
"version_default",
]
read_only = ["uuid", "created_at"]
ref_name = None
Expand Down Expand Up @@ -986,6 +985,7 @@ class Meta:
style={"show": False},
)
categories_list = serializers.SerializerMethodField(style={"show": False})
version_default = serializers.SerializerMethodField(style={"show": False})

def create(self, validated_data):
organization = validated_data.pop("organization", None)
Expand Down Expand Up @@ -1017,6 +1017,13 @@ def get_intents(self, obj):
def get_categories_list(self, obj):
return RepositoryCategorySerializer(obj.categories, many=True).data

def get_version_default(self, obj):
return {
"id": obj.current_version().repository_version.pk,
"repository_version_language_id": obj.current_version().pk,
"name": obj.current_version().repository_version.name,
}


class RepositoryPermissionSerializer(serializers.ModelSerializer):
class Meta:
Expand Down Expand Up @@ -1109,6 +1116,7 @@ class Meta:
"owner__nickname",
"absolute_url",
"votes",
"version_default",
]
read_only = fields
ref_name = None
Expand All @@ -1123,13 +1131,21 @@ class Meta:
absolute_url = serializers.SerializerMethodField()
intents = serializers.SerializerMethodField(style={"show": False})
votes = RepositoryVotesSerializer(many=True, read_only=True)
version_default = serializers.SerializerMethodField(style={"show": False})

def get_intents(self, obj):
return obj.get_formatted_intents()

def get_absolute_url(self, obj):
return obj.get_absolute_url()

def get_version_default(self, obj):
return {
"id": obj.current_version().repository_version.pk,
"repository_version_language_id": obj.current_version().pk,
"name": obj.current_version().repository_version.name,
}


class RepositoryContributionsSerializer(serializers.ModelSerializer):
class Meta:
Expand Down
13 changes: 6 additions & 7 deletions bothub/authentication/models.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.base_user import BaseUserManager
from django.conf import settings
from django.contrib.auth.base_user import AbstractBaseUser
from django.contrib.auth.base_user import BaseUserManager
from django.contrib.auth.models import PermissionsMixin
from django.core.validators import RegexValidator, _lazy_re_compile
from django.contrib.auth.tokens import PasswordResetTokenGenerator
from django.core.exceptions import ValidationError
from django.core.mail import send_mail
from django.core.validators import RegexValidator, _lazy_re_compile
from django.db import models
from django.template.loader import render_to_string
from django.conf import settings
from django.core.exceptions import ValidationError
from django.dispatch import receiver
from django.utils.translation import ugettext_lazy as _

user_nickname_re = _lazy_re_compile(r"^[-a-zA-Z0-9_]+\Z")
validate_user_nickname_format = RegexValidator(
Expand Down