Skip to content

Commit

Permalink
Merge pull request #422 from PROCOLLAB-github/feature/set_project_com…
Browse files Browse the repository at this point in the history
…pany_status

PRO-404: Set project company status
  • Loading branch information
sh1nkey authored Aug 24, 2024
2 parents 52fb11a + 05a4a20 commit e385ff1
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 10 deletions.
1 change: 1 addition & 0 deletions projects/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class ProjectAdmin(admin.ModelAdmin):
"id",
"name",
"draft",
"is_company",
)
list_display_links = (
"id",
Expand Down
9 changes: 8 additions & 1 deletion projects/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class ProjectFilter(filters.FilterSet):
industry (int), step (int), region (str), name__contains (str),
description__contains (str), collaborator__user__in (List[int]),
datetime_created__gt (datetime.datetime), step (int), any_vacancies (bool),
member_count__gt (int), member_count__lt (int), leader (int), partner_program (int)
member_count__gt (int), member_count__lt (int), leader (int), partner_program (int),
is_company (bool).
Examples:
?industry=1&name__contains=clown
Expand All @@ -26,6 +27,7 @@ class ProjectFilter(filters.FilterSet):
?step=1 equals to .filter(step=1)
?any_vacancies=true equals to .filter(any_vacancies=True)
?collaborator__count__gt=1 equals to .filter(collaborator__count__gt=1)
?is_company=0/?is_company=false equals .filter(is_company=False)
"""

@classmethod
Expand Down Expand Up @@ -84,6 +86,10 @@ def filter_by_partner_program(self, queryset, name, value):
datetime_created__gt = filters.DateTimeFilter(
field_name="datetime_created", lookup_expr="gt"
)
is_company = filters.BooleanFilter(
field_name="is_company",
label="is_company\n`1`/`true` is company\n`0`/`false` is not company"
)

# filters by whether there are any vacancies in the project
any_vacancies = filters.BooleanFilter(field_name="vacancies", method="vacancy_filter")
Expand All @@ -107,4 +113,5 @@ class Meta:
"leader",
"step",
"partner_program",
"is_company",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 4.2.11 on 2024-08-23 12:11

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("projects", "0021_project_subscribers"),
]

operations = [
migrations.AlterModelOptions(
name="project",
options={
"ordering": ["-is_company", "-hidden_score", "-datetime_created"],
"verbose_name": "Проект",
"verbose_name_plural": "Проекты",
},
),
migrations.AddField(
model_name="project",
name="is_company",
field=models.BooleanField(default=False),
),
]
4 changes: 3 additions & 1 deletion projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class Project(models.Model):
image_address: A URLField image URL address.
leader: A ForeignKey referring to the User model.
draft: A boolean indicating if Project is a draft.
is_company: A boolean indicating if Project is a company.
cover: A ForeignKey referring to the UserFile model, which is the image cover of the project.
datetime_created: A DateTimeField indicating date of creation.
datetime_updated: A DateTimeField indicating date of update.
Expand Down Expand Up @@ -98,6 +99,7 @@ class Project(models.Model):
)

draft = models.BooleanField(blank=False, default=True)
is_company = models.BooleanField(null=False, default=False)

cover = models.ForeignKey(
UserFile,
Expand Down Expand Up @@ -135,7 +137,7 @@ def __str__(self):
return f"Project<{self.id}> - {self.name}"

class Meta:
ordering = ["-hidden_score", "-datetime_created"]
ordering = ["-is_company", "-hidden_score", "-datetime_created"]
verbose_name = "Проект"
verbose_name_plural = "Проекты"

Expand Down
5 changes: 4 additions & 1 deletion projects/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class Meta:
"collaborators",
"leader",
"draft",
"is_company",
"vacancies",
"datetime_created",
"datetime_updated",
Expand All @@ -134,6 +135,7 @@ class Meta:
"views_count",
"datetime_created",
"datetime_updated",
"is_company",
]


Expand All @@ -159,9 +161,10 @@ class Meta:
"image_address",
"industry",
"views_count",
"is_company",
]

read_only_fields = ["leader", "views_count"]
read_only_fields = ["leader", "views_count", "is_company"]

def is_valid(self, *, raise_exception=False):
return super().is_valid(raise_exception=raise_exception)
Expand Down
9 changes: 6 additions & 3 deletions users/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,9 @@ class Meta:
"industry",
"views_count",
"collaborator",
"is_company",
]
read_only_fields = ["leader", "collaborator"]
read_only_fields = ["leader", "collaborator", "is_company"]


class UserSubscribedProjectsSerializer(serializers.ModelSerializer[Project]):
Expand All @@ -170,8 +171,9 @@ class Meta:
"image_address",
"industry",
"views_count",
"is_company",
]
read_only_fields = ["leader", "collaborator"]
read_only_fields = ["leader", "collaborator", "is_company"]


class SubscriptionSerializer(serializers.Serializer):
Expand Down Expand Up @@ -475,9 +477,10 @@ class Meta:
"industry",
"views_count",
"draft",
"is_company",
]

read_only_fields = ["leader", "views_count"]
read_only_fields = ["leader", "views_count", "is_company"]

def is_valid(self, *, raise_exception=False):
return super().is_valid(raise_exception=raise_exception)
Expand Down
11 changes: 8 additions & 3 deletions vacancy/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class Meta:
"name",
"description",
"image_address",
"is_company",
]


Expand Down Expand Up @@ -135,9 +136,10 @@ class Meta:
"image_address",
"industry",
"views_count",
"is_company",
]

read_only_fields = ["leader", "views_count"]
read_only_fields = ["leader", "views_count", "is_company"]

def is_valid(self, *, raise_exception=False):
return super().is_valid(raise_exception=raise_exception)
Expand All @@ -152,8 +154,6 @@ class ProjectVacancyCreateListSerializer(
AbstractVacancyReadOnlyFields,
RequiredSkillsWriteSerializerMixin[Vacancy],
):
# TODO FIX This
project = ProjectListSerializer_TODO_FIX()

def create(self, validated_data):
project = validated_data["project"]
Expand Down Expand Up @@ -185,6 +185,11 @@ def create(self, validated_data):

return vacancy

def to_representation(self, instance):
ret = super().to_representation(instance)
ret["project"] = ProjectListSerializer_TODO_FIX(instance.project).data
return ret

class Meta:
model = Vacancy
fields = [
Expand Down
2 changes: 1 addition & 1 deletion vacancy/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def test_vacancy_creation(self):
)
self.assertEqual(response.data["description"], "Test")
self.assertEqual(response.data["is_active"], not self.created_project.draft)
self.assertEqual(response.data["project"], self.vacancy_create_data["project"])
self.assertEqual(response.data["project"]["id"], self.vacancy_create_data["project"])

def user_create(self):
request = self.factory.post("auth/users/", USER_CREATE_DATA)
Expand Down

0 comments on commit e385ff1

Please sign in to comment.