CBV code updates: 26th March
This commit is contained in:
@@ -46,4 +46,4 @@
|
||||
{% for field in form.hidden_fields %}
|
||||
{{ field }}
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -86,6 +86,9 @@ class OnboardingCandidatesList(HorillaListView):
|
||||
("Recruitment", "recruitment_id"),
|
||||
("Offer letter", "offer_letter"),
|
||||
]
|
||||
header_attrs = {
|
||||
"action": "style='width: 350px;'",
|
||||
}
|
||||
|
||||
action_method = "actions"
|
||||
|
||||
|
||||
@@ -13,6 +13,49 @@
|
||||
color: white;" {% endif %} type="button" hx-get="{% url 'add-to-rejected-candidates' %}?candidate_id={{instance.id}}" {% if instance.is_offer_rejected %} title="{% trans "Added In Rejected Candidates" %}" {% else %} title="{% trans "Add To Rejected Candidates" %}" {% endif %} hx-target="#genericModalBody" hx-swap="innerHTML" class="oh-btn oh-btn--light w-100" data-toggle="oh-modal-toggle" data-target="#genericModal" >
|
||||
<ion-icon name="thumbs-down-outline"></ion-icon></button>
|
||||
{% endif %}
|
||||
{% if not instance.onboarding_stage %}
|
||||
<form hx-post="{% url 'email-send' %}?&no_portal=True" hx-target="#reloadMessages">
|
||||
<a class="oh-btn oh-btn--light-bkg w-100"
|
||||
onclick="
|
||||
event.preventDefault()
|
||||
Swal.fire({
|
||||
title: 'Are you sure?',
|
||||
text: '{% trans "Do you want to add this candidate to onboarding stage?" %}',
|
||||
icon: 'question',
|
||||
showCancelButton: true,
|
||||
confirmButtonText: '{% trans "Yes" %}',
|
||||
cancelButtonText: '{% trans "Cancel" %}'
|
||||
}).then((result) => {
|
||||
if (result.isConfirmed) {
|
||||
this.nextElementSibling.nextElementSibling.click();
|
||||
}
|
||||
})"
|
||||
{% comment %} style="background-color: yellowgreen;color: white;" {% endcomment %}
|
||||
title="{% trans 'Start Onboarding' %}"
|
||||
>
|
||||
<ion-icon name="add-outline"></ion-icon>
|
||||
</a>
|
||||
<input type="text" hidden name="ids" value="{{instance.pk}}">
|
||||
<input type="submit" hidden>
|
||||
</form>
|
||||
{% else %}
|
||||
<a class="oh-btn w-100"
|
||||
disabled
|
||||
onclick="
|
||||
event.preventDefault();
|
||||
Swal.fire({
|
||||
icon: 'warning',
|
||||
title: '{% trans "Already Added!" %}',
|
||||
text: '{% trans "Candidate already added to onboarding" %}.',
|
||||
confirmButtonText: 'OK'
|
||||
});
|
||||
"
|
||||
style="background-color: #1dbfca;color: white;"
|
||||
title="{% trans 'Added to Onobarding' %}"
|
||||
>
|
||||
<ion-icon name="add-outline"></ion-icon>
|
||||
</a>
|
||||
{% endif %}
|
||||
{% if instance.onboarding_portal %}
|
||||
<a href="#" class="oh-btn w-100" style="background-color: yellowgreen;color: white;"
|
||||
title="{% trans 'Send Portal / Start Onboarding' %}" onclick="$('select[name=ids]').val('{{instance.id}}');"
|
||||
|
||||
@@ -670,62 +670,65 @@ def email_send(request):
|
||||
for cand_id in candidates:
|
||||
attachments = list(set(attachments_other) | set([]))
|
||||
candidate = Candidate.objects.get(id=cand_id)
|
||||
if candidate.converted_employee_id:
|
||||
messages.info(
|
||||
request, _(f"{candidate} has already been converted to employee.")
|
||||
)
|
||||
continue
|
||||
for html in bodys:
|
||||
# due to not having solid template we first need to pass the context
|
||||
template_bdy = template.Template(html)
|
||||
context = template.Context(
|
||||
{"instance": candidate, "self": request.user.employee_get}
|
||||
)
|
||||
render_bdy = template_bdy.render(context)
|
||||
attachments.append(
|
||||
(
|
||||
"Document",
|
||||
generate_pdf(render_bdy, {}, path=False, title="Document").content,
|
||||
"application/pdf",
|
||||
if not request.GET["no_portal"]:
|
||||
if candidate.converted_employee_id:
|
||||
messages.info(
|
||||
request, _(f"{candidate} has already been converted to employee.")
|
||||
)
|
||||
continue
|
||||
for html in bodys:
|
||||
# due to not having solid template we first need to pass the context
|
||||
template_bdy = template.Template(html)
|
||||
context = template.Context(
|
||||
{"instance": candidate, "self": request.user.employee_get}
|
||||
)
|
||||
render_bdy = template_bdy.render(context)
|
||||
attachments.append(
|
||||
(
|
||||
"Document",
|
||||
generate_pdf(
|
||||
render_bdy, {}, path=False, title="Document"
|
||||
).content,
|
||||
"application/pdf",
|
||||
)
|
||||
)
|
||||
token = secrets.token_hex(15)
|
||||
existing_portal = OnboardingPortal.objects.filter(candidate_id=candidate)
|
||||
if existing_portal.exists():
|
||||
new_portal = existing_portal.first()
|
||||
new_portal.token = token
|
||||
new_portal.used = False
|
||||
new_portal.count = 0
|
||||
new_portal.profile = None
|
||||
new_portal.save()
|
||||
else:
|
||||
OnboardingPortal(candidate_id=candidate, token=token).save()
|
||||
html_message = render_to_string(
|
||||
"onboarding/mail_templates/default.html",
|
||||
{
|
||||
"portal": f"{protocol}://{host}/onboarding/user-creation/{token}",
|
||||
"instance": candidate,
|
||||
"host": host,
|
||||
"protocol": protocol,
|
||||
},
|
||||
request=request,
|
||||
)
|
||||
token = secrets.token_hex(15)
|
||||
existing_portal = OnboardingPortal.objects.filter(candidate_id=candidate)
|
||||
if existing_portal.exists():
|
||||
new_portal = existing_portal.first()
|
||||
new_portal.token = token
|
||||
new_portal.used = False
|
||||
new_portal.count = 0
|
||||
new_portal.profile = None
|
||||
new_portal.save()
|
||||
else:
|
||||
OnboardingPortal(candidate_id=candidate, token=token).save()
|
||||
html_message = render_to_string(
|
||||
"onboarding/mail_templates/default.html",
|
||||
{
|
||||
"portal": f"{protocol}://{host}/onboarding/user-creation/{token}",
|
||||
"instance": candidate,
|
||||
"host": host,
|
||||
"protocol": protocol,
|
||||
},
|
||||
request=request,
|
||||
)
|
||||
email = EmailMessage(
|
||||
subject=f"Hello {candidate.name}, Congratulations on your selection!",
|
||||
body=html_message,
|
||||
to=[candidate.email],
|
||||
)
|
||||
email.content_subtype = "html"
|
||||
email.attachments = attachments
|
||||
try:
|
||||
email.send()
|
||||
# to check ajax or not
|
||||
messages.success(request, "Portal link sent to the candidate")
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
messages.error(request, f"Mail not send to {candidate.name}")
|
||||
candidate.start_onboard = True
|
||||
candidate.save()
|
||||
email = EmailMessage(
|
||||
subject=f"Hello {candidate.name}, Congratulations on your selection!",
|
||||
body=html_message,
|
||||
to=[candidate.email],
|
||||
)
|
||||
email.content_subtype = "html"
|
||||
email.attachments = attachments
|
||||
try:
|
||||
email.send()
|
||||
# to check ajax or not
|
||||
messages.success(request, "Portal link sent to the candidate")
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
messages.error(request, f"Mail not send to {candidate.name}")
|
||||
candidate.start_onboard = True
|
||||
candidate.save()
|
||||
try:
|
||||
onboarding_candidate = CandidateStage()
|
||||
onboarding_candidate.onboarding_stage_id = (
|
||||
@@ -733,6 +736,7 @@ def email_send(request):
|
||||
)
|
||||
onboarding_candidate.candidate_id = candidate
|
||||
onboarding_candidate.save()
|
||||
messages.success(request, "Candidate Added to Onboarding Stage")
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user