Пример #1
0
 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)
Пример #2
0
 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)
Пример #3
0
    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'])
Пример #4
0
    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'])
Пример #5
0
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
Пример #7
0
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'])
Пример #8
0
 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')
Пример #9
0
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
Пример #10
0
 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')
Пример #11
0
 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')
Пример #12
0
def suit_time(parser, token):
    return NowNode(get_config('HEADER_TIME_FORMAT'))
Пример #13
0
def suit_date(parser, token):
    return NowNode(get_config('HEADER_DATE_FORMAT'))
Пример #14
0
def suit_conf(name):
    value = get_config(name)
    return mark_safe(value) if isinstance(value, str) else value
Пример #15
0
def suit_time(parser, token):
    return NowNode(get_config('HEADER_TIME_FORMAT'))
Пример #16
0
def suit_date(parser, token):
    return NowNode(get_config('HEADER_DATE_FORMAT'))
Пример #17
0
def suit_conf(name):
    value = get_config(name)
    return mark_safe(value) if isinstance(value, str) else value
Пример #18
0
def suit_conf(name, request):
    value = config.get_config(name, request)
    return mark_safe(value) if isinstance(value, str) else value
Пример #19
0
 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)
Пример #20
0
 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'))
Пример #21
0
 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')
Пример #22
0
 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'))
Пример #23
0
 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)