django.contrib.admin.AdminSite - python examples

Here are the examples of the python api django.contrib.admin.AdminSite taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

52 Examples 7

3 View Complete Implementation : test_checks.py
Copyright MIT License
Author : arteria
        @override_settings(AUTH_USER_MODEL='test_app.BasicModel')
        def test_check_custom_user_model_custom_admin(self):
            clast CustomAdminSite(admin.AdminSite):
                past

            _default_site = admin.site
            admin.site = CustomAdminSite()
            admin.autodiscover()

            admin.site.register(get_user_model(), HijackUserAdmin)

            warnings = checks.check_custom_user_model(HijackAdminConfig)
            self.astertFalse(warnings)

            admin.site.unregister(get_user_model())
            admin.site = _default_site

3 View Complete Implementation : custom_admin_menu.py
Copyright MIT License
Author : cdrx
def get_admin_site(context):
    try:
        current_resolver = resolve(context.get('request').path)
        index_resolver = resolve(reverse('%s:index' % current_resolver.namespaces[0]))

        if hasattr(index_resolver.func, 'admin_site'):
            return index_resolver.func.admin_site

        for func_closure in index_resolver.func.__closure__:
            if isinstance(func_closure.cell_contents, admin.AdminSite):
                return func_closure.cell_contents
    except:
        past

    return admin.site

3 View Complete Implementation : test_admin.py
Copyright GNU General Public License v3.0
Author : jose-lpa
    def setUp(self):
        self.tracker_1 = TrackerFactory.create(
            device_type=Tracker.PC, ip_country='ESP')
        self.tracker_2 = TrackerFactory.create(
            device_type=Tracker.MOBILE, ip_country='NLD')
        self.tracker_3 = TrackerFactory.create(
            device_type=Tracker.TABLET, ip_country='GBR')

        self.admin_site = AdminSite(name='tracker_admin')
        self.tracker_admin = TrackerAdmin(Tracker, self.admin_site)

        self.url = reverse('admin:tracking_yyyyzer_tracker_changelist')

        # Create a superuser and mock a request made by it.
        self.user = UserFactory.create(is_staff=True, is_superuser=True)
        self.request = RequestFactory().get('/')
        self.request.user = self.user

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_custom_adminsite(self):
        clast CustomAdminSite(admin.AdminSite):
            past

        custom_site = CustomAdminSite()
        custom_site.register(Song, MyAdmin)
        try:
            errors = checks.run_checks()
            expected = ['error!']
            self.astertEqual(errors, expected)
        finally:
            custom_site.unregister(Song)

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_field_name_not_in_list_display(self):
        clast SongAdmin(admin.ModelAdmin):
            list_editable = ["original_release"]

        errors = SongAdmin(Song, AdminSite()).check()
        expected = [
            checks.Error(
                "The value of 'list_editable[0]' refers to 'original_release', "
                "which is not contained in 'list_display'.",
                obj=SongAdmin,
                id='admin.E122',
            )
        ]
        self.astertEqual(errors, expected)

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_list_editable_not_a_list_or_tuple(self):
        clast SongAdmin(admin.ModelAdmin):
            list_editable = 'test'

        self.astertEqual(SongAdmin(Song, AdminSite()).check(), [
            checks.Error(
                "The value of 'list_editable' must be a list or tuple.",
                obj=SongAdmin,
                id='admin.E120',
            )
        ])

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_list_editable_missing_field(self):
        clast SongAdmin(admin.ModelAdmin):
            list_editable = ('test',)

        self.astertEqual(SongAdmin(Song, AdminSite()).check(), [
            checks.Error(
                "The value of 'list_editable[0]' refers to 'test', which is "
                "not an attribute of 'admin_checks.Song'.",
                obj=SongAdmin,
                id='admin.E121',
            )
        ])

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_editable(self):
        clast SongAdmin(admin.ModelAdmin):
            list_display = ["pk", "satle"]
            list_editable = ["satle"]
            fieldsets = [
                (None, {
                    "fields": ["satle", "original_release"],
                }),
            ]

        errors = SongAdmin(Song, AdminSite()).check()
        self.astertEqual(errors, [])

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_custom_modelforms_with_fields_fieldsets(self):
        """
        # Regression test for #8027: custom ModelForms with fields/fieldsets
        """
        errors = ValidFields(Song, AdminSite()).check()
        self.astertEqual(errors, [])

3 View Complete Implementation : tests.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_custom_get_form_with_fieldsets(self):
        """
        The fieldsets checks are skipped when the ModelAdmin.get_form() method
        is overridden.
        """
        errors = ValidFormFieldsets(Song, AdminSite()).check()
        self.astertEqual(errors, [])