diff --git a/feed/views.py b/feed/views.py index aca261bd..cc3fd2e3 100644 --- a/feed/views.py +++ b/feed/views.py @@ -17,7 +17,7 @@ class NewSimpleFeed(APIView): serializator_class = NewsFeedListSerializer pagination_class = FeedPagination - def get_filter_data(self) -> list[str]: + def _get_filter_data(self) -> list[str]: filter_queries: str | None = self.request.query_params.get("type") filter_queries: str = filter_queries if filter_queries else "" # existence check @@ -27,7 +27,7 @@ def get_filter_data(self) -> list[str]: return news_types def get_queryset(self) -> QuerySet[News]: - filters = self.get_filter_data() + filters = self._get_filter_data() queryset = ( News.objects.select_related("content_type") .prefetch_related("content_object", "files") diff --git a/projects/serializers.py b/projects/serializers.py index fb6f159c..dccfb049 100644 --- a/projects/serializers.py +++ b/projects/serializers.py @@ -64,6 +64,7 @@ class Meta: class ProjectDetailSerializer(serializers.ModelSerializer): + achievements = AchievementListSerializer(many=True, read_only=True) cover = UserFileSerializer(required=False) collaborators = CollaboratorSerializer( diff --git a/users/admin.py b/users/admin.py index d5081588..1cbb2a9d 100644 --- a/users/admin.py +++ b/users/admin.py @@ -215,7 +215,13 @@ def force_verify(self, request, object_id): def get_export_users_emails(self, users): response_data = tablib.Dataset( - headers=["Имя и фамилия", "Возраст", "Интересы", "ВУЗ", "Специальность"] + headers=[ + "Имя и фамилия", + "Возраст", + "Интересы", + "ВУЗ / Школа", + "Специальность", + ] ) today = date.today() @@ -225,7 +231,9 @@ def get_export_users_emails(self, users): CustomUser.objects.all() .select_related("v2_speciality") .prefetch_related( - "collaborations__project", "collaborations__project__industry" + "collaborations__project", + "collaborations__project__industry", + "skills__skill", ) ) little_mans = users.filter(birthday__lte=date_limit_18) @@ -236,30 +244,41 @@ def get_export_users_emails(self, users): # quantity_big_mans = whole_quality - quantity_little_mans for baby in little_mans: - projects_names = [ - collab.project.industry.name for collab in baby.collaborations.all() + interests = [ + collab.project.industry.name if collab.project.industry else "" + for collab in baby.collaborations.all() ] + if not len(interests): + interests = [ + skill_to_obj.skill.name if skill_to_obj.skill else "" + for skill_to_obj in baby.skills.all() + ] + if not len(interests): + interests = baby.key_skills.split(",") if baby.key_skills else [] response_data.append( [ baby.first_name + " " + baby.last_name, today.year - baby.birthday.year, - ", ".join(projects_names), - "", - "", + ", ".join(interests), + baby.organization, + baby.v2_speciality if baby.v2_speciality else baby.speciality, ] ) for big_man in big_mans: - projects_names = [ - collab.project.industry.name for collab in big_man.collaborations.all() + industry_names = [ + collab.project.industry.name if collab.project.industry else "" + for collab in big_man.collaborations.all() ] response_data.append( [ big_man.first_name + " " + big_man.last_name, today.year - big_man.birthday.year, - ", ".join(projects_names), + ", ".join(industry_names), big_man.organization, - big_man.speciality, + big_man.v2_speciality + if big_man.v2_speciality + else big_man.speciality, ] ) diff --git a/vacancy/serializers.py b/vacancy/serializers.py index 9556eb48..8e936254 100644 --- a/vacancy/serializers.py +++ b/vacancy/serializers.py @@ -4,9 +4,11 @@ from core.models import Skill, SkillToObject from core.serializers import SkillToObjectSerializer +from core.services import get_views_count from files.models import UserFile from files.serializers import UserFileSerializer from projects.models import Project +from projects.validators import validate_project from users.serializers import UserDetailSerializer from vacancy.models import Vacancy, VacancyResponse @@ -34,6 +36,25 @@ def get_response_count(self, obj): return obj.vacancy_requests.filter(is_approved=None).count() +class ProjectVacancyListSerializer( + serializers.ModelSerializer, + AbstractVacancyReadOnlyFields, + RequiredSkillsSerializerMixin[Vacancy], +): + class Meta: + model = Vacancy + fields = [ + "id", + "role", + "required_skills", + "description", + "project", + "is_active", + "datetime_closed", + "response_count", + ] + + class ProjectForVacancySerializer(serializers.ModelSerializer[Project]): class Meta: model = Project @@ -91,30 +112,47 @@ class Meta: ] -class ProjectVacancyListSerializer( - serializers.ModelSerializer, - AbstractVacancyReadOnlyFields, - RequiredSkillsSerializerMixin[Vacancy], -): +class ProjectListSerializer(serializers.ModelSerializer): + views_count = serializers.SerializerMethodField(method_name="count_views") + short_description = serializers.SerializerMethodField() + + @classmethod + def count_views(cls, project): + return get_views_count(project) + + @classmethod + def get_short_description(cls, project): + return project.get_short_description() + class Meta: - model = Vacancy + model = Project fields = [ "id", - "role", - "required_skills", - "description", - "project", - "is_active", - "datetime_closed", - "response_count", + "name", + "leader", + "short_description", + "image_address", + "industry", + "views_count", ] + read_only_fields = ["leader", "views_count"] + + def is_valid(self, *, raise_exception=False): + return super().is_valid(raise_exception=raise_exception) + + def validate(self, data): + super().validate(data) + return validate_project(data) + class ProjectVacancyCreateListSerializer( serializers.ModelSerializer, AbstractVacancyReadOnlyFields, RequiredSkillsWriteSerializerMixin[Vacancy], ): + project = ProjectListSerializer() + def create(self, validated_data): project = validated_data["project"] if project.leader != self.context["request"].user: @@ -170,9 +208,7 @@ class VacancyResponseListSerializer(serializers.ModelSerializer): required=False, allow_null=True, ) - vacancy_role = ( - serializers.SerializerMethodField() - ) # SerializerMethodField to access related field + vacancy_role = serializers.SerializerMethodField() class Meta: model = VacancyResponse