diff --git a/accounts/forms.py b/accounts/forms.py index db53ed5..0e644e1 100644 --- a/accounts/forms.py +++ b/accounts/forms.py @@ -2,14 +2,14 @@ import re from django import forms from django.utils.translation import ugettext_lazy as _ from django.contrib.auth.models import User -from django.conf import settings +from appsettings.models import AppSettings class UserAddForm(forms.Form): name = forms.CharField(label="Name", error_messages={'required': _('No User name has been entered')}, max_length=20) - password = forms.CharField(required=not settings.ALLOW_EMPTY_PASSWORD, + password = forms.CharField(required=False if AppSettings.objects.get(key="ALLOW_EMPTY_PASSWORD").value == 'True' else True, error_messages={'required': _('No password has been entered')},) def clean_name(self): diff --git a/accounts/models.py b/accounts/models.py index 77cf81a..cee3f7b 100644 --- a/accounts/models.py +++ b/accounts/models.py @@ -2,7 +2,6 @@ from django.db.models import Model, BooleanField, IntegerField, CharField from django.db.models import ForeignKey, OneToOneField from django.db.models import CASCADE, DO_NOTHING from django.contrib.auth.models import User -from django.conf import settings from instances.models import Instance from django.core.validators import MinValueValidator diff --git a/accounts/templates/accounts-list.html b/accounts/templates/accounts-list.html index 72b6d14..b9c3487 100644 --- a/accounts/templates/accounts-list.html +++ b/accounts/templates/accounts-list.html @@ -68,8 +68,8 @@
{% endblock %} diff --git a/appsettings/views.py b/appsettings/views.py index 8cc6e23..eaf175d 100644 --- a/appsettings/views.py +++ b/appsettings/views.py @@ -7,7 +7,6 @@ from django.urls import reverse from django.utils.translation import ugettext_lazy as _ from django.contrib.auth.decorators import login_required from django.contrib import messages -from django.conf import settings from appsettings.models import AppSettings from logs.views import addlogmsg @@ -22,14 +21,33 @@ def appsettings(request): """ error_messages = [] + sass_dir = AppSettings.objects.get(key="SASS_DIR") + bootstrap_theme = AppSettings.objects.get(key="BOOTSTRAP_THEME") + try: + themes_list = os.listdir(sass_dir.value + "/wvc-theme") + except FileNotFoundError as err: + error_messages.append(err) + addlogmsg(request.user.username, "", err) + + # Bootstrap settings related with filesystems, because of that they are excluded from other settings + appsettings = AppSettings.objects.exclude(description__startswith="Bootstrap").order_by("name") - show_inst_bottom_bar = AppSettings.objects.get(key="VIEW_INSTANCE_DETAIL_BOTTOM_BAR") - bootstrap_theme = AppSettings.objects.get(key="BOOTSTRAP_THEME") - sass_dir = AppSettings.objects.get(key="SASS_DIR") - themes_list = os.listdir(sass_dir.value + "/wvc-theme") + if request.method == 'POST': + if 'SASS_DIR' in request.POST: + try: + sass_dir.value = request.POST.get("SASS_DIR", "") + sass_dir.save() + + msg = _(f"SASS directory path is changed. Now: {sass_dir.value}") + messages.success(request, msg) + except Exception as err: + msg = err + error_messages.append(msg) + + addlogmsg(request.user.username, "", msg) + return HttpResponseRedirect(request.get_full_path()) - if request.method == 'POST': if 'BOOTSTRAP_THEME' in request.POST: theme = request.POST.get("BOOTSTRAP_THEME", "") scss_var = f"@import '{sass_dir.value}/wvc-theme/{theme}/variables';" @@ -56,33 +74,20 @@ def appsettings(request): addlogmsg(request.user.username, "", msg) return HttpResponseRedirect(request.get_full_path()) - if 'SASS_DIR' in request.POST: - try: - sass_dir.value = request.POST.get("SASS_DIR", "") - sass_dir.save() + for setting in appsettings: + if setting.key in request.POST: + try: + setting.value = request.POST.get(setting.key, "") + setting.save() - msg = _(f"SASS directory path is changed. Now: {sass_dir.value}") - messages.success(request, msg) - except Exception as err: - msg = err - error_messages.append(msg) - - addlogmsg(request.user.username, "", msg) - return HttpResponseRedirect(request.get_full_path()) - - if 'VIEW_INSTANCE_DETAIL_BOTTOM_BAR' in request.POST: - try: - show_inst_bottom_bar.value = request.POST.get("VIEW_INSTANCE_DETAIL_BOTTOM_BAR", "") - show_inst_bottom_bar.save() - - msg = _(f"Show bottom bar setting is changed. Now: {show_inst_bottom_bar.value}") - messages.success(request, msg) - except Exception as err: - msg = err - error_messages.append(msg) - - addlogmsg(request.user.username, "", msg) - return HttpResponseRedirect(request.get_full_path()) + msg = _(f"{setting.name} is changed. Now: {setting.value}") + messages.success(request, msg) + except Exception as err: + msg = err + error_messages.append(msg) + + addlogmsg(request.user.username, "", msg) + return HttpResponseRedirect(request.get_full_path()) return render(request, 'appsettings.html', locals()) diff --git a/computes/templates/overview.html b/computes/templates/overview.html index 88ce3db..c2d2e34 100644 --- a/computes/templates/overview.html +++ b/computes/templates/overview.html @@ -75,7 +75,7 @@{% trans "This action sends an ACPI shutdown signal to the instance." %}
{% trans "This action restore the instance after suspend." %}
@@ -226,8 +226,8 @@{% trans "Click on Boot button to start this instance." %}
{% trans "This action opens a new window with a VNC connection to the console of the instance." %}
- {% ifequal status 1 %} + {% if status == 1 %}{% trans "You need shut down your instance and enter a new root password." %}
{% trans "You need shut down your instance and choose your public key." %}
{% trans "This action opens a remote viewer with a connection to the console of the instance." %}
{% trans "This may take more than an hour, depending on how much content is on your droplet and how large the disk is." %}
{% trans "To take a snapshot please Power Off the instance." %}
- {% endifequal %} + {% endif %}{% trans "Autostart your instance when host server is power on " %} - {% ifequal autostart 0 %} + {% if autostart == 0 %} {% else %} - {% endifequal %} + {% endif %}
{% trans "Enable Boot Menu for your instance when it starts up " %} - {% ifequal bootmenu 0 %} + {% if bootmenu == 0 %} {% else %} - {% endifequal %} + {% endif %} {% else %} - {% ifequal bootmenu 0 %} + {% if bootmenu == 0 %}
**** {% trans "Please shutdown instance to modify boot menu" %} ****
- {% endifequal %} - {% endifequal %} + {% endif %} + {% endif %}{% trans "Delete storage for instance?" %}
{% if request.user.is_superuser or userinstance.is_delete %} - {% ifequal status 3 %} + {% if status == 3 %}