Skip to content

Commit

Permalink
Customize template
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexis committed Nov 30, 2023
1 parent 5fcbc8a commit 08baa98
Show file tree
Hide file tree
Showing 12 changed files with 436 additions and 78 deletions.
2 changes: 1 addition & 1 deletion csskp/config_dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}

# The generic site/tool name. Used to load specific config, templates, styles, logo.
SITE_NAME = "fit4cybersecurity"
SITE_NAME = "fstp_registration"

SECRET_KEY = "u__*z&=urjtc0t)b)@5qbt_a#3-354=k9x(j)@eu#h7sb=-66s"

Expand Down
13 changes: 1 addition & 12 deletions csskp/fstp_registration/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,7 @@
# Generic configurations
"tool_name": "FSTP Registration",
"intro_text": gettext_lazy(
"This questionnaire, created in consultation with "
'<a href="https://cnpd.public.lu/en.html" target="_blank">CNPD</a>, '
"aims to help organisations assess to what extent they are in control of their personal "
"data risks. First, Fit4Privacy asks questions to understand the amount of personal "
"data processing already in place, then its questions examine the response of the "
"organisation towards GDPR obligations. Based on the identified scope, the tool offers "
"a set of recommendations that could be consolidated into the first steps towards "
"implementing privacy and data protection. Note that this is a self-assessment tool "
"and as such cannot provide definitive guidelines. Yet, Fit4Privacy is raising "
"awareness around key topics such as personal data processing, data lifecycle "
"management, and basic data protection obligations for which organisations should "
"already be prepared as of 2021."
"TO BE DEFINED 895"
),
"countries_first": [
"LU",
Expand Down
2 changes: 1 addition & 1 deletion survey/management/commands/import_questions.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def handle(self, *args, **options): # noqa: C901
qindex = (
abs(qindex)
if question["section"] != CONTEXT_SECTION_LABEL
else qindex
else -abs(qindex)
)

if qindex > max_question_index:
Expand Down
102 changes: 44 additions & 58 deletions survey/viewLogic.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def create_user_and_sequence(lang: str) -> SurveyUser:
user = SurveyUser()
# defines the next question (exclude the context questions)
survey_question = SurveyQuestion.objects.exclude(
# section__label__contains=CONTEXT_SECTION_LABEL
section__label__contains=CONTEXT_SECTION_LABEL
).order_by("qindex")[:1]
user.current_question = survey_question[0]
# Ensures the submitted languages is accepted
Expand Down Expand Up @@ -98,7 +98,7 @@ def handle_start_survey(request: HttpRequest, lang: str) -> Union[Dict, SurveyUs
forms = {}
questions = (
SurveyQuestion.objects.filter(section__label__contains=CONTEXT_SECTION_LABEL)
.order_by("qindex")
.order_by("-qindex")
.all()
)

Expand Down Expand Up @@ -158,37 +158,25 @@ def handle_question_answers_request(
) -> Union[Dict, SurveyUser]:
current_sequence = get_sequence_by_user_and_index(user, question_index)
current_question = current_sequence.question
questions_group = SurveyQuestion.objects.filter(
section=current_question.section
)
does_map_exist = does_answers_questions_map_exist()

question_answers = {}
tuple_answers = {}
current_questions = {}
current_questions_tooltips = {}
try:
for question in questions_group:
current_questions[question.id] = _(question.label)
current_questions_tooltips[question.id] = _(question.tooltip)
question_answers[question.id] = question.surveyquestionanswer_set.filter(
is_active=True
)
tuple_answers[question.id] = get_answer_choices(question, user.chosen_lang)
question_answers = current_question.surveyquestionanswer_set.filter(
is_active=True
)
tuple_answers = get_answer_choices(current_question, user.chosen_lang)
except Exception as e:
logger.error(e)
raise e

free_text_answer_id = 0
# TODO: adjust here....
# for question_answer in question_answers:
# if question_answer.atype == "T":
# free_text_answer_id = question_answer.id
for question_answer in question_answers:
if question_answer.atype == "T":
free_text_answer_id = question_answer.id

translation.activate(user.chosen_lang)
forms = {}

if request.method == "POST":
# TODO: adjust here....
form = AnswerMChoice(
tuple_answers,
data=request.POST,
Expand Down Expand Up @@ -240,50 +228,48 @@ def handle_question_answers_request(

return user
else:
for question in questions_group:
forms[question.id] = AnswerMChoice(
tuple_answers[question.id],
lang=user.chosen_lang,
answers_field_type=question.qtype,
question_answers=question_answers[question.id],
)

user_answers = SurveyUserAnswer.objects.filter(
user=user, answer__question=question
)
selected_answers = []
for user_answer in user_answers:
if user_answer.uvalue == "1":
selected_answers.append(user_answer.answer.id)
if user_answer.content:
forms[question.id].set_answer_content(user_answer.content)

# user_feedback = SurveyUserFeedback.objects.filter(
# user=user, question=current_question
# )[:1]

forms[question.id].set_answers(selected_answers)
# if user_feedback:
# forms[question.id].set_feedback(user_feedback[0].feedback)

for question in questions_group:
unique_answers = SurveyQuestionAnswer.objects.filter(
question=question, uniqueAnswer=True
form = AnswerMChoice(
tuple_answers,
lang=user.chosen_lang,
answers_field_type=current_question.qtype,
question_answers=question_answers,
)
forms[question.id].set_unique_answers(
",".join(str(uniqueAnswer.id) for uniqueAnswer in unique_answers)

user_answers = SurveyUserAnswer.objects.filter(
user=user, answer__question=current_question
)
forms[question.id].set_free_text_answer_id(free_text_answer_id)
selected_answers = []
for user_answer in user_answers:
if user_answer.uvalue == "1":
selected_answers.append(user_answer.answer.id)
if user_answer.content:
form.set_answer_content(user_answer.content)

user_feedback = SurveyUserFeedback.objects.filter(
user=user, question=current_question
)[:1]

form.set_answers(selected_answers)
if user_feedback:
form.set_feedback(user_feedback[0].feedback)

uniqueAnswers = SurveyQuestionAnswer.objects.filter(
question=current_question, uniqueAnswer=True
)
form.set_unique_answers(
",".join(str(uniqueAnswer.id) for uniqueAnswer in uniqueAnswers)
)
form.set_free_text_answer_id(free_text_answer_id)

return {
"title": CUSTOM["tool_name"]
+ " - "
+ _("Question")
+ " "
+ str(question_index),
"questions": current_questions,
"questions_tooltips": current_questions_tooltips,
"forms": forms,
"question": _(current_question.label),
"question_tooltip": _(current_question.tooltip),
"form": form,
"action": "/survey/question/" + str(question_index),
"user": user,
"current_question_index": question_index,
Expand Down Expand Up @@ -652,7 +638,7 @@ def get_answer_choices(question: SurveyQuestion, lang: str) -> List[Tuple[int, s
def get_questions_with_user_answers(user: SurveyUser):
survey_user_answers = (
SurveyUserAnswer.objects.filter(user=user)
# .exclude(answer__question__section__label=CONTEXT_SECTION_LABEL)
.exclude(answer__question__section__label=CONTEXT_SECTION_LABEL)
.order_by("answer__question__qindex", "answer__aindex")
)

Expand Down
87 changes: 87 additions & 0 deletions templates/fstp_registration/survey/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
{% extends 'survey/bootstrap.html' %}

{% load i18n %}
{% load bootstrap4 %}
{% load static %}

{% block bootstrap4_extra_head %}
<meta name="description" content="{{ custom.tool_name }} by NC3-LU" />
<link rel="stylesheet" type="text/css" href="{% static custom.survey_css %}" />
<link rel="icon" type="image/x-icon" href="{% static 'images/favicon.ico' %}" />
<link rel="apple-touch-icon" sizes="152x152" href="{% static 'images/apple-touch-icon.png' %}" />
<link rel="apple-touch-icon" sizes="180x180" href="{% static 'images/apple-touch-icon.png' %}" />
<link rel="stylesheet" href="{% static 'npm_components/fork-awesome/css/fork-awesome.min.css' %}">
<link rel="stylesheet" href="{% static 'npm_components/bootstrap-icons/font/bootstrap-icons.css' %}">
<script type="text/javascript" src="{% static 'survey/js/language-selector.js' %}"></script>
{% endblock %}

{% block title %}
{{ custom.tool_name }}
{% endblock %}

{% block bootstrap4_content %}
{% get_current_language as LANGUAGE_CODE %}
{% get_available_languages as LANGUAGES %}
{% get_language_info_list for LANGUAGES as languages %}

{% if user.is_authenticated %}
<nav class="navbar navbar-expand-lg navbar-dark bg-cssk-blue">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto w-100 justify-content-end">
{% if user.is_superuser %}
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownAdmin" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i class="fa fa-cogs"></i></a>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdownAdmin">
<a class="dropdown-item" href="/admin/" title="Dashboard">Django Administration</a>
</div>
</li>
{% endif %}
<li class="nav-item">
<a class="nav-link" href="/admin/logout/" title="Log out"><i class="fa fa-sign-out" aria-hidden="true"></i></a>
</li>
</ul>
</div>
</nav>
{% endif %}

<div class="container">
{% block main_logo %}
<div class="row">
<div class="col text-center">
<div class="mt-1 border-bottom border-primary">
{% include custom.templates_parts.main_logo %}
</div>
</div>
</div>
{% endblock %}

{% if languages|length > 1 %}
<div class="dropdown d-flex flex-row-reverse" id="language-selector" >
<a class="btn dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="bi bi-translate text-primary"></i>
{{ LANGUAGE_CODE|language_name_local }}
</a>
<div class="dropdown-menu">
{% for lang in languages %}
<a class="dropdown-item" href="/survey/language/{{ lang.code }}">
{{ lang.name_local }}
</a>
{% endfor %}
</div>
</div>
{% endif %}

{% autoescape off %}{% bootstrap_messages %}{# {% bootstrap_alert content %} #}{% endautoescape %}

<div id="content-body">
{% block content %}{% endblock %}
</div>
</div>

<div class="footer d-none d-md-block">
{% include custom.templates_parts.footer %}
</div>
{% endblock %}
2 changes: 1 addition & 1 deletion templates/fstp_registration/survey/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends 'survey/index.html' %}

{% block index_welcome_message %}
{{ _('Welcome to the FSTP registration form').
<h3> {{ _('Welcome to the FSTP registration form.') }} </h3>
{% endblock %}
2 changes: 1 addition & 1 deletion templates/fstp_registration/survey/start.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

{% block start_description %}
<div class="card-title">
{{ _('Coucou try.') }}
TO BE DEFINED 963
</div>
{% endblock %}
2 changes: 1 addition & 1 deletion templates/parts/fstp_registration/footer_part.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
alt="{{ _('Privacy policy') }}">{{ _('Privacy policy') }}</a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://lhc.lu" target="_blank" rel="noopener noreferrer">Copyright {% now "Y" %} Luxembourg House of Cybersecurity</a>
<a class="nav-link" href="https://lhc.lu" target="_blank" rel="noopener noreferrer">Copyright {% now "Y" %} LHC</a>
</li>
</ul>
</div>
6 changes: 4 additions & 2 deletions templates/parts/fstp_registration/logo_part.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
<h1>
<a href="/" class="logo-link">
<img
src="{% settings_value 'SITE_IMAGES_URL' %}/logo-nc3.png"
src="{% settings_value 'STATIC_URL' %}images/logo-nc3-full.png"
class="py-4"
width="50%"
alt="{{ custom.tool_name }}"
title="{{ custom.tool_name }}">
title="{{ custom.tool_name }}"
style="max-width: 300px;">
</a>
</h1>
Loading

0 comments on commit 08baa98

Please sign in to comment.