interview results added

This commit is contained in:
Faheed 2025-12-15 15:52:51 +03:00
parent b72ab43a5e
commit fcc382d8f3
11 changed files with 188 additions and 83 deletions

View File

@ -1496,6 +1496,7 @@ class MessageForm(forms.ModelForm):
self.helper.form_class = "g-3" self.helper.form_class = "g-3"
self._filter_recipient_field() self._filter_recipient_field()
self._filter_job_field()
self.helper.layout = Layout( self.helper.layout = Layout(
Row( Row(
@ -1516,6 +1517,7 @@ class MessageForm(forms.ModelForm):
"""Filter job options based on user type""" """Filter job options based on user type"""
if self.user.user_type == "agency": if self.user.user_type == "agency":
print("jhjkshfjksd")
job_assignments =AgencyJobAssignment.objects.filter( job_assignments =AgencyJobAssignment.objects.filter(
agency__user=self.user, agency__user=self.user,
@ -1528,11 +1530,18 @@ class MessageForm(forms.ModelForm):
print("Agency user job queryset:", self.fields["job"].queryset) print("Agency user job queryset:", self.fields["job"].queryset)
elif self.user.user_type == "candidate": elif self.user.user_type == "candidate":
print("sjhdakjhsdkjashkdjhskd")
# Candidates can only see jobs they applied for # Candidates can only see jobs they applied for
person=self.user.person_profile
print(person)
applications=person.applications.all()
print(applications)
self.fields["job"].queryset = JobPosting.objects.filter( self.fields["job"].queryset = JobPosting.objects.filter(
applications__person=self.user.person_profile, applications__in=applications,
).distinct().order_by("-created_at") ).distinct().order_by("-created_at")
else: else:
print("shhadjkhkd")
# Staff can see all jobs # Staff can see all jobs
self.fields["job"].queryset = JobPosting.objects.filter( self.fields["job"].queryset = JobPosting.objects.filter(
status="ACTIVE" status="ACTIVE"
@ -2145,3 +2154,22 @@ KAAUH Hiring Team
self.fields['message'].initial = initial_message self.fields['message'].initial = initial_message
class InterviewResultForm(forms.ModelForm):
class Meta:
model = Interview
fields = ['interview_result', 'result_comments']
widgets = {
'interview_result': forms.Select(attrs={
'class': 'form-select', # Standard Bootstrap class
'required': 'required'
}),
'result_comments': forms.Textarea(attrs={
'class': 'form-control',
'rows': 3,
'placeholder': 'Enter setting value',
'required': True
}),
}

View File

@ -0,0 +1,23 @@
# Generated by Django 5.2.7 on 2025-12-15 12:03
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('recruitment', '0002_alter_source_name_alter_source_source_type'),
]
operations = [
migrations.AddField(
model_name='interview',
name='interview_result',
field=models.CharField(blank=True, choices=[('passed', 'Passed'), ('failed', 'Failed'), ('on_hold', 'ON Hold')], default='on_hold', max_length=10, null=True, verbose_name='Interview Result'),
),
migrations.AddField(
model_name='interview',
name='result_comments',
field=models.TextField(blank=True, null=True),
),
]

View File

@ -1123,12 +1123,29 @@ class Interview(Base):
ENDED = "ended", _("Ended") ENDED = "ended", _("Ended")
CANCELLED = "cancelled", _("Cancelled") CANCELLED = "cancelled", _("Cancelled")
class InterviewResult(models.TextChoices):
PASSED="passed",_("Passed")
FAILED="failed",_("Failed")
ON_HOLD="on_hold",_("ON Hold")
location_type = models.CharField( location_type = models.CharField(
max_length=10, max_length=10,
choices=LocationType.choices, choices=LocationType.choices,
verbose_name=_("Location Type"), verbose_name=_("Location Type"),
db_index=True, db_index=True,
) )
interview_result=models.CharField(
max_length=10,
choices=InterviewResult.choices,
verbose_name=_("Interview Result"),
null=True,
blank=True,
default='on_hold'
)
result_comments=models.TextField(
null=True,
blank=True
)
# Common fields # Common fields
topic = models.CharField( topic = models.CharField(

View File

@ -56,34 +56,34 @@ class EmailService:
return 0 return 0
def send_single_email( # def send_single_email(
self, # self,
user: User, # user: User,
subject: str, # subject: str,
template_name: str, # template_name: str,
context: dict, # context: dict,
from_email: str = settings.DEFAULT_FROM_EMAIL # from_email: str = settings.DEFAULT_FROM_EMAIL
) -> int: # ) -> int:
""" # """
Sends a single, template-based email to one user. # Sends a single, template-based email to one user.
""" # """
recipient_list = [user.email] # recipient_list = [user.email]
# 1. Render content from template # # 1. Render content from template
html_content = render_to_string(template_name, context) # html_content = render_to_string(template_name, context)
# You can optionally render a plain text version as well: # # You can optionally render a plain text version as well:
# text_content = strip_tags(html_content) # # text_content = strip_tags(html_content)
# 2. Call internal sender # # 2. Call internal sender
return self._send_email_internal( # return self._send_email_internal(
subject=subject, # subject=subject,
body="", # Can be empty if html_content is provided # body="", # Can be empty if html_content is provided
recipient_list=recipient_list, # recipient_list=recipient_list,
from_email=from_email, # from_email=from_email,
html_content=html_content # html_content=html_content
) # )
def send_bulk_email( def send_email_service(
self, self,
recipient_emails: List[str], recipient_emails: List[str],
subject: str, subject: str,

View File

@ -1534,7 +1534,7 @@ def send_job_closed_notification(job_id):
) )
def send_bulk_email_task( def send_email_task(
recipient_emails, recipient_emails,
subject: str, subject: str,
template_name: str, template_name: str,
@ -1551,7 +1551,7 @@ def send_bulk_email_task(
service = EmailService() service = EmailService()
# Execute the bulk sending method # Execute the bulk sending method
processed_count = service.send_bulk_email( processed_count = service.send_email_service(
recipient_emails=recipient_emails, recipient_emails=recipient_emails,
subject=subject, subject=subject,
template_name=template_name, template_name=template_name,
@ -1565,33 +1565,33 @@ def send_bulk_email_task(
"message": f"Attempted to send email to {len(recipient_emails)} recipients. Service reported processing {processed_count}." "message": f"Attempted to send email to {len(recipient_emails)} recipients. Service reported processing {processed_count}."
}) })
def send_single_email_task( # def send_single_email_task(
recipient_emails, # recipient_emails,
subject: str, # subject: str,
template_name: str, # template_name: str,
context: dict, # context: dict,
) -> str: # ) -> str:
""" # """
Django-Q task to send a bulk email asynchronously. # Django-Q task to send a bulk email asynchronously.
""" # """
from .services.email_service import EmailService # from .services.email_service import EmailService
if not recipient_emails: # if not recipient_emails:
return json.dumps({"status": "error", "message": "No recipients provided."}) # return json.dumps({"status": "error", "message": "No recipients provided."})
service = EmailService() # service = EmailService()
# Execute the bulk sending method # # Execute the bulk sending method
processed_count = service.send_bulk_email( # processed_count = service.send_bulk_email(
recipient_emails=recipient_emails, # recipient_emails=recipient_emails,
subject=subject, # subject=subject,
template_name=template_name, # template_name=template_name,
context=context, # context=context,
) # )
# The return value is stored in the result object for monitoring # # The return value is stored in the result object for monitoring
return json.dumps({ # return json.dumps({
"status": "success", # "status": "success",
"count": processed_count, # "count": processed_count,
"message": f"Attempted to send email to {len(recipient_emails)} recipients. Service reported processing {processed_count}." # "message": f"Attempted to send email to {len(recipient_emails)} recipients. Service reported processing {processed_count}."
}) # })

View File

@ -83,6 +83,8 @@ urlpatterns = [
path("interviews/", views.interview_list, name="interview_list"), path("interviews/", views.interview_list, name="interview_list"),
path("interviews/<slug:slug>/", views.interview_detail, name="interview_detail"), path("interviews/<slug:slug>/", views.interview_detail, name="interview_detail"),
path("interviews/<slug:slug>/update_interview_status", views.update_interview_status, name="update_interview_status"), path("interviews/<slug:slug>/update_interview_status", views.update_interview_status, name="update_interview_status"),
path("interviews/<slug:slug>/update_interview_result", views.update_interview_result, name="update_interview_result"),
path("interviews/<slug:slug>/cancel_interview_for_application", views.cancel_interview_for_application, name="cancel_interview_for_application"), path("interviews/<slug:slug>/cancel_interview_for_application", views.cancel_interview_for_application, name="cancel_interview_for_application"),
path("interview/<slug:slug>/interview-email/",views.send_interview_email,name="send_interview_email"), path("interview/<slug:slug>/interview-email/",views.send_interview_email,name="send_interview_email"),

View File

@ -94,6 +94,7 @@ from .forms import (
InterviewCancelForm, InterviewCancelForm,
InterviewEmailForm, InterviewEmailForm,
ApplicationStageForm, ApplicationStageForm,
InterviewResultForm
) )
from .utils import generate_random_password from .utils import generate_random_password
from django.views.decorators.csrf import csrf_exempt from django.views.decorators.csrf import csrf_exempt
@ -1764,6 +1765,7 @@ def _handle_confirm_schedule(request, slug, job):
for i, application in enumerate(applications): for i, application in enumerate(applications):
if i < len(available_slots): if i < len(available_slots):
slot = available_slots[i] slot = available_slots[i]
# schedule=ScheduledInterview.objects.create(application=application,job=job)
async_task( async_task(
"recruitment.tasks.create_interview_and_meeting", "recruitment.tasks.create_interview_and_meeting",
application.pk, application.pk,
@ -2141,6 +2143,7 @@ def reschedule_meeting_for_application(request, slug):
if request.method == "POST": if request.method == "POST":
if interview.location_type == "Remote": if interview.location_type == "Remote":
form = ScheduledInterviewForm(request.POST) form = ScheduledInterviewForm(request.POST)
else: else:
form = OnsiteScheduleInterviewUpdateForm(request.POST) form = OnsiteScheduleInterviewUpdateForm(request.POST)
@ -3056,6 +3059,8 @@ def applicant_portal_dashboard(request):
# Get candidate's documents using the Person documents property # Get candidate's documents using the Person documents property
documents = applicant.documents.order_by("-created_at") documents = applicant.documents.order_by("-created_at")
print(documents)
# Add password change form for modal # Add password change form for modal
password_form = PasswordResetForm() password_form = PasswordResetForm()
@ -3683,7 +3688,7 @@ def message_create(request):
subject=message.subject subject=message.subject
email_result=async_task( email_result=async_task(
"recruitment.tasks.send_bulk_email_task", "recruitment.tasks.send_email_task",
email_addresses, email_addresses,
subject, subject,
# message, # message,
@ -3750,7 +3755,7 @@ def message_create(request):
and "HX-Request" in request.headers and "HX-Request" in request.headers
and request.user.user_type in ["candidate", "agency"] and request.user.user_type in ["candidate", "agency"]
): ):
print()
job_id = request.GET.get("job") job_id = request.GET.get("job")
if job_id: if job_id:
job = get_object_or_404(JobPosting, id=job_id) job = get_object_or_404(JobPosting, id=job_id)
@ -4252,7 +4257,7 @@ def cancel_interview_for_application(request, slug):
Handles POST request to cancel an interview, setting the status Handles POST request to cancel an interview, setting the status
and saving the form data (likely a reason for cancellation). and saving the form data (likely a reason for cancellation).
""" """
scheduled_interview = get_object_or_404(ScheduledInterview) scheduled_interview = get_object_or_404(ScheduledInterview,slug=slug)
form = InterviewCancelForm(request.POST, instance=scheduled_interview) form = InterviewCancelForm(request.POST, instance=scheduled_interview)
if form.is_valid(): if form.is_valid():
@ -4276,6 +4281,33 @@ def cancel_interview_for_application(request, slug):
return redirect("interview_detail", slug=scheduled_interview.slug) return redirect("interview_detail", slug=scheduled_interview.slug)
@require_POST
@login_required # Assuming this should be protected
@staff_user_required # Assuming only staff can cancel
def update_interview_result(request,slug):
interview = get_object_or_404(Interview,slug=slug)
schedule=interview.scheduled_interview
form = InterviewResultForm(request.POST, instance=interview)
if form.is_valid():
interview.save(update_fields=['interview_result', 'result_comments'])
form.save() # Saves form data
messages.success(request, _("Interview cancelled successfully."))
return redirect("interview_detail", slug=schedule.slug)
else:
error_list = [
f"{field}: {', '.join(errors)}" for field, errors in form.errors.items()
]
error_message = _("Please correct the following errors: ") + " ".join(
error_list
)
messages.error(request, error_message)
return redirect("interview_detail", slug=schedule.slug)
@login_required @login_required
@staff_user_required @staff_user_required
def agency_access_link_deactivate(request, slug): def agency_access_link_deactivate(request, slug):
@ -4724,6 +4756,7 @@ def application_signup(request, slug):
@login_required @login_required
@staff_user_required @staff_user_required
def interview_list(request): def interview_list(request):
"""List all interviews with filtering and pagination""" """List all interviews with filtering and pagination"""
interviews = ScheduledInterview.objects.select_related( interviews = ScheduledInterview.objects.select_related(
"application", "application",
@ -4750,7 +4783,7 @@ def interview_list(request):
interviews = interviews.filter( interviews = interviews.filter(
Q(application__person__first_name=search_query) Q(application__person__first_name=search_query)
| Q(application__person__last_name__icontains=search_query) | Q(application__person__last_name__icontains=search_query)
| Q(application__person__email=search_query) | Q(application__person__email__icontains=search_query)
| Q(job__title__icontains=search_query) | Q(job__title__icontains=search_query)
) )
@ -4779,8 +4812,11 @@ def interview_detail(request, slug):
OnsiteScheduleInterviewUpdateForm, OnsiteScheduleInterviewUpdateForm,
) )
schedule = get_object_or_404(ScheduledInterview, slug=slug) schedule = get_object_or_404(ScheduledInterview, slug=slug)
interview = schedule.interview interview = schedule.interview
interview_result_form=InterviewResultForm(instance=interview)
application = schedule.application application = schedule.application
job = schedule.job job = schedule.job
print(interview.location_type) print(interview.location_type)
@ -4803,6 +4839,7 @@ def interview_detail(request, slug):
"interview_status_form": ScheduledInterviewUpdateStatusForm(), "interview_status_form": ScheduledInterviewUpdateStatusForm(),
"cancel_form": InterviewCancelForm(instance=meeting), "cancel_form": InterviewCancelForm(instance=meeting),
"interview_email_form": interview_email_form, "interview_email_form": interview_email_form,
"interview_result_form":interview_result_form,
} }
return render(request, "interviews/interview_detail.html", context) return render(request, "interviews/interview_detail.html", context)
@ -6486,7 +6523,7 @@ def send_interview_email(request, slug):
# 2. Match the context expected by your task/service # 2. Match the context expected by your task/service
# We pass IDs for the sender/job to avoid serialization issues # We pass IDs for the sender/job to avoid serialization issues
async_task( async_task(
"recruitment.tasks.send_bulk_email_task", "recruitment.tasks.send_email_task",
recipient_list, recipient_list,
subject, subject,
"emails/email_template.html", "emails/email_template.html",
@ -6558,7 +6595,7 @@ def compose_application_email(request, slug):
async_task( async_task(
"recruitment.tasks.send_bulk_email_task", "recruitment.tasks.send_email_task",
email_addresses, email_addresses,
subject, subject,
# message, # message,

View File

@ -360,6 +360,7 @@
</form> </form>
{% endif %} {% endif %}
</li> </li>
{% if request.user.is_authenticated%}
<li class="nav-item dropdown"> <li class="nav-item dropdown">
<button class="language-toggle-btn dropdown-toggle" type="button" <button class="language-toggle-btn dropdown-toggle" type="button"
data-bs-toggle="dropdown" data-bs-offset="0, 8" aria-expanded="false" data-bs-toggle="dropdown" data-bs-offset="0, 8" aria-expanded="false"
@ -410,12 +411,14 @@
<i class="fas fa-tachometer-alt me-3 fs-5"></i> <span>{% trans "Dashboard" %}</span> <i class="fas fa-tachometer-alt me-3 fs-5"></i> <span>{% trans "Dashboard" %}</span>
</a> </a>
</li> </li>
<li> <li>
<a class="dropdown-item py-2 px-4 d-flex align-items-center text-decoration-none text-primary-theme" href="{% url 'user_detail' request.user.pk %}" > <a class="dropdown-item py-2 px-4 d-flex align-items-center text-decoration-none text-primary-theme" href="{% url 'user_detail' request.user.pk %}" >
<i class="fas fa-user-circle me-3 fs-5"></i> <span>{% trans "My Profile" %}</span> <i class="fas fa-user-circle me-3 fs-5"></i> <span>{% trans "My Profile" %}</span>
</a> </a>
</li> </li>
<li><hr class="dropdown-divider my-1"></li> <li><hr class="dropdown-divider my-1"></li>
<li> <li>
<form method="post" action="{% url 'account_logout'%}" class="d-inline"> <form method="post" action="{% url 'account_logout'%}" class="d-inline">
@ -432,6 +435,8 @@
</li> </li>
</ul> </ul>
</li> </li>
{% endif %}
</ul> </ul>
</div> </div>
</div> </div>

View File

@ -670,22 +670,9 @@
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div> </div>
<div class="modal-body"> <div class="modal-body">
<form method="post" action="#"> <form method="post" action="{% url 'update_interview_result' interview.slug %}">
{% csrf_token %} {% csrf_token %}
<div class="mb-3"> {{interview_result_form|crispy}}
<label for="interview_result" class="form-label">{% trans "Interview Result" %}</label>
<select class="form-select" id="interview_result" name="result" required>
<option value="">{% trans "Select Result" %}</option>
<option value="passed">{% trans "Passed" %}</option>
<option value="failed">{% trans "Failed" %}</option>
<option value="on_hold">{% trans "On Hold" %}</option>
</select>
</div>
<div class="mb-3">
<label for="result_notes" class="form-label">{% trans "Notes" %}</label>
<textarea class="form-control" id="result_notes" name="notes" rows="4"
placeholder="{% trans 'Add interview feedback and notes' %}"></textarea>
</div>
<button type="submit" class="btn btn-main-action btn-sm mt-2"> <button type="submit" class="btn btn-main-action btn-sm mt-2">
<i class="fas fa-check me-1"></i> {% trans "Update Result" %} <i class="fas fa-check me-1"></i> {% trans "Update Result" %}
</button> </button>

View File

@ -502,7 +502,7 @@
- -
{% endif %} {% endif %}
</td> </td>
<td> <td id="document-{{ document.id }}">
{% if document.file %} {% if document.file %}
<a href="{{ document.file.url }}" <a href="{{ document.file.url }}"
class="btn btn-sm btn-outline-primary me-1" class="btn btn-sm btn-outline-primary me-1"
@ -510,7 +510,13 @@
<i class="fas fa-download"></i> <i class="fas fa-download"></i>
{% trans "Download" %} {% trans "Download" %}
</a> </a>
<button class="btn btn-sm btn-outline-danger" onclick="deleteDocument({{ document.id }})">
<button hx-post="{% url 'document_delete' document.pk %}"
hx-target="#document-{{ document.id }}"
hx-swap="outerHTML"
hx-confirm="{% trans 'Are you sure you want to delete this file?' %}"
class="btn btn-sm btn-danger">
<i class="fas fa-trash"></i> <i class="fas fa-trash"></i>
</button> </button>
{% endif %} {% endif %}
@ -657,7 +663,7 @@ function addToCalendar(year, month, day, time, title) {
window.open(googleCalendarUrl, '_blank'); window.open(googleCalendarUrl, '_blank');
} }
{% comment %}
function deleteDocument(documentId) { function deleteDocument(documentId) {
if (confirm('{% trans "Are you sure you want to delete this document?" %}')) { if (confirm('{% trans "Are you sure you want to delete this document?" %}')) {
fetch(`/documents/${documentId}/delete/`, { fetch(`/documents/${documentId}/delete/`, {
@ -696,7 +702,7 @@ function getCookie(name) {
} }
} }
return cookieValue; return cookieValue;
} } {% endcomment %}
</script> </script>
{% endblock %} {% endblock %}

View File

@ -572,7 +572,7 @@
<a href="{{ document.file.url }}" target="_blank" class="btn btn-sm btn-outline-secondary me-2"><i class="fas fa-eye"></i></a> <a href="{{ document.file.url }}" target="_blank" class="btn btn-sm btn-outline-secondary me-2"><i class="fas fa-eye"></i></a>
{# HTMX DELETE BUTTON #} {# HTMX DELETE BUTTON #}
<button hx-post="{% url 'application_document_delete' document.id %}" <button hx-post="{% url 'document_delete' document.pk %}"
hx-target="#document-{{ document.id }}" hx-target="#document-{{ document.id }}"
hx-swap="outerHTML" hx-swap="outerHTML"
hx-confirm="{% trans 'Are you sure you want to delete this file?' %}" hx-confirm="{% trans 'Are you sure you want to delete this file?' %}"