-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into fit4ehealth
* 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
Showing
26 changed files
with
450 additions
and
672 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.