Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into fit4ehealth
Browse files Browse the repository at this point in the history
* origin/master:
  Updated po Files
  Updated [fit4ehealth] questions
  Updated [fit4ehealth] questions
  chg: [templates] added survey result column in the admin page
  chg: [core] calculateResult is not using the lang parameter.
  fix: [templates] Fixed type in admin/views.py and removed useless stuff in templates.
  fix: [typing] exec_cmd_no_wait type is None and not NoReturn.
  chg: [admin] improved management of commands executed in a subprocess.
  chg: [templates] improved customization in the Django admin area.
  chg: [style] format code with black
  new: [templates] added new maintenance task in admin panel
  chg: [templates] removed useless messages section in the admin template.
  chg: [style] format code with black
  new: [templates] added new maintenance task in admin panel
  Survey4operators (#66)
  chg: [templates] added option to generate mo files from the admin page.

# Conflicts:
#	csskp/settings.py
#	locale/de/LC_MESSAGES/django.po
#	locale/django.pot
#	locale/fr/LC_MESSAGES/django.po
  • Loading branch information
Ruslan Baidan committed Dec 17, 2021
2 parents d74a601 + d5c3f48 commit 505b151
Show file tree
Hide file tree
Showing 26 changed files with 450 additions and 672 deletions.
16 changes: 16 additions & 0 deletions admin/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,20 @@

urlpatterns = [
path("export/survey.json", views.export_survey_json),
path("site_stats", views.site_stats),
path(
"compile-translations", views.compile_translations, name="compile_translations"
),
path("migrate-database", views.migrate_database, name="migrate_database"),
path("update-software", views.update_software, name="update_software"),
path(
"stats/survey-status-count.json",
views.survey_status_count,
name="survey_status_count",
),
path(
"stats/survey-language-count.json",
views.survey_language_count,
name="survey_language_count",
),
]
90 changes: 89 additions & 1 deletion admin/views.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,99 @@
# -*- coding: utf-8 -*-

from django.http import JsonResponse
import sys
from django.shortcuts import render
from django.db.models import Count
from django.http import JsonResponse, HttpResponseRedirect
from django.contrib.auth.decorators import login_required
from django.contrib import messages
from django.conf.global_settings import LANGUAGES
from utils.utils import exec_cmd, exec_cmd_no_wait
from survey.reporthelper import calculateResult
from survey.lib.utils import export_survey
from survey.models import SurveyUser


@login_required
def export_survey_json(request):
"""Returns the survey (questions, answers, recommendations and sections) in JSON."""
result = export_survey()
return JsonResponse(result, safe=False)


@login_required
def survey_status_count(request):
"""Returns the count for the SurveyUser status property."""
result = SurveyUser.objects.values("status").annotate(count=Count("status"))
status = {1: "In progress", 2: "Under reviews", 3: "Finished"}
return JsonResponse(
{status[item["status"]]: item["count"] for item in result.all()}
)


@login_required
def survey_language_count(request):
"""Returns the count for the SurveyUser choosen_lang property."""
result = SurveyUser.objects.values("choosen_lang").annotate(
count=Count("choosen_lang")
)
return JsonResponse(
{
[lang for lang in LANGUAGES if lang[0] == item["choosen_lang"]][0][1]: item[
"count"
]
for item in result.all()
}
)


@login_required
def site_stats(request):
"""Returns the page which will display some statistics."""
nb_finished_surveys = SurveyUser.objects.filter(status=3).count()
nb_surveys = SurveyUser.objects.count()
last_surveys = SurveyUser.objects.filter(status=3).order_by("-created_at")[:10]
survey_results = {user.id: calculateResult(user)[0] for user in last_surveys}
context = {
"nb_surveys": nb_surveys,
"nb_finished_surveys": nb_finished_surveys,
"last_surveys": last_surveys,
"survey_results": survey_results
}
return render(request, "admin/site_stats.html", context=context)


@login_required
def compile_translations(request):
"""Triggers the compilation of the translation files in a subprocess."""
cmd = [
sys.exec_prefix + "/bin/python",
"manage.py",
"compilemessages",
]
result = exec_cmd(" ".join(cmd))
print(result) # TODO: log the result
messages.info(request, "Translations files compiled.")
return HttpResponseRedirect("/admin/")


@login_required
def migrate_database(request):
"""Triggers the execution of the database migration scripts."""
cmd = [
sys.exec_prefix + "/bin/python",
"manage.py",
"migrate",
]
result = exec_cmd(" ".join(cmd))
print(result) # TODO: log the result
messages.info(request, "Database up-to-date.")
return HttpResponseRedirect("/admin/")


@login_required
def update_software(request):
"""Triggers the execution of the script which will update the software."""
cmd = ["./contrib/update.sh"]
exec_cmd_no_wait(cmd)
messages.info(request, "Updated.")
return HttpResponseRedirect("/admin/")
25 changes: 25 additions & 0 deletions contrib/update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#! /usr/bin/env bash

#
# Update the software.
#

RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color

set -e
#set -x

git pull origin master --tags
npm ci
poetry install --no-dev
poetry run python manage.py collectstatic --no-input
poetry run python manage.py migrate
poetry run python manage.py compilemessages

echo -e "✨ 🌟 ✨"
echo -e "${GREEN}Update finished. You can now restart the service.${NC} Example:"
echo " sudo systemctl restart apache2.service"

exit 0
4 changes: 2 additions & 2 deletions data/fit4ehealth/questions.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"max_e_count": "j",
"sector": null,
"answerChosen": false,
"label": "Written rules can:\n\t- avoid to forget relevant points and can be consulted at any time;\n\t- have a legal proof if the rules have been read."
"label": "Written rules can:<ul><li>avoid to forget relevant points and can be consulted at any time</li><li>have a legal proof if the rules have been read.</li></ul>"
}
]
},
Expand Down Expand Up @@ -1807,7 +1807,7 @@
"max_e_count": "j",
"sector": null,
"answerChosen": false,
"label": " Personal devices shouldn't be used in company without any controls, rules and explanations. By knowing all the different existing ways to attack an organization, it's possible to avoid them."
"label": "Personal devices shouldn't be used in company without any controls, rules and explanations. By knowing all the different existing ways to attack an organization, it's possible to avoid them."
}
]
},
Expand Down
2 changes: 1 addition & 1 deletion data/fit4privacy/questions.json
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@
"max_e_count": "j",
"sector": null,
"answerChosen": true,
"label": "Your company should consider informing all types of data subjects whose data it processes, of the existence of the processing, the conditions you put in place to protect their data, and their rights over their data. In relation to your employees or trainees, you should be transparent about the personal data processed at the time of hiring (for example, by updating\n work or internship contracts), but also for the duration of their contract (for example, in the intranet, or with an amendment to the employment contract). If you have a website whose use involves processing of visitors' personal data, that site should also explain the data processed and the measures your organization has put in place to protect that data. To your customers, as well as to suppliers and third parties, you have a similar obligation to be transparent (for example, by updating contracts or terms and conditions). In terms of what to communicate to them, you should consider following Art. 13 and 14 of GDPR when it comes to this information."
"label": "Your company should consider informing all types of data subjects whose data it processes, of the existence of the processing, the conditions you put in place to protect their data, and their rights over their data. In relation to your employees or trainees, you should be transparent about the personal data processed at the time of hiring (for example, by updating\n work or internship contracts), but also for the duration of their contract (for example, in the intranet, or with an amendment to the employment contract). If you have a website whose use involves processing of visitors' personal data, that site should also explain the data processed and the measures your organization has put in place to protect that data. To your customers, as well as to suppliers and third parties, you have a similar obligation to be transparent (for example, by updating contracts or terms and conditions). In terms of what to communicate to them, you should consider following Art. 13 and 14 of GDPR when it comes to this information."
}
],
"label": "We have given no information whatsoever."
Expand Down
4 changes: 2 additions & 2 deletions data/fit4privacy/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -1160,12 +1160,12 @@
"lang": "de"
},
{
"original": "Your company should consider informing all types of data subjects whose data it processes, of the existence of the processing, the conditions you put in place to protect their data, and their rights over their data. In relation to your employees or trainees, you should be transparent about the personal data processed at the time of hiring (for example, by updating\n work or internship contracts), but also for the duration of their contract (for example, in the intranet, or with an amendment to the employment contract). If you have a website whose use involves processing of visitors' personal data, that site should also explain the data processed and the measures your organization has put in place to protect that data. To your customers, as well as to suppliers and third parties, you have a similar obligation to be transparent (for example, by updating contracts or terms and conditions). In terms of what to communicate to them, you should consider following Art. 13 and 14 of GDPR when it comes to this information.",
"original": "Your company should consider informing all types of data subjects whose data it processes, of the existence of the processing, the conditions you put in place to protect their data, and their rights over their data. In relation to your employees or trainees, you should be transparent about the personal data processed at the time of hiring (for example, by updating\n work or internship contracts), but also for the duration of their contract (for example, in the intranet, or with an amendment to the employment contract). If you have a website whose use involves processing of visitors' personal data, that site should also explain the data processed and the measures your organization has put in place to protect that data. To your customers, as well as to suppliers and third parties, you have a similar obligation to be transparent (for example, by updating contracts or terms and conditions). In terms of what to communicate to them, you should consider following Art. 13 and 14 of GDPR when it comes to this information.",
"translated": "Votre entreprise devrait informer tous les types de personnes concern\u00e9es dont elle traite les donn\u00e9es \u00e0 caract\u00e8re personnel, de l'existence de ces traitements, des conditions que vous mettez en place pour prot\u00e9ger leurs donn\u00e9es et de leurs droits sur leurs donn\u00e9es. En relation avec vos employ\u00e9s ou stagiaires, vous devriez \u00eatre transparent sur les donn\u00e9es personnelles trait\u00e9es au moment de l\u2019embauche (par exemple, en mettant \u00e0\n jour les contrats de travail ou de stage), mais aussi pendant la dur\u00e9e de leur contrat (par exemple, dans l'intranet, ou avec un avenant au contrat de travail). Si vous avez un site Web dont l'usage entraine des traitements des donn\u00e9es personnelles des visiteurs, ce site devrait aussi expliquer les donn\u00e9es trait\u00e9es et les mesures mises en place par votre organisation pour prot\u00e9ger ces donn\u00e9es. Envers vos clients, ainsi qu'en relation avec les fournisseurs et les parties tierces, vous avez l\u2019obligation similaire d\u2019\u00eatre transparent (par exemple, en mettant \u00e0 jour les contrats ou les conditions g\u00e9n\u00e9rales). Par rapport au contenu de cette communication vers eux, vous devriez suivre <a href=\"https://www.privacy-regulation.eu/en/article-13-information-to-be-provided-where-personal-data-are-collected-from-the-data-subject-GDPR.htm\" target=\"_blank\"> Article 13 du RGPD </a> et 14 du RGPD en ce qui concerne les informations \u00e0 fournir.",
"lang": "fr"
},
{
"original": "Your company should consider informing all types of data subjects whose data it processes, of the existence of the processing, the conditions you put in place to protect their data, and their rights over their data. In relation to your employees or trainees, you should be transparent about the personal data processed at the time of hiring (for example, by updating\n work or internship contracts), but also for the duration of their contract (for example, in the intranet, or with an amendment to the employment contract). If you have a website whose use involves processing of visitors' personal data, that site should also explain the data processed and the measures your organization has put in place to protect that data. To your customers, as well as to suppliers and third parties, you have a similar obligation to be transparent (for example, by updating contracts or terms and conditions). In terms of what to communicate to them, you should consider following Art. 13 and 14 of GDPR when it comes to this information.",
"original": "Your company should consider informing all types of data subjects whose data it processes, of the existence of the processing, the conditions you put in place to protect their data, and their rights over their data. In relation to your employees or trainees, you should be transparent about the personal data processed at the time of hiring (for example, by updating\n work or internship contracts), but also for the duration of their contract (for example, in the intranet, or with an amendment to the employment contract). If you have a website whose use involves processing of visitors' personal data, that site should also explain the data processed and the measures your organization has put in place to protect that data. To your customers, as well as to suppliers and third parties, you have a similar obligation to be transparent (for example, by updating contracts or terms and conditions). In terms of what to communicate to them, you should consider following Art. 13 and 14 of GDPR when it comes to this information.",
"translated": "Ihr Unternehmen sollte in Betracht ziehen, alle Gruppen von betroffenen Personen, deren Daten es verarbeitet, \u00fcber die Tatsache der Verarbeitung, die von Ihnen zum Schutz der Daten ergriffenen Ma\u00dfnahmen und die Rechte der Benutzer an ihren Daten zu informieren. In Bezug auf Ihre Mitarbeiter oder Auszubildenden sollten Sie \u00fcber die bei der Einstellung verarbeiteten personenbezogenen Daten transparent sein (z. B. durch Aktualisierung\n Arbeits- oder Praktikumsvertr\u00e4ge), sondern auch f\u00fcr die Dauer ihres Vertrages (z.B. im Intranet oder bei einer \u00c4nderung des Arbeitsvertrages). Wenn Sie \u00fcber eine Website verf\u00fcgen, deren Nutzung die Verarbeitung personenbezogener Daten von Besuchern beinhaltet, sollte diese Website auch die verarbeiteten Daten und die Ma\u00dfnahmen erl\u00e4utern, die Ihre Organisation zum Schutz dieser Daten ergriffen hat. Gegen\u00fcber Ihren Kunden sowie Lieferanten und Dritten haben Sie eine \u00e4hnliche Verpflichtung zur Transparenz (z. B. durch Aktualisierung von Vertr\u00e4gen oder AGB). In Bezug auf diese Informationen sind Art. 13 und 14 der DSGVO zu befolgen. ",
"lang": "de"
},
Expand Down
Loading

0 comments on commit 505b151

Please sign in to comment.