Example #1
0
 def setUp(self):
     site = admin.AdminSite()
     self.hijacked_admin = versioning_admin.VersionAdmin(Version, site)
Example #2
0
class WorkerInlineAdmin(admin.TabularInline):
    model = Worker

    def view_on_site(self, obj):
        return '/worker_inline/%s/%s/' % (obj.surname, obj.name)


class RestaurantAdmin(admin.ModelAdmin):
    inlines = [WorkerInlineAdmin]
    view_on_site = False

    def get_changeform_initial_data(self, request):
        return {'name': 'overridden_value'}


site = admin.AdminSite(name="admin")
site.register(Article, ArticleAdmin)
site.register(CustomArticle, CustomArticleAdmin)
site.register(Section, save_as=True, inlines=[ArticleInline])
site.register(ModelWithStringPrimaryKey)
site.register(Color)
site.register(Thing, ThingAdmin)
site.register(Actor)
site.register(Inquisition, InquisitionAdmin)
site.register(Sketch, SketchAdmin)
site.register(Person, PersonAdmin)
site.register(Persona, PersonaAdmin)
site.register(Subscriber, SubscriberAdmin)
site.register(ExternalSubscriber, ExternalSubscriberAdmin)
site.register(OldSubscriber, OldSubscriberAdmin)
site.register(Podcast, PodcastAdmin)
 def setUp(self):
     site = admin.AdminSite()
     model_admin = short_text_field.admin.ModelAdmin(TestModel,
                                                     admin_site=site)
     self.field = model_admin.get_form(request).base_fields['test_field']
Example #4
0
from django.conf.urls import patterns, include
from django.contrib import admin
from django_comments.admin import CommentsAdmin
from django_comments.models import Comment

# Make a new AdminSite to avoid picking up the deliberately broken admin
# modules in other tests.
admin_site = admin.AdminSite()
admin_site.register(Comment, CommentsAdmin)

# To demonstrate proper functionality even when ``delete_selected`` is removed.
admin_site2 = admin.AdminSite()
admin_site2.disable_action('delete_selected')
admin_site2.register(Comment, CommentsAdmin)

urlpatterns = patterns('',
    (r'^admin/', include(admin_site.urls)),
    (r'^admin2/', include(admin_site2.urls)),
)
Example #5
0
File: admin.py Project: jaeh/mos
from django.contrib import admin
from django.contrib.auth.models import User

from mos.cal.models import Event, Category, Location
from mos.members.models import MemberAdmin
from mos.projects.models import Project
from mos.scrooge.models import Account, AccountAdmin, Product, ProductAdmin

#models for event admin site
calendar_admin = admin.AdminSite()
calendar_admin.register(Event)
calendar_admin.register(Category)
calendar_admin.register(Location)

#models for project admin site
project_admin = admin.AdminSite()
project_admin.register(Project)

#models for user admin site
member_admin = admin.AdminSite()
member_admin.register(User, MemberAdmin)

#models for scrooge
scrooge_admin = admin.AdminSite()
scrooge_admin.register(Account, AccountAdmin)
#scrooge_admin.register(Account)
scrooge_admin.register(Product, ProductAdmin)

Example #6
0

register_seo_admin(admin.site, Coverage)
register_seo_admin(admin.site, WithSites)

try:
    admin.site.register(Product, admin.ModelAdmin)
except admin.sites.AlreadyRegistered:
    pass
try:
    admin.site.register(Page, admin.ModelAdmin)
except admin.sites.AlreadyRegistered:
    pass
try:
    admin.site.register(Tag, WithMetadataAdmin)
except admin.sites.AlreadyRegistered:
    pass
try:
    admin.site.register(NoPath, WithMetadataAdmin)
except admin.sites.AlreadyRegistered:
    pass

# Register alternative site here to avoid double import
alternative_site = admin.AdminSite()
alternative_site.register(Tag)
auto_register_inlines(alternative_site, Coverage)
alternative_site.register(Page)
auto_register_inlines(alternative_site, WithSites)
auto_register_inlines(alternative_site, WithSEOModels)
alternative_site.register(Product)
Example #7
0
# -*- coding: utf-8 -*-

from django.contrib import admin
import models

myadmin = admin.AdminSite()

myadmin.register(models.CameraBluetoothDongle)
myadmin.register(models.CameraRemoteDevice)
myadmin.register(models.CameraRecord)
myadmin.register(models.CameraCampaign)
Example #8
0
def reset_admin_site():
    """Return the Django admin globals to their original state"""
    admin.site = admin.AdminSite()  # restore default
    if 'djrill.admin' in sys.modules:
        del sys.modules['djrill.admin']  # force autodiscover to re-import
from django.contrib import admin
from .models import Faculty, Country, Region, Area, City, Special, Abiturient, Application
# Register your models here.
sc_admin = admin.AdminSite('sc_admin')
sc_admin.register(Faculty)
sc_admin.register(Country)
sc_admin.register(Region)
sc_admin.register(Area)
sc_admin.register(City)
sc_admin.register(Special)
sc_admin.register(Abiturient)
sc_admin.register(Application)
Example #10
0
"""
Test URLs for auth admins.
"""

from django.conf.urls import include, url
from django.contrib import admin
from django.contrib.auth.admin import GroupAdmin, UserAdmin
from django.contrib.auth.models import Group, User
from django.contrib.auth.urls import urlpatterns

# Create a silo'd admin site for just the user/group admins.
site = admin.AdminSite(name='auth_test_admin')
site.register(User, UserAdmin)
site.register(Group, GroupAdmin)

urlpatterns += [
    url(r'^admin/', include(site.urls)),
]
Example #11
0
admin.site.register(models.Object, ObjectAdmin)
admin.site.register(models.City, CityAdmin)
admin.site.register(models.Country, CountryAdmin)
admin.site.register(models.Designer, DesignerAdmin)
admin.site.register(models.Label, LabelAdmin)
admin.site.register(models.Retailer, RetailerAdmin)
admin.site.register(models.Retailer_Label, Retailer_LabelAdmin)
admin.site.register(models.Classification, ClassificationAdmin)
admin.site.register(models.Location, LocationAdmin)
admin.site.register(models.Condition, ConditionAdmin)
admin.site.register(models.Material, MaterialAdmin)
admin.site.register(models.Measurement, MeasurementAdmin)
admin.site.register(models.Type, TypeAdmin)
admin.site.register(models.Part, PartAdmin)

accession_admin = admin.AdminSite(name="tfc")
accession_admin.register(models.Accession, AccessionAdmin)
accession_admin.register(models.Donor, DonorAdmin)
accession_admin.register(models.City, CityAdmin)
accession_admin.register(models.Country, CountryAdmin)
accession_admin.register(models.Designer, DesignerAdmin)
accession_admin.register(models.Label, LabelAdmin)
accession_admin.register(models.Retailer, RetailerAdmin)
accession_admin.register(models.Retailer_Label, Retailer_LabelAdmin)
accession_admin.register(models.Classification, ClassificationAdmin)
accession_admin.register(models.Location, LocationAdmin)
accession_admin.register(models.Condition, ConditionAdmin)
accession_admin.register(models.Material, MaterialAdmin)
accession_admin.register(models.Measurement, MeasurementAdmin)
accession_admin.register(models.Type, TypeAdmin)
accession_admin.register(models.Part, PartAdmin)
Example #12
0
    nolabel_form_field = forms.BooleanField(required=False)

    class Meta:
        model = Article
        fields = ['title']

    @property
    def changed_data(self):
        data = super().changed_data
        if data:
            # Add arbitrary name to changed_data to test
            # change message construction.
            return data + ['not_a_form_field']
        return data


class ArticleInline(admin.TabularInline):
    model = Article
    fields = ['title']
    form = ArticleAdminForm


class SiteAdmin(admin.ModelAdmin):
    inlines = [ArticleInline]


site = admin.AdminSite(name='admin')
site.register(Article)
site.register(ArticleProxy)
site.register(Site, SiteAdmin)
Example #13
0
from django.contrib import admin
from django.contrib.admin.actions import delete_selected
from django.contrib.auth.models import User
from django.test import SimpleTestCase, TestCase, override_settings
from django.test.client import RequestFactory
from django.urls import path, reverse

from .models import Article

site = admin.AdminSite(name="test_adminsite")
site.register(User)
site.register(Article)

urlpatterns = [
    path('test_admin/admin/', site.urls),
]


@override_settings(ROOT_URLCONF='admin_views.test_adminsite')
class SiteEachContextTest(TestCase):
    """
    Check each_context contains the documented variables and that available_apps context
    variable structure is the expected one.
    """
    request_factory = RequestFactory()

    @classmethod
    def setUpTestData(cls):
        cls.u1 = User.objects.create_superuser(username='******', password='******', email='*****@*****.**')

    def setUp(self):
Example #14
0
class Book(models.Model):
    bid = models.AutoField(primary_key=True)
    title = models.CharField(max_length=200)
    author = models.ForeignKey(Person, null=True, related_name='bibliography')
    categories = models.ManyToManyField(Genre, related_name='collection')
    loc_url = models.URLField("Library of Congress URL", blank=True)

    class Meta:
        app_label = 'adminbrowse'

    def __unicode__(self):
        return self.title


test_site = admin.AdminSite('test')
test_site.register(Person)
test_site.register(Genre)
test_site.register(Book)
test_site.register(User)
test_site.register(Group)
test_site.register(LogEntry)
# An atypical admin path for the test site.
urlpatterns = patterns('', (r'^foo/admin/bar/', include(test_site.urls)))


def setup_test_models(sender, **kwargs):
    import adminbrowse.models
    if sender is adminbrowse.models and not setup_test_models.done:
        setup_test_models.done = True
        for model in [Person, Genre, Book]:
Example #15
0
class AuthorAdmin(admin.ModelAdmin):
    ordering = ["id"]
    search_fields = ["id"]


class AuthorshipInline(admin.TabularInline):
    model = Authorship
    autocomplete_fields = ["author"]


class BookAdmin(admin.ModelAdmin):
    inlines = [AuthorshipInline]


site = admin.AdminSite(name="autocomplete_admin")
site.register(Question, QuestionAdmin)
site.register(Answer, AnswerAdmin)
site.register(Author, AuthorAdmin)
site.register(Book, BookAdmin)
site.register(Employee, search_fields=["name"])
site.register(WorkHour, autocomplete_fields=["employee"])
site.register(Manager, search_fields=["name"])
site.register(Bonus, autocomplete_fields=["recipient"])
site.register(PKChild, search_fields=["name"])
site.register(Toy, autocomplete_fields=["child"])


@contextmanager
def model_admin(model, model_admin, admin_site=site):
    org_admin = admin_site._registry.get(model)
Example #16
0
 def setUp(self):
     self.site = admin.AdminSite()
Example #17
0
 def setUp(self):
     self.site = admin.AdminSite()
     self.request = MockRequest()
     self.request.user = MockSuperUser()
Example #18
0
from django.contrib import admin

from .models import Event, Timestamp


class EventAdmin(admin.ModelAdmin):
    list_display = ("dt", )


class TimestampAdmin(admin.ModelAdmin):
    readonly_fields = ("created", "updated")


site = admin.AdminSite(name="admin_tz")
site.register(Event, EventAdmin)
site.register(Timestamp, TimestampAdmin)
Example #19
0
from django.contrib import admin
from .models import Faculty, Country, Region, Area, City, Special, Abiturient, Application
# Register your models here.
hrd_admin = admin.AdminSite('hrd_admin')
hrd_admin.register(Faculty)
hrd_admin.register(Country)
hrd_admin.register(Region)
hrd_admin.register(Area)
hrd_admin.register(City)
hrd_admin.register(Special)
hrd_admin.register(Abiturient)
hrd_admin.register(Application)
Example #20
0
from django.contrib import admin

from .models import Client

public_admin_site = admin.AdminSite(name="public-admin")


# @public_admin_site.register(Client)
class ClientModelAdmin(admin.ModelAdmin):
    list_display = ['name']


public_admin_site.register(Client, ClientModelAdmin)
Example #21
0
from django.contrib import admin
from django.contrib.auth import models as auth_models

site = admin.AdminSite()
site.register(auth_models.User, admin.ModelAdmin)
site.register(auth_models.Group, admin.ModelAdmin)
Example #22
0
from __future__ import unicode_literals
from django.test import TestCase
from django.test.client import RequestFactory
from django.contrib import admin
from django.contrib.admin.views.main import ChangeList
from django.contrib.auth.models import AnonymousUser

from django_countries import filters
from django_countries.tests import models

test_site = admin.AdminSite(name='test-admin')


class PersonAdmin(admin.ModelAdmin):
    list_filter = [
        ('country', filters.CountryFilter),
    ]


test_site.register(models.Person, PersonAdmin)


class TestCountryFilter(TestCase):
    def get_changelist_args(self, **kwargs):
        m = self.person_admin
        args = [
            kwargs.pop('list_display', m.list_display),
            kwargs.pop('list_display_links', m.list_display_links),
            kwargs.pop('list_filter', m.list_filter),
            kwargs.pop('date_hierarchy', m.date_hierarchy),
            kwargs.pop('search_fields', m.search_fields),
Example #23
0
        request.is_add_view = False
        return super().change_view(request, *args, **kwargs)

    def get_formsets_with_inlines(self, request, obj=None):
        if request.is_add_view and obj is not None:
            raise Exception(
                "'obj' passed to get_formsets_with_inlines wasn't None during add_view"
            )
        if not request.is_add_view and obj is None:
            raise Exception(
                "'obj' passed to get_formsets_with_inlines was None during change_view"
            )
        return super().get_formsets_with_inlines(request, obj)


site = admin.AdminSite(name="admin")
site.site_url = '/my-site-url/'
site.register(Article, ArticleAdmin)
site.register(CustomArticle, CustomArticleAdmin)
site.register(
    Section,
    save_as=True,
    inlines=[ArticleInline],
    readonly_fields=['name_property'],
    search_fields=['name'],
)
site.register(ModelWithStringPrimaryKey)
site.register(Color)
site.register(Thing, ThingAdmin)
site.register(Actor)
site.register(Inquisition, InquisitionAdmin)
Example #24
0
 def setUpExtra(self):
     self.setUpModels()
     self.site = admin.AdminSite(name="tagulous_admin")
     tag_admin.register(self.model, site=self.site)
     self.ma = self.site._registry[self.model]
     self.cl = None
Example #25
0
    }


class UnorderedObjectAdmin(admin.ModelAdmin):
    list_display = ['name']
    list_editable = ['name']
    list_per_page = 2


class UndeletableObjectAdmin(admin.ModelAdmin):
    def change_view(self, *args, **kwargs):
        kwargs['extra_context'] = {'show_delete': False}
        return super(UndeletableObjectAdmin, self).change_view(*args, **kwargs)


site = admin.AdminSite(name="admin")
site.register(Article, ArticleAdmin)
site.register(CustomArticle, CustomArticleAdmin)
site.register(Section, save_as=True, inlines=[ArticleInline])
site.register(ModelWithStringPrimaryKey)
site.register(Color)
site.register(Thing, ThingAdmin)
site.register(Actor)
site.register(Inquisition, InquisitionAdmin)
site.register(Sketch, SketchAdmin)
site.register(Person, PersonAdmin)
site.register(Persona, PersonaAdmin)
site.register(Subscriber, SubscriberAdmin)
site.register(ExternalSubscriber, ExternalSubscriberAdmin)
site.register(OldSubscriber, OldSubscriberAdmin)
site.register(Podcast, PodcastAdmin)
Example #26
0
 def setUpExtra(self):
     self.admin = test_admin.SimpleMixedTestAdmin
     self.model = test_models.SimpleMixedTest
     self.model_singletag = self.model.singletag.tag_model
     self.model_tags = self.model.tags.tag_model
     self.site = admin.AdminSite(name="tagulous_admin")
Example #27
0
from django.test import TestCase, override_settings
from django.urls import path, reverse

from .models import Book


class Router:
    target_db = None

    def db_for_read(self, model, **hints):
        return self.target_db

    db_for_write = db_for_read


site = admin.AdminSite(name='test_adminsite')
site.register(Book)

urlpatterns = [
    path('admin/', site.urls),
]


@override_settings(ROOT_URLCONF=__name__,
                   DATABASE_ROUTERS=['%s.Router' % __name__])
class MultiDatabaseTests(TestCase):
    databases = {'default', 'other'}

    @classmethod
    def setUpTestData(cls):
        cls.superusers = {}
Example #28
0
# coding: utf-8

# DJANGO IMPORTS
from django.contrib import admin

# PROJECT IMPORTS
from grappelli.tests.models import Category, Entry

site = admin.AdminSite(name="Admin Site")


class CategoryOptions(admin.ModelAdmin):
    list_display = (
        "id",
        "name",
    )
    list_display_links = ("name", )


class EntryOptions(admin.ModelAdmin):
    list_display = (
        "id",
        "title",
        "category",
        "user",
    )
    list_display_links = ("title", )

    def get_queryset(self, request):
        qs = super(EntryOptions, self).get_queryset(request)
        if request.user.is_superuser:
Example #29
0
class AuthorAdmin(admin.ModelAdmin):
    ordering = ['id']
    search_fields = ['id']


class AuthorshipInline(admin.TabularInline):
    model = Authorship
    autocomplete_fields = ['author']


class BookAdmin(admin.ModelAdmin):
    inlines = [AuthorshipInline]


site = admin.AdminSite(name='autocomplete_admin')
site.register(Question, QuestionAdmin)
site.register(Answer, AnswerAdmin)
site.register(Author, AuthorAdmin)
site.register(Book, BookAdmin)


class AutocompleteJsonViewTests(AdminViewBasicTestCase):
    as_view_args = {'model_admin': QuestionAdmin(Question, site)}
    factory = RequestFactory()
    url = reverse_lazy('autocomplete_admin:admin_views_question_autocomplete')

    @classmethod
    def setUpTestData(cls):
        cls.user = User.objects.create_user(
            username='******',
Example #30
0
 def setUp(self):
     self.model = Poll
     self.site = admin.AdminSite()
     self.admin_class = type('TestAdmin', (admin.ModelAdmin, ), {})