def test_cannot_instanciate_preference_or_section_with_invalid_name(self): invalid_names = ['with space', 'with__separator', 'with-hyphen'] for n in invalid_names: with self.assertRaises(ValueError): Section(n) with self.assertRaises(ValueError): class P(IntegerPreference): name = n P()
from django.utils.translation import gettext_lazy as _ from dynamic_preferences.preferences import Section from dynamic_preferences.registries import global_preferences_registry from dynamic_preferences.types import LongStringPreference, StringPreference mailchimp_integration = Section("mailchimp", _("Mailchimp")) @global_preferences_registry.register class MailchimpServer(StringPreference): section = mailchimp_integration name = "server" default = "" verbose_name = _("Mailchimp server") @global_preferences_registry.register class MailchimpListId(StringPreference): section = mailchimp_integration name = "list_id" default = "" verbose_name = _("Mailchimp list ID") @global_preferences_registry.register class MailchimpSegmentId(StringPreference): section = mailchimp_integration name = "segment_id" default = "" verbose_name = _("Mailchimp segment ID")
from django.core.exceptions import ValidationError from django.utils.translation import gettext_lazy as _ from dynamic_preferences.preferences import Section from dynamic_preferences.types import BooleanPreference, IntegerPreference from aleksis.core.registries import person_preferences_registry, site_preferences_registry alsijil = Section("alsijil", verbose_name=_("Class register")) @site_preferences_registry.register class BlockPersonalNotesForCancelled(BooleanPreference): section = alsijil name = "block_personal_notes_for_cancelled" default = True verbose_name = _("Block adding personal notes for cancelled lessons") @site_preferences_registry.register class ViewOwnPersonalNotes(BooleanPreference): section = alsijil name = "view_own_personal_notes" default = True verbose_name = _("Allow users to view their own personal notes") @site_preferences_registry.register class RegisterAbsenceAsPrimaryGroupOwner(BooleanPreference): section = alsijil name = "register_absence_as_primary_group_owner"
from dynamic_preferences.types import StringPreference from dynamic_preferences.preferences import Section from dynamic_preferences.registries import global_preferences_registry stats = Section('stats') @global_preferences_registry.register class LatestPatch(StringPreference): name = 'LATEST_PATCH' default = '9.0.0' @global_preferences_registry.register class SummonerCount(StringPreference): name = 'SUMMONER_COUNT' default = '0' section = stats @global_preferences_registry.register class UpdatedSummonerCount(StringPreference): name = 'UPDATED_SUMMONER_COUNT' default = '0' section = stats @global_preferences_registry.register class MatchCount(StringPreference): name = 'MATCH_COUNT' default = '0'
from django.core.validators import ip_address_validators from django.forms import ValidationError, CheckboxInput, TextInput from dynamic_preferences.preferences import Section from dynamic_preferences.types import BooleanPreference, StringPreference, IntegerPreference, StringSerializer from dynamic_preferences.registries import global_preferences_registry # we create some section objects to link related preferences together from network_monitor.core.forms import boolean_toggle_attrs dhcp_scan = Section('dhcp_scan') @global_preferences_registry.register class DhcpScanIsEnabled(BooleanPreference): field_kwargs = { 'required': False, 'help_text': 'Enable/Disable DHCP scanning', 'widget': CheckboxInput(attrs=boolean_toggle_attrs) } section = dhcp_scan name = 'is_enabled' verbose_name = '' default = True # We start with a global preference @global_preferences_registry.register class DhcpScanIpRanges(StringPreference): field_kwargs = { 'required': False, 'help_text':
from django.forms import ValidationError from django.utils.encoding import force_text from django.utils.translation import gettext_lazy as _ from dynamic_preferences.preferences import Section from dynamic_preferences.types import BooleanPreference, ChoicePreference, FloatPreference, IntegerPreference, LongStringPreference, StringPreference from django_summernote.widgets import SummernoteWidget from standings.teams import TeamStandingsGenerator from standings.speakers import SpeakerStandingsGenerator from tournaments.utils import get_side_name_choices from .types import MultiValueChoicePreference from .models import tournament_preferences_registry # ============================================================================== scoring = Section('scoring', verbose_name=_("Score Rules")) # ============================================================================== @tournament_preferences_registry.register class MinimumSpeakerScore(FloatPreference): help_text = _("Minimum allowed score for substantive speeches") section = scoring name = 'score_min' verbose_name = _("Minimum speaker score") default = 68.0 @tournament_preferences_registry.register class MaximumSpeakerScore(FloatPreference): verbose_name = _("Maximum speaker score")
from django.utils.translation import gettext_lazy as _ from dynamic_preferences.preferences import Section from dynamic_preferences.types import BooleanPreference from aleksis.core.registries import site_preferences_registry untis_mysql = Section("untis_mysql", verbose_name=_("UNTIS: MySQL")) @site_preferences_registry.register class UpdateSubjects(BooleanPreference): section = untis_mysql name = "update_subjects" default = True verbose_name = _("Update values of existing subjects") @site_preferences_registry.register class UpdatePersonsShortName(BooleanPreference): section = untis_mysql name = "update_persons_short_name" default = False verbose_name = _("Update short name of existing persons") @site_preferences_registry.register class UpdatePersonsName(BooleanPreference): section = untis_mysql name = "update_persons_name" default = False
from dynamic_preferences.types import BooleanPreference, StringPreference from dynamic_preferences.preferences import Section from dynamic_preferences.registries import global_preferences_registry general = Section('general') witness = Section('witness') @global_preferences_registry.register class Released(BooleanPreference): section = general name = 'released' default = False @global_preferences_registry.register class showHeaderMessage(BooleanPreference): section = general name = 'show_header_message' default = True @global_preferences_registry.register class OurWitnessName(StringPreference): section = witness name = 'our_witness_name' default = 'noisy.witness' @global_preferences_registry.register class AskingForVotes(BooleanPreference): section = witness name = 'asking_for_votes' default = False
from django.utils.translation import gettext_lazy as _ import pycountry from dynamic_preferences.preferences import Section from dynamic_preferences.types import ChoicePreference, ModelChoicePreference, StringPreference from aleksis.core.models import Group, GroupType from aleksis.core.registries import site_preferences_registry csv_import = Section("csv_import", verbose_name=_("CSV import")) @site_preferences_registry.register class GroupTypeDepartments(ModelChoicePreference): section = csv_import name = "group_type_departments" required = False default = None model = GroupType verbose_name = _("Group type for department groups") help_text = _("If you leave it empty, no group type will be used.") @site_preferences_registry.register class GroupPrefixDepartments(StringPreference): section = csv_import name = "group_prefix_departments" default = "" verbose_name = _("Prefix for long names of department groups") help_text = _("If you leave it empty, no prefix will be added.")
import os import re import uuid from django.forms import ValidationError from dynamic_preferences.admin import GlobalPreferenceAdmin, PerInstancePreferenceAdmin from dynamic_preferences.types import StringPreference from dynamic_preferences.preferences import Section from dynamic_preferences.registries import global_preferences_registry as global_registry GlobalPreferenceAdmin.has_add_permission = lambda *args, **kwargs: False GlobalPreferenceAdmin.has_delete_permission = lambda *args, **kwargs: False PerInstancePreferenceAdmin.has_add_permission = lambda *args, **kwargs: False PerInstancePreferenceAdmin.has_delete_permission = lambda *args, **kwargs: False orchestrator = Section("orchestrator") # Validation Functions def is_valid_hostname(hostname): """ Validate a hostname :param hostname: hostname to validate :return: bool - valid hostname """ if len(hostname) > 255: return False if hostname[-1] == ".": hostname = hostname[: -1] # strip exactly one dot from the right, if present allowed = re.compile(r"(?!-)[A-Z\d-]{1,63}(?<!-)$", re.IGNORECASE)
# blog/dynamic_preferences_registry.py from dynamic_preferences.types import BooleanPreference, StringPreference, ChoicePreference, IntegerPreference, LongStringPreference, DurationPreference from dynamic_preferences.preferences import Section from dynamic_preferences.registries import global_preferences_registry # we create some section objects to link related preferences together general = Section('general') discussion = Section('manage') item = Section('item') user = Section('user') message = Section('message') nomenclature = Section('nomenclature') check = Section('check') # All preference types: https://github.com/agateblue/django-dynamic-preferences/blob/develop/dynamic_preferences/types.py # ------------------------------------ GENERAL ------------------------------------ @global_preferences_registry.register class ShowVersion(BooleanPreference): section = general name = 'show_version' verbose_name = "Show version number in footer" default = True required = True @global_preferences_registry.register
from dynamic_preferences.types import BooleanPreference, StringPreference from dynamic_preferences.preferences import Section from dynamic_preferences.registries import global_preferences_registry from dynamic_preferences.users.registries import user_preferences_registry # we create some section objects to link related preferences together site = Section('site') reader = Section('reader') discussion = Section('discussion') # We start with a global preference @global_preferences_registry.register class SiteName(StringPreference): section = site name = 'name' default = 'ComiCake' @global_preferences_registry.register class MaintenanceMode(BooleanPreference): section = site name = 'maintenance' default = False @global_preferences_registry.register class ProtectedByDefault(BooleanPreference): section = reader name = 'protected_by_default'
import json from dynamic_preferences.types import BooleanPreference, StringPreference, ChoicePreference from dynamic_preferences.preferences import Section from dynamic_preferences.registries import global_preferences_registry from dynamic_preferences.users.registries import user_preferences_registry from dalme_app.utils import JSONPreference api_settings = Section('api_settings') general = Section('general') interface = Section('interface') source_editor = Section('source_editor') # @global_preferences_registry.register # class SiteTitle(StringPreference): # section = general # name = 'title' # default = 'My site' # required = False # @global_preferences_registry.register # class MaintenanceMode(BooleanPreference): # name = 'maintenance_mode' # default = False @global_preferences_registry.register class ModelSelectFields(JSONPreference): """ Object that stores information about select fields for endpoints in the API - used by the Select renderer """ section = api_settings name = 'model_select_fields'
from dynamic_preferences.preferences import Section from dynamic_preferences.registries import global_preferences_registry from dynamic_preferences.types import StringPreference exchange = Section('exchange') @global_preferences_registry.register class BithumbApiKey(StringPreference): section = exchange name = 'bithumbApiKey' default = '' @global_preferences_registry.register class BithumbApiSecret(StringPreference): section = exchange name = 'bithumbApiSecret' default = '' @global_preferences_registry.register class BittrexApiKey(StringPreference): section = exchange name = 'bittrexApiKey' default = '' @global_preferences_registry.register class BittrexApiSecret(StringPreference): section = exchange
# blog/dynamic_preferences_registry.py from dynamic_preferences.types import StringPreference from dynamic_preferences.preferences import Section from dynamic_preferences.registries import global_preferences_registry # we create some section objects to link related preferences together company = Section('company') @global_preferences_registry.register class CompanyName(StringPreference): section = company name = 'legal_name' default = 'Emanuel Zúñiga Infante' @global_preferences_registry.register class CompanyComercialName(StringPreference): section = company name = 'comercial_name' default = 'iFact CR' @global_preferences_registry.register class CompanyIdType(StringPreference): section = company name = 'id_type' default = 'PERSON'
from django.forms import ValidationError from dynamic_preferences.types import IntegerPreference from dynamic_preferences.preferences import Section from dynamic_preferences.registries import global_preferences_registry as global_registry command = Section('command') @global_registry.register class CommandWait(IntegerPreference): """ Dynamic Preference for Command wait time Time before checking the database after sending a command for a response """ section = command name = 'wait' help_text = 'The amount of time to wait, in seconds, for a response to a command (0-30 seconds)' default = 5 def validate(self, value): """ Validate the wait time when updated :param value: new value to validate :return: None/exception """ if value < 0: raise ValidationError('Wait cannot be less than 0 seconds') elif value > 30: raise ValidationError('Wait cannot be greater than 30 seconds')
from django import forms from dynamic_preferences.preferences import Section from dynamic_preferences.types import BooleanPreference from dynamic_preferences.users.registries import user_preferences_registry ui = Section("user_interface") @user_preferences_registry.register class NavigationMenuExtended(BooleanPreference): section = ui name = "navigation_menu_extended" default = True # this setting should not be directly visibel to the user because we set it through ajax widget = forms.CheckboxInput(attrs={"style": "display: none"})
from dynamic_preferences.types import BooleanPreference from dynamic_preferences.preferences import Section from dynamic_preferences.registries import global_preferences_registry general = Section('general') @global_preferences_registry.register class Released(BooleanPreference): section = general name = 'released' default = False
from dynamic_preferences import types from dynamic_preferences.preferences import Section from dynamic_preferences.registries import global_preferences_registry clan_ranks = Section('clan_ranks') @global_preferences_registry.register class RecruitRank(types.FloatPreference): section = clan_ranks verbose_name = 'Exp para Recruta' name = 'recruit_exp' default = float(0) @global_preferences_registry.register class CorporalRank(types.FloatPreference): section = clan_ranks verbose_name = 'Exp para Cabo' name = 'corporal_exp' default = float(0) @global_preferences_registry.register class SergeantRank(types.FloatPreference): section = clan_ranks verbose_name = 'Exp para Sargento' name = 'sergeant_exp' default = float(50_000_000)
from dynamic_preferences.preferences import Section from dynamic_preferences.types import ( BooleanPreference, ChoicePreference, FilePreference, IntegerPreference, ModelMultipleChoicePreference, MultipleChoicePreference, StringPreference, ) from .models import Group, Person from .registries import person_preferences_registry, site_preferences_registry from .util.notifications import get_notification_choices_lazy general = Section("general", verbose_name=_("General")) school = Section("school", verbose_name=_("School")) theme = Section("theme", verbose_name=_("Theme")) mail = Section("mail", verbose_name=_("Mail")) notification = Section("notification", verbose_name=_("Notifications")) footer = Section("footer", verbose_name=_("Footer")) account = Section("account", verbose_name=_("Accounts")) auth = Section("auth", verbose_name=_("Authentication")) internationalisation = Section("internationalisation", verbose_name=_("Internationalisation")) @site_preferences_registry.register class SiteTitle(StringPreference): """Title of the AlekSIS instance, e.g. schools display name."""
from dynamic_preferences.preferences import Section from dynamic_preferences.registries import global_preferences_registry from dynamic_preferences.types import BooleanPreference, StringPreference, \ IntegerPreference # we create some section objects to link related preferences together shiftleader = Section('shiftleader') @global_preferences_registry.register class ShiftLeaderPopupEnabled(BooleanPreference): section = shiftleader name = 'popup_enabled' help_text = "Should the shift leader see a reminding popup every now and then?" default = False @global_preferences_registry.register class ShiftLeaderPopupText(StringPreference): section = shiftleader name = 'popup_text' help_text = "The popup text that will be displayed every now and then" default = 'Please perform the daily checks' @global_preferences_registry.register class ShiftLeaderPopupInterval(IntegerPreference): section = shiftleader name = 'popup_time_period' help_text = "The periodic popup time in seconds" default = 10800 # 3 hours
from dynamic_preferences.types import BooleanPreference from dynamic_preferences.preferences import Section from dynamic_preferences.registries import global_preferences_registry # we create some section objects to link related preferences together configuration = Section('Confirguration') # We start with a global preference @global_preferences_registry.register class SiteTitle(BooleanPreference): section = configuration name = 'prelaunch_mode' default = False
from django.utils.translation import gettext_lazy as _ from dynamic_preferences.preferences import Section from dynamic_preferences.types import StringPreference from dynamic_preferences.users.registries import user_preferences_registry general = Section("general", _("General")) @user_preferences_registry.register class PreferredLanguage(StringPreference): section = general name = "preferred_language" default = "" verbose_name = _("Preferred Language") @user_preferences_registry.register class Timezone(StringPreference): section = general name = "timezone" default = "" verbose_name = _("Timezone")
from dynamic_preferences.types import StringPreference from dynamic_preferences.preferences import Section from dynamic_preferences.registries import global_preferences_registry # Define preferences section for finance. finance = Section('Finance') # Register input for Reset prefix @global_preferences_registry.register class ResetPrefix(StringPreference): section = finance name = 'reset_prefix' default = '' verbose_name = "Documentnumber prefix for reset receipts" # Register input for currency @global_preferences_registry.register class Currency(StringPreference): section = finance name = 'currency' default = '€' verbose_name = "Currency sign" # Register input for currency @global_preferences_registry.register class AccountingYear(StringPreference): section = finance name = 'accounting_year'
from django.utils.translation import gettext_lazy as _ from dynamic_preferences.preferences import Section from dynamic_preferences.types import BooleanPreference, IntegerPreference from aleksis.core.registries import person_preferences_registry, site_preferences_registry chronos = Section("chronos", verbose_name=_("Timetables")) @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.")
from dynamic_preferences.preferences import Section from dynamic_preferences.registries import global_preferences_registry from dynamic_preferences.types import StringPreference dashboard = Section('dashboard') @global_preferences_registry.register class CoinBlackList(StringPreference): section = dashboard name = 'coinBlackList' default = ''
from dynamic_preferences.preferences import Section from dynamic_preferences.registries import global_preferences_registry from dynamic_preferences.types import ChoicePreference, IntegerPreference from dynamic_preferences.users.registries import user_preferences_registry from .lib.lang import get_ocr_lang_choices, get_default_ocr_lang ocr = Section('ocr') system_settings = Section('system_settings') user_views = Section('views') @global_preferences_registry.register class UserStorageSize(IntegerPreference): help_text = """ Storage size allocated for users. It is expressed in MB. """ section = system_settings name = "user_storage_size" default = 128 * 1024 @user_preferences_registry.register class DocumentsView(ChoicePreference): help_text = """ Display documents as grid or list view """ section = user_views name = "documents_view" choices = (('grid', 'Grid'), ('list', 'List')) default = 'grid'
from django.utils.translation import gettext_lazy as _ from djmoney.settings import CURRENCY_CHOICES from dynamic_preferences.preferences import Section from dynamic_preferences.registries import global_preferences_registry from dynamic_preferences.types import ChoicePreference contributions = Section("contributions", _("Contributions")) @global_preferences_registry.register class PreferredCurrency(ChoicePreference): section = contributions name = "currency" default = "EUR" verbose_name = _("Preferred Currency") choices = CURRENCY_CHOICES
class BirthDateTime(DateTimePreference): section = Section('child', verbose_name='Child Section Verbose Name') name = 'BirthDateTime' default = datetime(1992, 5, 4, 3, 4, 10, 150, FixedOffset(offset=330))
from dynamic_preferences.preferences import Section from dynamic_preferences.registries import global_preferences_registry from dynamic_preferences.types import StringPreference dhis2_settings = Section("DHIS2_Settings") @global_preferences_registry.register class DHIS2_URL(StringPreference): section = dhis2_settings verbose_name = "DHIS2 URL" name = "DHIS2_URL" default = "http://localhost:8080" @global_preferences_registry.register class DHIS2_USERNAME(StringPreference): section = dhis2_settings verbose_name = "DHIS2 USERNAME" name = "DHIS2_USERNAME" default = "admin" @global_preferences_registry.register class DHIS2_PASSWORD(StringPreference): section = dhis2_settings verbose_name = "DHIS2 PASSWORD" name = "DHIS2_PASSWORD" default = "district"