Skip to content

Commit

Permalink
Merge pull request #466 from PROCOLLAB-github/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
sh1nkey authored Oct 16, 2024
2 parents bbd53c0 + fd4ca8e commit 0dd6359
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
13 changes: 8 additions & 5 deletions project_rates/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class RateProject(generics.CreateAPIView):
serializer_class = ProjectScoreCreateSerializer
permission_classes = [IsExpertPost]

def get_needed_data(self) -> tuple[dict, list[int]]:
def get_needed_data(self) -> tuple[dict, list[int], str]:
data = self.request.data
user_id = self.request.user.id
project_id = self.kwargs.get("project_id")
Expand All @@ -36,18 +36,20 @@ def get_needed_data(self) -> tuple[dict, list[int]]:
criterion["criterion_id"] for criterion in data
] # is needed for validation later

Expert.objects.get(user__id=user_id, programs__criterias__id=criteria_to_get[0])
expert = Expert.objects.get(
user__id=user_id, programs__criterias__id=criteria_to_get[0]
)

for criterion in data:
criterion["user"] = user_id
criterion["project"] = project_id
criterion["criteria"] = criterion.pop("criterion_id")

return data, criteria_to_get
return data, criteria_to_get, expert.programs.all().first().name

def create(self, request, *args, **kwargs) -> Response:
try:
data, criteria_to_get = self.get_needed_data()
data, criteria_to_get, program_name = self.get_needed_data()

serializer = ProjectScoreCreateSerializer(
data=data, criteria_to_get=criteria_to_get, many=True
Expand All @@ -66,10 +68,11 @@ def create(self, request, *args, **kwargs) -> Response:
send_email.delay(
ProjectRatedParams(
message_type=MessageTypeEnum.PROJECT_RATED.value,
user_id=project.leader.name,
user_id=project.leader.id,
project_name=project.name,
project_id=project.id,
schema_id=2,
program_name=program_name,
)
)

Expand Down
4 changes: 3 additions & 1 deletion users/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from weasyprint import HTML

from procollab.celery import app
from procollab.settings import EMAIL_USER
from users.typing import UserCVData
from users.services.cv_data_prepare import UserCVDataPreparer

Expand All @@ -24,8 +25,9 @@ def send_mail_cv(user_id: int, user_email: str, filename: str):
template_content = f.read()

email = EmailMessage(
subject='Procollab | Резюме',
subject="Procollab | Резюме",
body=template_content,
from_email=EMAIL_USER,
to=[user_email],
)
email.content_subtype = "html"
Expand Down
1 change: 1 addition & 0 deletions vacancy/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class ProjectRatedParams(BaseEmailCeleryParams):
MessageTypeEnum.OUTDATED.value: "У вашей вакансии истёк срок годности",
MessageTypeEnum.REJECTED.value: "На ваш отклик ответили отказом",
MessageTypeEnum.REGISTERED_PROGRAM_USER.value: "Вы зарегистрировались на программу",
MessageTypeEnum.PROJECT_RATED.value: "Ваш проект был оценён",
}


Expand Down
3 changes: 2 additions & 1 deletion vacancy/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
get_link,
MessageTypeEnum,
message_type_to_title,
EmailParamsType,
)
from vacancy.models import Vacancy


@app.task
def send_email(data: CeleryEmailParams):
def send_email(data: EmailParamsType):
context_data = ContextDataDict(
text=create_text_for_email(data),
title=message_type_to_title[data["message_type"]],
Expand Down

0 comments on commit 0dd6359

Please sign in to comment.