From 123e791f9812512855ff6099f76b525def0b9051 Mon Sep 17 00:00:00 2001 From: Horilla Date: Fri, 28 Feb 2025 18:55:35 +0530 Subject: [PATCH] [UPDT] RECRUITMENT: Changed signals to signals.py --- recruitment/apps.py | 1 + recruitment/models.py | 60 ---------- recruitment/signals.py | 47 ++++++++ .../offerletter/empty_mail_template.html | 89 -------------- .../templates/offerletter/view_templates.html | 109 ------------------ 5 files changed, 48 insertions(+), 258 deletions(-) create mode 100644 recruitment/signals.py delete mode 100644 recruitment/templates/offerletter/empty_mail_template.html delete mode 100644 recruitment/templates/offerletter/view_templates.html diff --git a/recruitment/apps.py b/recruitment/apps.py index f73583cbb..abf3d4cb5 100644 --- a/recruitment/apps.py +++ b/recruitment/apps.py @@ -25,6 +25,7 @@ class RecruitmentConfig(AppConfig): from horilla.horilla_settings import APPS from horilla.urls import urlpatterns + from recruitment import signals APPS.append("recruitment") urlpatterns.append( diff --git a/recruitment/models.py b/recruitment/models.py index 7d76ad3d5..16f510779 100644 --- a/recruitment/models.py +++ b/recruitment/models.py @@ -246,27 +246,6 @@ class Recruitment(HorillaModel): return True -@receiver(post_save, sender=Recruitment) -def create_initial_stage(sender, instance, created, **kwargs): - """ - This is post save method, used to create initial stage for the recruitment - """ - if created: - applied_stage = Stage() - applied_stage.sequence = 0 - applied_stage.recruitment_id = instance - applied_stage.stage = "Applied" - applied_stage.stage_type = "applied" - applied_stage.save() - - initial_stage = Stage() - initial_stage.sequence = 1 - initial_stage.recruitment_id = instance - initial_stage.stage = "Initial" - initial_stage.stage_type = "initial" - initial_stage.save() - - class Stage(HorillaModel): """ Stage model @@ -617,9 +596,6 @@ class Candidate(HorillaModel): ordering = ["sequence"] -from horilla.signals import pre_bulk_update - - class RejectReason(HorillaModel): """ RejectReason @@ -820,21 +796,6 @@ class RecruitmentSurveyAnswer(HorillaModel): return f"{self.candidate_id.name}-{self.recruitment_id}" -class RecruitmentMailTemplate(HorillaModel): - title = models.CharField(max_length=25, unique=True) - body = models.TextField() - company_id = models.ForeignKey( - Company, - null=True, - blank=True, - on_delete=models.CASCADE, - verbose_name=_("Company"), - ) - - def __str__(self) -> str: - return f"{self.title}" - - class SkillZone(HorillaModel): """ " Model for talent pool @@ -1054,24 +1015,3 @@ class CandidateDocument(HorillaModel): raise ValidationError( {"document": _("Please upload {} file only.").format(format)} ) - - -@receiver(m2m_changed, sender=CandidateDocumentRequest.candidate_id.through) -def document_request_m2m_changed(sender, instance, action, **kwargs): - if action == "post_add": - candidate_document_create(instance) - - elif action == "post_remove": - candidate_document_create(instance) - - -def candidate_document_create(instance): - candidates = instance.candidate_id.all() - for candidate in candidates: - document, created = CandidateDocument.objects.get_or_create( - candidate_id=candidate, - document_request_id=instance, - defaults={"title": f"Upload {instance.title}"}, - ) - document.title = f"Upload {instance.title}" - document.save() diff --git a/recruitment/signals.py b/recruitment/signals.py new file mode 100644 index 000000000..02a3218e7 --- /dev/null +++ b/recruitment/signals.py @@ -0,0 +1,47 @@ + +from django.dispatch import receiver +from django.db.models.signals import post_save, m2m_changed +from recruitment.models import CandidateDocument, CandidateDocumentRequest, Recruitment, Stage + + +@receiver(post_save, sender=Recruitment) +def create_initial_stage(sender, instance, created, **kwargs): + """ + This is post save method, used to create initial stage for the recruitment + """ + if created: + applied_stage = Stage() + applied_stage.sequence = 0 + applied_stage.recruitment_id = instance + applied_stage.stage = "Applied" + applied_stage.stage_type = "applied" + applied_stage.save() + + initial_stage = Stage() + initial_stage.sequence = 1 + initial_stage.recruitment_id = instance + initial_stage.stage = "Initial" + initial_stage.stage_type = "initial" + initial_stage.save() + + +@receiver(m2m_changed, sender=CandidateDocumentRequest.candidate_id.through) +def document_request_m2m_changed(sender, instance, action, **kwargs): + if action == "post_add": + candidate_document_create(instance) + + elif action == "post_remove": + candidate_document_create(instance) + + +def candidate_document_create(instance): + candidates = instance.candidate_id.all() + for candidate in candidates: + document, created = CandidateDocument.objects.get_or_create( + candidate_id=candidate, + document_request_id=instance, + defaults={"title": f"Upload {instance.title}"}, + ) + document.title = f"Upload {instance.title}" + document.save() + diff --git a/recruitment/templates/offerletter/empty_mail_template.html b/recruitment/templates/offerletter/empty_mail_template.html deleted file mode 100644 index 35a1a45e6..000000000 --- a/recruitment/templates/offerletter/empty_mail_template.html +++ /dev/null @@ -1,89 +0,0 @@ -{% extends 'index.html' %} -{% load static %} -{% load i18n %} -{% block content %} - - -
-
-

{% trans "Mail Templates" %}

-
- {% if perms.recruitment.add_recruitmentmailtemplate %} - - {% endif %} -
-
- -
-
- Page not found. 404. -
{% trans "There are currently no email templates." %}
-
-
-
- - - - - -{% endblock content %} diff --git a/recruitment/templates/offerletter/view_templates.html b/recruitment/templates/offerletter/view_templates.html deleted file mode 100644 index 66153a3fe..000000000 --- a/recruitment/templates/offerletter/view_templates.html +++ /dev/null @@ -1,109 +0,0 @@ -{% extends 'index.html' %} -{% load static %} -{% load i18n %} -{% block content %} - - -
-
-

{% trans "Mail Templates" %}

-
- {% if perms.recruitment.add_recruitmentmailtemplate %} - - {% endif %} -
- -
- {% for template in templates %} -
- {% if perms.recruitment.delete_recruitmentmailtemplate %} -

{{ template.title }} -
- - - - - - -
-

- {% endif %} - {% if perms.recruitment.change_recruitmentmailtemplate %} - - {% endif %} -
-
{{ template.body|safe }}
-
- {% if perms.recruitment.change_recruitmentmailtemplate %} - {% trans "View Template" %} - {% endif %} -
- {% endfor %} -
- - - - -{% endblock %}