diff --git a/recruitment/forms.py b/recruitment/forms.py index 9f9aad8f3..77dde09e1 100644 --- a/recruitment/forms.py +++ b/recruitment/forms.py @@ -851,7 +851,11 @@ class SurveyForm(forms.Form): def __init__(self, recruitment, *args, **kwargs) -> None: super().__init__(recruitment, *args, **kwargs) questions = recruitment.recruitmentsurvey_set.all() - context = {"form": self, "questions": questions} + all_questions = RecruitmentSurvey.objects.none() | questions + for template in recruitment.survey_templates.all(): + questions = template.recruitmentsurvey_set.all() + all_questions = all_questions | questions + context = {"form": self, "questions": all_questions.distinct()} form = render_to_string("survey_form.html", context) self.form = form return @@ -859,6 +863,22 @@ class SurveyForm(forms.Form): # self +class SurveyPreviewForm(forms.Form): + """ + SurveyTemplateForm + """ + + def __init__(self, template, *args, **kwargs) -> None: + super().__init__(template, *args, **kwargs) + all_questions = RecruitmentSurvey.objects.filter(template_id__in=[template]) + context = {"form": self, "questions": all_questions.distinct()} + form = render_to_string("survey_preview_form.html", context) + self.form = form + return + # for question in questions: + # self + + class TemplateForm(ModelForm): """ TemplateForm diff --git a/recruitment/templates/survey/survey_preview.html b/recruitment/templates/survey/survey_preview.html new file mode 100644 index 000000000..ba63aa7af --- /dev/null +++ b/recruitment/templates/survey/survey_preview.html @@ -0,0 +1,24 @@ +{% extends 'index.html' %} +{% block content %} +{% load i18n %} +{% if messages %} +
+ {% for message in messages %} +
+ {{ message }} +
+ {% endfor %} +
+{% endif %} +
+
+ {% csrf_token %} +
+

+ {{template}} {% trans "Survey" %} +

+
+ {{form}} +
+
+{% endblock content %} diff --git a/recruitment/templates/survey/template_accordion.html b/recruitment/templates/survey/template_accordion.html index 11801330e..9c1e95435 100644 --- a/recruitment/templates/survey/template_accordion.html +++ b/recruitment/templates/survey/template_accordion.html @@ -23,12 +23,15 @@ {% elif question.type == "options" %} -
- {% if question.is_mandatory %} - {{ question.question }} * {% trans "Mandatory Question" %} - {% else %} - {{ question.question }} - {% endif %} - +
+ {% if question.is_mandatory %} + {{ question.question }} * {% trans "Mandatory Question" %} + {% else %} + {{ question.question }} + {% endif %} + +
{% elif question.type == "multiple" %}
{% if question.is_mandatory %} @@ -125,12 +126,14 @@ />
{% elif question.type == "rating" %} - {% if question.is_mandatory %} - {{ question.question }} * {% trans "Mandatory Question" %} - {% else %} - {{ question.question }} - {% endif %} - {% include "rating_input.html" %} +
+ {% if question.is_mandatory %} + {{ question.question }} * {% trans "Mandatory Question" %} + {% else %} + {{ question.question }} + {% endif %} + {% include "rating_input.html" %} +
{% elif question.type == "checkbox" %}
{% if question.is_mandatory %} diff --git a/recruitment/templates/survey_preview_form.html b/recruitment/templates/survey_preview_form.html new file mode 100644 index 000000000..b674b78f3 --- /dev/null +++ b/recruitment/templates/survey_preview_form.html @@ -0,0 +1,298 @@ +{% load i18n %}{% load widget_tweaks %} {% load attendancefilters %} +{% load static %} + +
+
+
+
+
+
{{form.non_field_errors}}
+ + {% for question in questions %} + + {% if question.type == "textarea" %} +
+
+ +
+
+ {% if question.is_mandatory %} + {{ question.question }} * {% trans "Mandatory Question" %} + {% else %} + {{ question.question }} + {% endif %} + +
+
+ {% elif question.type == "options" %} +
+
+ +
+
+ {% if question.is_mandatory %} + {{ question.question }} * {% trans "Mandatory Question" %} + {% else %} + {{ question.question }} + {% endif %} + +
+
+ {% elif question.type == "multiple" %} +
+
+ +
+
+ {% if question.is_mandatory %} + {{ question.question }} * {% trans "Mandatory Question" %} + {% else %} + {{ question.question }} + {% endif %} + +
+
+ {% elif question.type == "percentage" %} +
+
+ +
+
+ {% if question.is_mandatory %} + + {{ question.question }} + * {% trans "Mandatory Question" %} + + {% else %} + {{ question.question }} + {% endif %} +
+ + +
+
+
+ {% elif question.type == "file" %} +
+
+ +
+
+ {% if question.is_mandatory %} + {{ question.question }} * {% trans "Mandatory Question" %} + {% else %} + {{ question.question }} + {% endif %} + +
+
+ {% elif question.type == "date" %} +
+
+ +
+
+ {% if question.is_mandatory %} + {{ question.question }} * {% trans "Mandatory Question" %} + {% else %} + {{ question.question }} + {% endif %} + +
+
+ {% elif question.type == "rating" %} +
+
+ +
+
+ {% if question.is_mandatory %} + {{ question.question }} * {% trans "Mandatory Question" %} + {% else %} + {{ question.question }} + {% endif %} +
+ + + + + + + + + + +
+
+
+ {% elif question.type == "checkbox" %} +
+
+ +
+
+ {% if question.is_mandatory %} + {{ question.question }} * {% trans "Mandatory Question" %} + {% else %} + {{ question.question }} + {% endif %} +
+
+ + + Yes + + +
+
+ + + No + + +
+
+
+
+ {% else %} +
+
+ +
+
+ {% if question.is_mandatory %} + {{ question.question }} * {% trans "Mandatory Question" %} + {% else %} + {{ question.question }} + {% endif %} + +
+
+ {% endif %} {% endfor %} +
+ {% comment %}
+ +
{% endcomment %} +
+

+ © {% now 'Y' %} {{white_label_company_name}}. All rights resevered. +

+
+
+
+
+
+ diff --git a/recruitment/urls.py b/recruitment/urls.py index 61627a213..9da1689c6 100644 --- a/recruitment/urls.py +++ b/recruitment/urls.py @@ -323,6 +323,16 @@ urlpatterns = [ views.stage_sequence_update, name="stage-sequence-update", ), + path( + "survey-template-preview//", + recruitment.views.surveys.survey_preview, + name="survey-template-preview", + ), + path( + "update-question-order", + recruitment.views.surveys.question_order_update, + name="update-question-order", + ), path( "recruitment-application-survey", recruitment.views.surveys.survey_form, diff --git a/recruitment/views/surveys.py b/recruitment/views/surveys.py index f4b7b45ce..40512617c 100644 --- a/recruitment/views/surveys.py +++ b/recruitment/views/surveys.py @@ -13,7 +13,7 @@ from django.core import serializers from django.core.files.storage import default_storage from django.core.files.uploadedfile import SimpleUploadedFile from django.db.models import ProtectedError -from django.http import HttpResponse, HttpResponseRedirect +from django.http import HttpResponse, HttpResponseRedirect, JsonResponse from django.shortcuts import redirect, render from django.utils.translation import gettext_lazy as _ @@ -30,6 +30,7 @@ from recruitment.forms import ( ApplicationForm, QuestionForm, SurveyForm, + SurveyPreviewForm, TemplateForm, ) from recruitment.models import ( @@ -56,6 +57,56 @@ def survey_form(request): return render(request, "survey/form.html", {"form": form}) +def survey_preview(request, title): + """ + Used to render survey form to the candidate + """ + # title = request.GET.get("title") + template = SurveyTemplate.objects.get(title=str(title)) + + form = SurveyPreviewForm(template=template).form + return render( + request, + "survey/survey_preview.html", + {"form": form, "template": template}, + ) + + +from django.views.decorators.csrf import csrf_exempt + + +@csrf_exempt +def question_order_update(request): + if request.method == "POST": + # Extract data from the request + question_id = request.POST.get("question_id") + new_position = int(request.POST.get("new_position")) + qs = RecruitmentSurvey.objects.get(id=question_id) + + print("____OLD POSITION______") + print(qs.sequence) + print("____NEW POSITION______") + print(new_position) + + if qs.sequence > new_position: + new_position = new_position + if qs.sequence <= new_position: + new_position = new_position - 1 + + old_qs = RecruitmentSurvey.objects.filter(sequence=new_position) + for i in old_qs: + + i.sequence = new_position + 1 + i.save() + qs.sequence = int(new_position) + qs.save() + return JsonResponse( + {"success": True, "message": "Question order updated successfully"} + ) + + return JsonResponse({"error": "Invalid request method"}, status=405) + + def candidate_survey(request): """ Used to render survey form to the candidate diff --git a/static/images/ui/drag.svg b/static/images/ui/drag.svg new file mode 100644 index 000000000..5e8fa2385 --- /dev/null +++ b/static/images/ui/drag.svg @@ -0,0 +1 @@ + \ No newline at end of file