def test_suit_config_when_defined_but_no_key(self): settings.SUIT_CONFIG = {'RANDOM_KEY': 123} default_suit_config = default_config() self.assertEqual(get_config('ADMIN_NAME'), default_suit_config['ADMIN_NAME']) # Defined as empty, should stay empty admin_name = '' settings.SUIT_CONFIG = {'ADMIN_NAME': admin_name} self.assertEqual(get_config('ADMIN_NAME'), admin_name)
def test_suit_config_when_defined_but_no_key(self): settings.SUIT_CONFIG = { 'RANDOM_KEY': 123 } default_suit_config = default_config() self.assertEqual(get_config('ADMIN_NAME'), default_suit_config['ADMIN_NAME']) # Defined as empty, should stay empty admin_name = '' settings.SUIT_CONFIG = { 'ADMIN_NAME': admin_name } self.assertEqual(get_config('ADMIN_NAME'), admin_name)
def test_suit_config_when_not_defined(self): try: del settings.SUIT_CONFIG except AttributeError: pass default_suit_config = default_config() self.assertEqual(get_config('ADMIN_NAME'), default_suit_config['ADMIN_NAME']) # Defined as None, should also use fallback admin_name = None settings.SUIT_CONFIG = {'ADMIN_NAME': admin_name} self.assertEqual(get_config('ADMIN_NAME'), default_suit_config['ADMIN_NAME'])
def test_suit_config_when_not_defined(self): try: del settings.SUIT_CONFIG except AttributeError: pass default_suit_config = default_config() self.assertEqual(get_config('ADMIN_NAME'), default_suit_config['ADMIN_NAME']) # Defined as None, should also use fallback admin_name = None settings.SUIT_CONFIG = { 'ADMIN_NAME': admin_name } self.assertEqual(get_config('ADMIN_NAME'), default_suit_config['ADMIN_NAME'])
def suit_body_class(value, request): css_classes = [] config_vars_to_add = ['toggle_changelist_top_actions', 'form_submit_on_right', 'layout'] for each in config_vars_to_add: suit_conf_param = getattr(config.get_config(None, request), each, None) if suit_conf_param: value = each if isinstance(suit_conf_param, bool) \ else '_'.join((each, suit_conf_param)) css_classes.append('suit_%s' % value) return ' '.join(css_classes)
def get_form_size(fieldset): form_size_by_config = get_config('form_size') # Fallback to model admin definition form_size_by_model_admin = getattr(fieldset.model_admin, 'suit_form_size', {}) form_size = {} form_size.update(form_size_by_config) form_size.update(form_size_by_model_admin) return form_size
def suit_form_conf(context, param_name, inline_admin_formset=None): """ Get form config param """ if inline_admin_formset: model_admin = inline_admin_formset.opts else: model_admin = context['adminform'].model_admin param_by_model_admin = getattr(model_admin, 'suit_%s' % param_name, None) if param_by_model_admin is not None: return param_by_model_admin return get_config(param_name, context['request'])
def init_config(self): self.conf_exclude = get_config('MENU_EXCLUDE') self.conf_open_first_child = get_config('MENU_OPEN_FIRST_CHILD') self.conf_icons = get_config('MENU_ICONS') self.conf_menu_order = get_config('MENU_ORDER') self.conf_menu = get_config('MENU') self.conf_menu_append = get_config('MENU_APPEND')
def get_form_size(fieldset): default_label_class = get_config('form_size').split(':') # Try fieldset definition at first size_by_fieldset = get_fieldset_size(fieldset) if size_by_fieldset: return size_by_fieldset # Fallback to model admin definition ma_sizes = getattr(fieldset.model_admin, 'suit_form_size', None) if ma_sizes: return ma_sizes.split(':') # Use default values at last return default_label_class
def init_config(self): self.conf_exclude = get_config('menu_exclude') self.conf_open_first_child = get_config('menu_open_first_child') self.conf_icons = get_config('menu_icons') self.conf_menu_order = get_config('menu_order') self.conf_menu = get_config('menu')
def init_config(self): self.conf_exclude = get_config('MENU_EXCLUDE') self.conf_open_first_child = get_config('MENU_OPEN_FIRST_CHILD') self.conf_icons = get_config('MENU_ICONS') self.conf_menu_order = get_config('MENU_ORDER') self.conf_menu = get_config('MENU')
def suit_time(parser, token): return NowNode(get_config('HEADER_TIME_FORMAT'))
def suit_date(parser, token): return NowNode(get_config('HEADER_DATE_FORMAT'))
def suit_conf(name): value = get_config(name) return mark_safe(value) if isinstance(value, str) else value
def suit_conf(name, request): value = config.get_config(name, request) return mark_safe(value) if isinstance(value, str) else value
def test_suit_config_when_defined(self): admin_name = 'Custom Name' settings.SUIT_CONFIG = {'ADMIN_NAME': admin_name} self.assertEqual(get_config('ADMIN_NAME'), admin_name)
def test_django_modeladmin_overrides(self): self.assertEqual(ModelAdmin.actions_on_top, False) self.assertEqual(ModelAdmin.actions_on_bottom, True) self.assertEqual(ModelAdmin.list_per_page, get_config('LIST_PER_PAGE'))
def test_suit_config_when_defined(self): admin_name = 'Custom Name' settings.SUIT_CONFIG = { 'ADMIN_NAME': admin_name } self.assertEqual(get_config('ADMIN_NAME'), admin_name)