当前位置: 首页>>代码示例>>Python>>正文


Python sites.AdminSite类代码示例

本文整理汇总了Python中django.contrib.admin.sites.AdminSite的典型用法代码示例。如果您正苦于以下问题:Python AdminSite类的具体用法?Python AdminSite怎么用?Python AdminSite使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了AdminSite类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestCflatpagesAdmin

class TestCflatpagesAdmin(TestCase):
    def setUp(self):
        self.site = AdminSite()

    def test_category_admin(self):
        """
        Category admin
        """
        self.assertIsNone(self.site.register(models.Category, admin.CategoryAdmin))

    def test_page_admin(self):
        """
        Page admin
        """
        self.assertIsNone(self.site.register(models.CFlatPage, admin.CategorizedFlatPageAdmin))

    @override_settings()
    def test_page_settings_admin(self):
        """
        Page admin
        """
        settings.INSTALLED_APPS = settings.INSTALLED_APPS + ["ckeditor"]
        self.assertIsNone(self.site.register(models.CFlatPage, admin.CategorizedFlatPageAdmin))

    def tearDown(self):
        pass
开发者ID:eugena,项目名称:django-categorized-flatpages,代码行数:26,代码来源:test_admin.py

示例2: test_autocomplete_is_valid

    def test_autocomplete_is_valid(self):
        class SearchFieldsAdmin(ModelAdmin):
            search_fields = 'name'

        class AutocompleteAdmin(ModelAdmin):
            autocomplete_fields = ('featuring',)

        site = AdminSite()
        site.register(Band, SearchFieldsAdmin)
        self.assertIsValid(AutocompleteAdmin, Song, admin_site=site)
开发者ID:czpython,项目名称:django,代码行数:10,代码来源:test_checks.py

示例3: test_autocomplete_is_onetoone

    def test_autocomplete_is_onetoone(self):
        class UserAdmin(ModelAdmin):
            search_fields = ('name',)

        class Admin(ModelAdmin):
            autocomplete_fields = ('best_friend',)

        site = AdminSite()
        site.register(User, UserAdmin)
        self.assertIsValid(Admin, ValidationTestModel, admin_site=site)
开发者ID:czpython,项目名称:django,代码行数:10,代码来源:test_checks.py

示例4: StatsAdminTests

class StatsAdminTests(TestCase):
    def setUp(self):
        self.admin_site = AdminSite()
        patch_admin(self.admin_site)
        self.factory = RequestFactory()

    def test_modelstats_overview_called(self):
        """Test that the overview function on the ModelStats object is called
        by the overview function on the admin site.
        """
        class TestModelStats(ModelStats):
            slug = 'unique_slug'
        self.admin_site.register_stats(TestModel, TestModelStats)

        with patch.object(TestModelStats, 'overview') as overview:
            eq_(overview.called, False)
            self.admin_site.overview(self.factory.get('/test'), 'unique_slug')
            eq_(overview.called, True)

    def test_unique_slugs(self):
        """Test that the admin site generates unique slugs for multiple
        ModelStats that have identical slugs.
        """
        class TestModelStats(ModelStats):
            slug = 'unique_slug'
        self.admin_site.register_stats(TestModel, TestModelStats)

        class TestModelStats2(ModelStats):
            slug = 'unique_slug'
        self.admin_site.register_stats(TestModel, TestModelStats2)

        # If slugs were identical, there would be only 1 stat here.
        eq_(len(self.admin_site.stats), 2)
开发者ID:Hugochazz,项目名称:affiliates,代码行数:33,代码来源:test_sites.py

示例5: display_login_form

 def display_login_form(request, error_message='', 
         extra_context=None):
     extra_context = extra_context or {}
     extra_context['openid_path'] = openid_path
     return AdminSite.display_login_form(
         bind_to_me, request, error_message, extra_context
     )
开发者ID:amephraim,项目名称:compass-site,代码行数:7,代码来源:auth.py

示例6: setUp

 def setUp(self):
     self.band = Band.objects.create(
         name='The Doors',
         bio='',
         sign_date=date(1965, 1, 1),
     )
     self.site = AdminSite()
开发者ID:ArcTanSusan,项目名称:django,代码行数:7,代码来源:tests.py

示例7: lazy_registration

 def lazy_registration(self):
     # First, directly handle models we don't want at all,
     # as per the ``ADMIN_REMOVAL`` setting.
     for model in getattr(settings, "ADMIN_REMOVAL", []):
         try:
             model = tuple(model.rsplit(".", 1))
             exec("from %s import %s" % model)
         except ImportError:
             pass
         else:
             try:
                 AdminSite.unregister(self, eval(model[1]))
             except NotRegistered:
                 pass
     # Call register/unregister.
     for name, deferred_args, deferred_kwargs in self._deferred:
         getattr(AdminSite, name)(self, *deferred_args, **deferred_kwargs)
开发者ID:AliLozano,项目名称:mezzanine,代码行数:17,代码来源:lazy_admin.py

示例8: test_validation_only_runs_in_debug

    def test_validation_only_runs_in_debug(self):
        # Ensure validation only runs when DEBUG = True
        with override_settings(DEBUG=True):
            class ValidationTestModelAdmin(ModelAdmin):
                raw_id_fields = 10

            site = AdminSite()

            six.assertRaisesRegex(self,
                ImproperlyConfigured,
                "'ValidationTestModelAdmin.raw_id_fields' must be a list or tuple.",
                site.register,
                ValidationTestModel,
                ValidationTestModelAdmin,
            )

        with override_settings(DEBUG=False):
            site = AdminSite()
            site.register(ValidationTestModel, ValidationTestModelAdmin)
开发者ID:OleLaursen,项目名称:django,代码行数:19,代码来源:tests.py

示例9: test_autocomplete_e040

    def test_autocomplete_e040(self):
        class NoSearchFieldsAdmin(ModelAdmin):
            pass

        class AutocompleteAdmin(ModelAdmin):
            autocomplete_fields = ('featuring',)

        site = AdminSite()
        site.register(Band, NoSearchFieldsAdmin)
        self.assertIsInvalid(
            AutocompleteAdmin, Song,
            msg=(
                'NoSearchFieldsAdmin must define "search_fields", because '
                'it\'s referenced by AutocompleteAdmin.autocomplete_fields.'
            ),
            id='admin.E040',
            invalid_obj=AutocompleteAdmin,
            admin_site=site,
        )
开发者ID:czpython,项目名称:django,代码行数:19,代码来源:test_checks.py

示例10: test_validation_only_runs_in_debug

    def test_validation_only_runs_in_debug(self):
        # Ensure validation only runs when DEBUG = True
        try:
            settings.DEBUG = True

            class ValidationTestModelAdmin(ModelAdmin):
                raw_id_fields = 10

            site = AdminSite()

            self.assertRaisesRegexp(
                ImproperlyConfigured,
                "'ValidationTestModelAdmin.raw_id_fields' must be a list or tuple.",
                site.register,
                ValidationTestModel,
                ValidationTestModelAdmin,
            )
        finally:
            settings.DEBUG = False

        site = AdminSite()
        site.register(ValidationTestModel, ValidationTestModelAdmin)
开发者ID:MyaThandarKyaw,项目名称:django,代码行数:22,代码来源:tests.py

示例11: lazy_registration

 def lazy_registration(self):
     # First pick up any admin classes registered via decorator to the
     # default admin site.
     for model, admin in default_site._registry.items():
         self._deferred.append(("register", (model, admin.__class__), {}))
     # Call register/unregister.
     for name, args, kwargs in self._deferred:
         try:
             getattr(AdminSite, name)(self, *args, **kwargs)
         except (AlreadyRegistered, NotRegistered):
             pass
     # Then handle models we don't want at all,
     # as per the ``ADMIN_REMOVAL`` setting.
     for model in getattr(settings, "ADMIN_REMOVAL", []):
         try:
             model = tuple(model.rsplit(".", 1))
             exec("from %s import %s" % model)
         except ImportError:
             pass
         else:
             try:
                 AdminSite.unregister(self, eval(model[1]))
             except NotRegistered:
                 pass
开发者ID:ctrengove,项目名称:mezzanine,代码行数:24,代码来源:lazy_admin.py

示例12: AdminSite

from django.contrib.admin.sites import AdminSite
from libscampi.contrib.cms.renaissance import models as renaissance_models, admin as renaissance_admin
from libscampi.contrib.cms.conduit import models as conduit_models, admin as conduit_admin
from libscampi.contrib.cms.communism import models as communism_models, admin as communism_admin
from libscampi.contrib.cms.newsengine import models as newsengine_models, admin as newsengine_admin

cms_admin = AdminSite()

# Admin for communism
cms_admin.register(communism_models.Theme)
cms_admin.register(communism_models.StyleSheet, communism_admin.GenericDOMElementAdmin)
cms_admin.register(communism_models.Javascript, communism_admin.GenericDOMElementAdmin)
cms_admin.register(communism_models.Realm, communism_admin.RealmAdmin)
cms_admin.register(communism_models.RealmNotification, communism_admin.RealmNotificationAdmin)
cms_admin.register(communism_models.Section, communism_admin.SectionAdmin)
cms_admin.register(communism_models.Slice, communism_admin.SliceAdmin)
cms_admin.register(communism_models.NamedBox, communism_admin.BoxAdmin)
cms_admin.register(communism_models.Commune, communism_admin.CommuneAdmin)
cms_admin.register(communism_models.Application, communism_admin.ApplicationAdmin)

# Admin for conduit
cms_admin.register(conduit_models.DynamicPicker, conduit_admin.DynamicPickerAdmin)
cms_admin.register(conduit_models.StaticPicker)
cms_admin.register(conduit_models.PickerTemplate, conduit_admin.PickerTemplateAdmin)

# Admin for newsengine
cms_admin.register(newsengine_models.Article, newsengine_admin.ArticleAdmin)
cms_admin.register(newsengine_models.ArticleTranslation)
cms_admin.register(newsengine_models.StoryCategory)
cms_admin.register(newsengine_models.Story, newsengine_admin.StoryAdmin)
cms_admin.register(newsengine_models.PublishCategory, newsengine_admin.PublishCategoryAdmin)
开发者ID:azpm,项目名称:django-scampi-cms,代码行数:31,代码来源:admin.py

示例13: UserSite


class UserSite(AdminSite):

    login_form = UserAuthenticationForm

    def has_permission(self, request):
        """
        Allow all users which are in 'users' group.
        """
        return request.user.is_active \
            and request.user.groups.filter(name='users').count()


admin = SuperAdminSite(name='admin')
staff = AdminSite(name='staff')
user = UserSite(name='user')


# admin
admin.register(Site, SiteAdmin)
admin.register(User, UserAdmin)
admin.register(Group, GroupAdmin)

admin.register(Author, AuthorAdmin)
admin.register(BookCategory, BookCategoryAdmin)
admin.register(Book, BookAdmin)
admin.register(CdCategory, CdCategoryAdmin)
admin.register(Cd, CdAdmin)
admin.register(DvdCategory, DvdCategoryAdmin)
admin.register(Dvd, DvdAdmin)
开发者ID:burhan,项目名称:django-wpadmin,代码行数:29,代码来源:admin.py

示例14: AdminSite

from django.contrib import admin

from django.forms import ModelForm
from django.contrib.auth.models import User

from django.core.exceptions import ObjectDoesNotExist

from productions.models import *
from auditions.models import *

from django.contrib.admin.sites import AdminSite

admin_site = AdminSite()

# Allow administration of admin users
admin_site.register(User)

# Allow administration of productions
admin_site.register(ProductionType)

class ProductionAdmin(admin.ModelAdmin):
  list_display = ('name', 'default_production')
  
admin_site.register(Production, ProductionAdmin)

# The form which is used for each audition when editing an actor.
class AuditionInlineForm(ModelForm):
  model = Audition
  
  def __init__(self, *args, **kwargs):
    super(AuditionInlineForm, self).__init__(*args, **kwargs)
开发者ID:alogic,项目名称:AuditionManager,代码行数:31,代码来源:admin.py

示例15: check_in

    #             'fields':('checkin_time','checkin_station')
    #             }),
#    )
  date_hierarchy = 'checkin_time'
  ordering = ('-checkout_time',)
  actions = ['check_in']
  search_fields = ['rider__name','rider__penncard','bike__bike_name']
  save_on_top = True
##  change_form_template = 'c:/djcode/penncycle/templates/admin/app/change_form.html'

  # make this only work for bikes not already checked in
  # def check_in(self, request, queryset):
  #   return RidesAdmin.check_in(self, request, queryset)
  # check_in = admin_check_in

  def add_view(self, request, extra_context={}):
    try:
      station = request.user.groups.exclude(name='Associate')[0].name
    except:
      email_razzi("{} tried to sign somebody in it would seem. They were told to check their /admin/auth/user status. They had groups {}".format(request.user.get_full_name(), request.user.groups.all()))
      return HttpResponse("You don't have any groups. Go to app.penncycle.org/admin/auth/user and make sure 'associate' and your station are checked.")
    extra_context['station'] = station
    return super(pcRidesAdmin, self).add_view(request, extra_context=extra_context)

pcAdminSite = AdminSite(name='pcadmin')
pcAdminSite.register(Ride, pcRidesAdmin)
pcAdminSite.register(Payment, PaymentAdmin)
pcAdminSite.register(Bike, BikeAdmin)
pcAdminSite.register(Student, StudentAdmin)
pcAdminSite.register(Comment)
# pcAdminSite.register(Station)
开发者ID:rattrayalex,项目名称:PennCycle,代码行数:31,代码来源:pc_admin.py


注:本文中的django.contrib.admin.sites.AdminSite类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。