Python django.contrib.admin.options.VERTICAL Examples

The following are 14 code examples of django.contrib.admin.options.VERTICAL(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module django.contrib.admin.options , or try the search function .
Example #1
Source File: checks.py    From GTDWeb with GNU General Public License v2.0 6 votes vote down vote up
def _check_radio_fields_value(self, cls, model, val, label):
        """ Check type of a value of `radio_fields` dictionary. """

        from django.contrib.admin.options import HORIZONTAL, VERTICAL

        if val not in (HORIZONTAL, VERTICAL):
            return [
                checks.Error(
                    "The value of '%s' must be either admin.HORIZONTAL or admin.VERTICAL." % label,
                    hint=None,
                    obj=cls,
                    id='admin.E024',
                )
            ]
        else:
            return [] 
Example #2
Source File: checks.py    From openhgsenti with Apache License 2.0 6 votes vote down vote up
def _check_radio_fields_value(self, obj, val, label):
        """ Check type of a value of `radio_fields` dictionary. """

        from django.contrib.admin.options import HORIZONTAL, VERTICAL

        if val not in (HORIZONTAL, VERTICAL):
            return [
                checks.Error(
                    "The value of '%s' must be either admin.HORIZONTAL or admin.VERTICAL." % label,
                    hint=None,
                    obj=obj.__class__,
                    id='admin.E024',
                )
            ]
        else:
            return [] 
Example #3
Source File: validation.py    From GTDWeb with GNU General Public License v2.0 5 votes vote down vote up
def validate_radio_fields(self, cls, model):
        " Validate that radio_fields is a dictionary of choice or foreign key fields. "
        from django.contrib.admin.options import HORIZONTAL, VERTICAL
        if hasattr(cls, 'radio_fields'):
            check_isdict(cls, 'radio_fields', cls.radio_fields)
            for field, val in cls.radio_fields.items():
                f = get_field(cls, model, 'radio_fields', field)
                if not (isinstance(f, models.ForeignKey) or f.choices):
                    raise ImproperlyConfigured("'%s.radio_fields['%s']' "
                            "is neither an instance of ForeignKey nor does "
                            "have choices set." % (cls.__name__, field))
                if val not in (HORIZONTAL, VERTICAL):
                    raise ImproperlyConfigured("'%s.radio_fields['%s']' "
                            "is neither admin.HORIZONTAL nor admin.VERTICAL."
                            % (cls.__name__, field)) 
Example #4
Source File: checks.py    From bioforum with MIT License 5 votes vote down vote up
def _check_radio_fields_value(self, obj, val, label):
        """ Check type of a value of `radio_fields` dictionary. """

        from django.contrib.admin.options import HORIZONTAL, VERTICAL

        if val not in (HORIZONTAL, VERTICAL):
            return [
                checks.Error(
                    "The value of '%s' must be either admin.HORIZONTAL or admin.VERTICAL." % label,
                    obj=obj.__class__,
                    id='admin.E024',
                )
            ]
        else:
            return [] 
Example #5
Source File: checks.py    From Hands-On-Application-Development-with-PyCharm with MIT License 5 votes vote down vote up
def _check_radio_fields_value(self, obj, val, label):
        """ Check type of a value of `radio_fields` dictionary. """

        from django.contrib.admin.options import HORIZONTAL, VERTICAL

        if val not in (HORIZONTAL, VERTICAL):
            return [
                checks.Error(
                    "The value of '%s' must be either admin.HORIZONTAL or admin.VERTICAL." % label,
                    obj=obj.__class__,
                    id='admin.E024',
                )
            ]
        else:
            return [] 
Example #6
Source File: checks.py    From python with Apache License 2.0 5 votes vote down vote up
def _check_radio_fields_value(self, obj, val, label):
        """ Check type of a value of `radio_fields` dictionary. """

        from django.contrib.admin.options import HORIZONTAL, VERTICAL

        if val not in (HORIZONTAL, VERTICAL):
            return [
                checks.Error(
                    "The value of '%s' must be either admin.HORIZONTAL or admin.VERTICAL." % label,
                    obj=obj.__class__,
                    id='admin.E024',
                )
            ]
        else:
            return [] 
Example #7
Source File: checks.py    From python2017 with MIT License 5 votes vote down vote up
def _check_radio_fields_value(self, obj, val, label):
        """ Check type of a value of `radio_fields` dictionary. """

        from django.contrib.admin.options import HORIZONTAL, VERTICAL

        if val not in (HORIZONTAL, VERTICAL):
            return [
                checks.Error(
                    "The value of '%s' must be either admin.HORIZONTAL or admin.VERTICAL." % label,
                    obj=obj.__class__,
                    id='admin.E024',
                )
            ]
        else:
            return [] 
Example #8
Source File: test_checks.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_missing_field(self):
        class TestModelAdmin(ModelAdmin):
            radio_fields = {'non_existent_field': VERTICAL}

        self.assertIsInvalid(
            TestModelAdmin, ValidationTestModel,
            "The value of 'radio_fields' refers to 'non_existent_field', "
            "which is not an attribute of 'modeladmin.ValidationTestModel'.",
            'admin.E022'
        ) 
Example #9
Source File: test_checks.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_invalid_field_type(self):
        class TestModelAdmin(ModelAdmin):
            radio_fields = {'name': VERTICAL}

        self.assertIsInvalid(
            TestModelAdmin, ValidationTestModel,
            "The value of 'radio_fields' refers to 'name', which is not an instance "
            "of ForeignKey, and does not have a 'choices' definition.",
            'admin.E023'
        ) 
Example #10
Source File: test_checks.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_invalid_value(self):
        class TestModelAdmin(ModelAdmin):
            radio_fields = {'state': None}

        self.assertIsInvalid(
            TestModelAdmin, ValidationTestModel,
            "The value of 'radio_fields[\"state\"]' must be either admin.HORIZONTAL or admin.VERTICAL.",
            'admin.E024'
        ) 
Example #11
Source File: test_checks.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_valid_case(self):
        class TestModelAdmin(ModelAdmin):
            radio_fields = {'state': VERTICAL}

        self.assertIsValid(TestModelAdmin, ValidationTestModel) 
Example #12
Source File: test_checks.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_missing_field(self):
        class TestModelAdmin(ModelAdmin):
            radio_fields = {'non_existent_field': VERTICAL}

        self.assertIsInvalid(
            TestModelAdmin, ValidationTestModel,
            "The value of 'radio_fields' refers to 'non_existent_field', "
            "which is not an attribute of 'modeladmin.ValidationTestModel'.",
            'admin.E022'
        ) 
Example #13
Source File: test_checks.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_invalid_value(self):
        class TestModelAdmin(ModelAdmin):
            radio_fields = {'state': None}

        self.assertIsInvalid(
            TestModelAdmin, ValidationTestModel,
            "The value of 'radio_fields[\"state\"]' must be either admin.HORIZONTAL or admin.VERTICAL.",
            'admin.E024'
        ) 
Example #14
Source File: test_checks.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_valid_case(self):
        class TestModelAdmin(ModelAdmin):
            radio_fields = {'state': VERTICAL}

        self.assertIsValid(TestModelAdmin, ValidationTestModel)