Skip to content

Commit

Permalink
Merge pull request #413 from PROCOLLAB-github/fix/vacancies-project-data
Browse files Browse the repository at this point in the history
Fix/vacancies project data
  • Loading branch information
sh1nkey authored Aug 4, 2024
2 parents ca6948b + 8e272f0 commit 8b87b4a
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 29 deletions.
4 changes: 2 additions & 2 deletions feed/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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")
Expand Down
1 change: 1 addition & 0 deletions projects/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class Meta:


class ProjectDetailSerializer(serializers.ModelSerializer):

achievements = AchievementListSerializer(many=True, read_only=True)
cover = UserFileSerializer(required=False)
collaborators = CollaboratorSerializer(
Expand Down
41 changes: 30 additions & 11 deletions users/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand All @@ -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,
]
)

Expand Down
68 changes: 52 additions & 16 deletions vacancy/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8b87b4a

Please sign in to comment.