Skip to content
Snippets Groups Projects
Verified Commit fa76e030 authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

Replace constance by dynamic-preferences

parent f398d318
No related branches found
No related tags found
1 merge request!56Use dynamic preferences
......@@ -5,7 +5,6 @@ from datetime import date, datetime, timedelta, time
from enum import Enum
from typing import Dict, Optional, Tuple, Union
from constance import config
from django.core import validators
from django.core.exceptions import ValidationError
from django.db import models
......@@ -29,7 +28,7 @@ from aleksis.core.mixins import ExtensibleModel
from aleksis.core.models import Group, Person, DashboardWidget
from aleksis.apps.chronos.util.date import week_weekday_from_date
from aleksis.core.util.core_helpers import has_person
from aleksis.core.util.core_helpers import has_person, get_site_preferences
class TimetableType(Enum):
......@@ -437,7 +436,7 @@ class GroupPropertiesMixin:
@property
def groups_to_show(self) -> models.QuerySet:
groups = self.groups.all()
if groups.count() == 1 and groups[0].parent_groups.all() and config.CHRONOS_USE_PARENT_GROUPS:
if groups.count() == 1 and groups[0].parent_groups.all() and get_site_preferences()["chronos__use_parent_groups"]:
return groups[0].parent_groups.all()
else:
return groups
......
from django.utils.translation import gettext as _
from dynamic_preferences.preferences import Section
from dynamic_preferences.types import BooleanPreference, IntegerPreference
from aleksis.core.registries import site_preferences_registry, person_preferences_registry
chronos = Section("chronos", verbose_name=_("Chronos"))
@site_preferences_registry.register
class UseParentGroups(BooleanPreference):
section = chronos
name = "use_parent_groups"
default = False
verbose_name = _("Use parent groups in timetable views")
help_text = _(
"If an lesson or substitution has only one group"
" and this group has parent groups,"
" show the parent groups instead of the original group."
)
@person_preferences_registry.register
class ShortenGroups(BooleanPreference):
section = chronos
name = "shorten_groups"
default = True
verbose_name = _("Shorten groups in timetable views")
help_text = _(
"If there are more groups than the set limit, they will be collapsed."
)
@site_preferences_registry.register
class ShortenGroupsLimit(IntegerPreference):
section = chronos
name = "shorten_groups_limit"
default = 4
verbose_name = _("Limit of groups for shortening of groups")
help_text = _(
"If an user activates shortening of groups, they will be collapsed if there are more groups than this limit."
)
@site_preferences_registry.register
class SubstitutionsPrintNumberOfDays(IntegerPreference):
section = chronos
name = "substitutions_print_number_of_days"
default = 2
verbose_name = _("Number of days shown on substitutions print view")
@site_preferences_registry.register
class SubstitutionsShowHeaderBox(BooleanPreference):
section = chronos
name = "substitutions_show_header_box"
default = True
verbose_name = _("Show header box in substitution views")
help_text = _("The header box shows affected teachers/groups.")
from django.utils.translation import gettext_lazy as _
CONSTANCE_CONFIG = {
"CHRONOS_USE_PARENT_GROUPS": (
False,
_(
"If an lesson or substitution has only one group"
" and this group has parent groups,"
" show the parent groups instead of the original group."
),
),
"CHRONOS_SHORTEN_GROUPS": (
False,
_(
"If there are more groups than the limit set in CHRONOS_SHORTEN_GROUPS_LIMIT, add text collapsible."
),
),
"CHRONOS_SHORTEN_GROUPS_LIMIT": (
4,
_(
"If there are more groups than this limit and CHRONOS_SHORTEN_GROUPS is enabled, add text collapsible."
),
),
"CHRONOS_SUBSTITUTIONS_PRINT_DAY_NUMBER": (
2,
_("Number of days shown on substitutions print view"),
),
"CHRONOS_SUBSTITUTIONS_SHOW_HEADER_BOX": (
True,
_("The header box shows affected teachers/groups."),
),
}
CONSTANCE_CONFIG_FIELDSETS = {
"Chronos settings": (
"CHRONOS_USE_PARENT_GROUPS",
"CHRONOS_SHORTEN_GROUPS",
"CHRONOS_SHORTEN_GROUPS_LIMIT",
"CHRONOS_SUBSTITUTIONS_PRINT_DAY_NUMBER",
"CHRONOS_SUBSTITUTIONS_SHOW_HEADER_BOX",
),
}
{% if groups.count == 1 and groups.0.parent_groups.all and config.CHRONOS_USE_PARENT_GROUPS %}
{% if groups.count == 1 and groups.0.parent_groups.all and request.site.preferences.chronos__use_parent_groups %}
{% include "chronos/partials/groups_part.html" with groups=groups.0.parent_groups.all %}
{% else %}
{% include "chronos/partials/groups_part.html" with groups=groups %}
......
{% if groups.count > config.CHRONOS_SHORTEN_GROUPS_LIMIT and config.CHRONOS_SHORTEN_GROUPS %}
{% if groups.count > request.site.preferences.chronos__shorten_groups_limit and request.user.preferences.chronos__shorten_groups %}
{% include "components/text_collapsible.html" with template="chronos/partials/group.html" qs=groups %}
{% else %}
{% for group in groups %}
......
......@@ -2,7 +2,6 @@ from collections import OrderedDict
from datetime import date, datetime, timedelta
from typing import Optional, Tuple
from constance import config
from django.contrib.auth.decorators import login_required
from django.db.models import Count
from django.http import HttpRequest, HttpResponse, HttpResponseNotFound
......@@ -21,7 +20,7 @@ from .tables import LessonsTable
from .util.build import build_timetable, build_substitutions_list, build_weekdays
from .util.js import date_unix
from .util.date import CalendarWeek, get_weeks_for_year
from aleksis.core.util.core_helpers import has_person
from aleksis.core.util.core_helpers import has_person, get_site_preferences
@permission_required("chronos.view_timetable_overview")
......@@ -293,7 +292,7 @@ def substitutions(
else:
wanted_day = TimePeriod.get_next_relevant_day(timezone.now().date(), datetime.now().time())
day_number = config.CHRONOS_SUBSTITUTIONS_PRINT_DAY_NUMBER
day_number = get_site_preferences()["chronos__substitutions_print_number_of_days"]
day_contexts = {}
if is_print:
......@@ -310,7 +309,7 @@ def substitutions(
day_contexts[day]["announcements"] = Announcement.for_timetables().on_date(day).filter(show_in_timetables=True)
if config.CHRONOS_SUBSTITUTIONS_SHOW_HEADER_BOX:
if get_site_preferences()["chronos__substitutions_show_header_box"]:
subs = LessonSubstitution.objects.on_day(day).order_by("lesson_period__lesson__groups",
"lesson_period__period")
absences = Absence.objects.on_day(day)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment