コード例 #1
0
def gerador_crop_admin(classe_alvo):
    if hasattr(classe_alvo, "__crop__"):
        crop = getattr(classe_alvo, "__crop__")
        classe_admin = site._registry[classe_alvo].__class__
        from utilidades.imagem import cropar_imagem_view
        print classe_admin
        print "-------------------"
        class CropAdmin(classe_admin):
            def response_add(self, request, obj, post_url_continue = "../%s/") :
                redirect = super(CropAdmin, self).response_add(request, obj)
                obj.criar_miniaturas()
                request.session['obj_crop'] = obj
                redirect = redirect.__getitem__("Location")
                return cropar_imagem_view(request, obj.imagem.name, redirect, crop["largura"], crop["altura"], crop["proporcao"], POST_DATA = True, manter_original = crop["manter_original"])#

            def response_change(self, request, obj):
                redirect = super(CropAdmin, self).response_change(request, obj)
                if request.FILES.has_key('imagem'):
                    redirect = redirect.__getitem__("Location")
                    request.session['obj_crop'] = obj
                    return cropar_imagem_view(request, obj.imagem.name, redirect, crop["largura"], crop["altura"], crop["proporcao"], POST_DATA = True, manter_original = crop["manter_original"])
                else:
                    return redirect
        site.unregister(classe_alvo)
        site.register(classe_alvo, CropAdmin)
コード例 #2
0
 def decorator(cls):
     """
     The actual decorator that does the work.
     """
     site.unregister(model_class)
     site.register(model_class, cls)
     return cls
コード例 #3
0
 def decorator(cls):
     """
     The actual decorator that does the work.
     """
     site.unregister(model_class)
     site.register(model_class, cls)
     return cls
    def tearDown(self):
        for app_models_module in self.app_models_modules:
            for model_name in app_models_module.__all__:
                site.unregister(getattr(app_models_module, model_name))

        self.reset_urlresolvers_caches()

        super(WithReadmeConfigurationTests, self).tearDown()
コード例 #5
0
def flatpages():
    """Hack the sites field widget.
    """
    fpafm = FlatpageForm.Meta
    if getattr(fpafm, 'widgets', None) is None:
        fpafm.widgets = {}
    fpafm.widgets['sites'] = PreSelectDefaultSiteOnCreateSelectMultiple

    site.unregister(FlatPage)
    FlatPageAdmin.Media = Flatpagemedia
    site.register(FlatPage, FlatPageAdmin)
コード例 #6
0
ファイル: admin.py プロジェクト: MAPC/masshealth
def flatpages():
    """Hack the sites field widget.
    """
    fpafm = FlatpageForm.Meta
    if getattr(fpafm, 'widgets', None) is None:
        fpafm.widgets = {}
    fpafm.widgets['sites'] = PreSelectDefaultSiteOnCreateSelectMultiple

    site.unregister(FlatPage)
    FlatPageAdmin.Media = Flatpagemedia
    site.register(FlatPage, FlatPageAdmin)
コード例 #7
0
def audit_install():
    # import here to avoid triggering django imports during package import
    from django.contrib.admin import site
    from .models import AdminAuditMixin, AuditLog

    for model, model_admin in site._registry.items():
        if (model is AuditLog or isinstance(model_admin, AdminAuditMixin)):
            # Do not mingle with our own model
            continue
        site.unregister(model)
        new_model_admin = type('new_model_admin',
                               (AdminAuditMixin, model_admin.__class__),
                               model_admin.__dict__)
        site.register(model, new_model_admin)
コード例 #8
0
def install_site_permission_admin():
    if Group in site._registry:
        old_class = site._registry[Group].__class__
        site.unregister(Group)
    else:
        old_class = ModelAdmin
        
    class SiteGroupInline(StackedInline):
        model = SiteGroup
        max_num = 1
        
    class GroupExtendedAdmin(old_class):
        inlines = old_class.inlines + [SiteGroupInline]
        
    site.register(Group, GroupExtendedAdmin)
コード例 #9
0
ファイル: admin.py プロジェクト: Osmose/firefox-flicks
from django.contrib.admin import site
from django.contrib.auth import admin
from django.contrib.auth.models import User


class UserAdmin(admin.UserAdmin):
    """Configuration for the user admin pages."""
    list_display = ['email', 'full_name', 'country', 'is_staff']
    search_fields = ['email', 'userprofile__full_name', 'userprofile__nickname']

    def full_name(self, user):
        return user.profile.full_name

    def country(self, user):
        return user.profile.country
site.unregister(User)
site.register(User, UserAdmin)
コード例 #10
0
                (_('Personal info'), {'fields': ('first_name', 'last_name', 'email')}), ]

    def response_change(self, request, obj):
        if request.user.is_active and request.user.is_superuser:
            return super(UserAdmin, self).response_change(request, obj)

        # Redirect user that is not superuser to index page
        return redirect('/api/admin/')

    def get_inline_instances(self, request, obj=None):
        if not obj:
            return list()
        return super(UserAdmin, self).get_inline_instances(request, obj)


site.unregister(BaseGroup)
site.register(Group, GroupAdmin)
site.register(User, UserAdmin)


class MenuItemsParentFilter(SimpleListFilter):
    title = 'parent'
    parameter_name = 'parent'

    def lookups(self, request, model_admin):
        queryset: QuerySet[MenuItem] = model_admin.get_queryset(request)
        return [(item.id, item.name) for item in queryset if not item.parent]

    def get_children_filter(self):
        filters = Q(pk=0)
        for item in MenuItem.objects.filter(parent__id=self.value()):
コード例 #11
0
ファイル: admin.py プロジェクト: 55minutes/django-lib
def register(model_or_iterable, admin_class=None, **options):
    try:
        site.unregister(model_or_iterable)
    except NotRegistered:
        pass
    site.register(model_or_iterable, admin_class, **options)
コード例 #12
0
ファイル: admin.py プロジェクト: hernan0216/utopia-cms
        if db_field.name == "articles":
            kwargs["queryset"] = Article.objects.filter(is_published=True)
        return super(BreakingNewsModuleAdmin, self).formfield_for_manytomany(
            db_field, request, **kwargs)


class TagAdmin(admin.ModelAdmin):
    model = Tag
    search_fields = ('name',)


class TaggedItemAdmin(admin.ModelAdmin):
    model = TaggedItem
    search_fields = ('name',)

site.register(Article, ArticleAdmin)
site.register(Edition, EditionAdmin)
site.register(Journalist, JournalistAdmin)
site.register(Location, LocationAdmin)
site.register(PrintOnlyArticle, PrintOnlyArticleAdmin)
site.register(Section, SectionAdmin)
site.register(Supplement, SupplementAdmin)
site.register(Publication, PublicationAdmin)
site.register(Category, CategoryAdmin)
site.register(BreakingNewsModule, BreakingNewsModuleAdmin)
site.unregister(Tag)
site.unregister(TaggedItem)
site.register(Tag, TagAdmin)
site.register(TaggedItem, TaggedItemAdmin)

コード例 #13
0
from django import forms
from django.contrib import admin
from django.contrib.admin import site as admin_site
from django.contrib.auth.admin import UserAdmin as UA
from django.contrib.auth.models import User

from .models import Token, UserPreferences

admin_site.unregister(User)


class TokenAdminForm(forms.ModelForm):
    key = forms.CharField(
        required=False,
        help_text="If no key is provided, one will be generated automatically.",
    )

    class Meta:
        fields = ["user", "key", "write_enabled", "expires", "description"]
        model = Token


@admin.register(Token, site=admin_site)
class TokenAdmin(admin.ModelAdmin):
    form = TokenAdminForm
    list_display = [
        "key", "user", "created", "expires", "write_enabled", "description"
    ]


class UserPreferencesInline(admin.TabularInline):
コード例 #14
0
ファイル: admin.py プロジェクト: normanjaeckel/UH-praxis
from django.contrib.admin import site
from django.contrib.auth.models import Group

from .models import Section


site.register(Section)
site.unregister(Group)
コード例 #15
0
ファイル: admin.py プロジェクト: 5l1v3r1/tellecast

@property
def ewkt(self):
    if self.get_srid():
        return u'SRID={srid};POINT ({coords_0:.14f}, {coords_1:.14f})'.format(
            srid=self.srid,
            coords_0=self.coords[0],
            coords_1=self.coords[1],
        )
    return 'N/A'


GEOSGeometry.ewkt = ewkt

site.unregister(Administrator)
site.unregister(UserSocialAuth)

delattr(AdministratorAdmin, 'form')

AdministratorAdmin.actions = [delete_selected]
AdministratorAdmin.delete_view = delete_view
AdministratorAdmin.fieldsets = ()
AdministratorAdmin.fields = (
    'username',
    'email',
    'first_name',
    'last_name',
    'is_active',
    'is_staff',
    'is_superuser',
コード例 #16
0
ファイル: groups.py プロジェクト: x10-utils/polyaxon
def register(admin_register):
    site.unregister(Group)
コード例 #17
0
ファイル: admin.py プロジェクト: pombredanne/Updoc
from django.contrib.admin import site, ModelAdmin, TabularInline
from django.contrib.auth.models import Group


class UserAdmin(ModelAdmin):
    fields = ('username', 'first_name', 'last_name', 'email',
              ('is_staff', 'is_superuser'))


class ItemInline(TabularInline):
    model = RssItem


class RssAdmin(ModelAdmin):
    inlines = [ItemInline, ]


site.unregister(get_user_model())
site.unregister(Group)
site.unregister(Site)
site.unregister(SocialToken)
site.unregister(SocialAccount)
site.unregister(SocialApp)
site.unregister(EmailAddress)
site.unregister(EmailConfirmation)
site.register(get_user_model(), UserAdmin)
site.register(RssRoot, RssAdmin)
site.register(RewrittenUrl)
site.register(ProxyfiedHost)
コード例 #18
0
from django.conf import settings
from django.contrib.admin import site as admin_site
from taggit.models import Tag


# Override default AdminSite attributes so we can avoid creating and
# registering our own class
admin_site.site_header = 'NetBox Administration'
admin_site.site_title = 'NetBox'
admin_site.site_url = '/{}'.format(settings.BASE_PATH)

# Unregister the unused stock Tag model provided by django-taggit
admin_site.unregister(Tag)
コード例 #19
0
ファイル: __init__.py プロジェクト: matrixalex/DemoDjango
from django.contrib.admin import site
from django.contrib.auth.models import Group
from ..models import User
from .models import UserAdmin


site.register(User, UserAdmin)
site.unregister(Group)
コード例 #20
0
from django.contrib.admin import site
from django.contrib.auth.models import User, Group

# No one can edit Group or User in admin.
site.unregister(Group)
site.unregister(User)
コード例 #21
0
from django.contrib.auth.models import Group
from django.contrib.sites.models import Site
from django.core.urlresolvers import reverse_lazy
from django.views.generic.base import RedirectView
from rest_framework.authtoken.models import Token
from rest_framework.renderers import JSONRenderer
from rest_framework_swagger import urls
from social.apps.django_app.default.models import Association, Nonce

from api import views

JSONRenderer.charset = 'utf-8'

autodiscover()

site.unregister(Association)
site.unregister(Group)
site.unregister(Nonce)
site.unregister(Site)
site.unregister(Token)

urlpatterns = patterns(
    '',
    url(r'^$',
        RedirectView.as_view(permanent=True, url=reverse_lazy('admin:index'))),
    url(r'^admin/api/user/(?P<platform>[^\d/]+)/$',
        views.users,
        name='views.users'),
    url(r'^admin/', include(site.urls)),
    url(r'^api/ads/$', views.ads),
    url(r'^api/authenticate/email/$', views.authenticate_1),
コード例 #22
0
ファイル: admin.py プロジェクト: tarasov/deproc
from deproc.tariffication import models

__author__ = 'tarasov'

class AdminUser(ModelAdmin):
    fields = ('username', 'first_name', 'last_name', 'other_name', 'email', 'password', 'phone', 'b_day', 'sex', 'groups',)

class AdminUserStatus(ModelAdmin):
    pass

class AdminPost(ModelAdmin):
    list_display = ('user', 'get_user_status')

#site.unregister(User)
#site.unregister(Group)
site.unregister(Site)

site.register(models.Profile, AdminUser)
site.register(models.Students)
site.register(models.Teachers)
site.register(models.Group)
site.register(models.UserStatus)
site.register(models.UserPost, AdminPost)
site.register(models.PO)
site.register(models.Speciality)
site.register(models.UchPlan)
site.register(models.UchPlanHour)
site.register(models.Discipline)
site.register(models.Disc_type)
site.register(models.Groups)
site.register(models.Groups_stud)
コード例 #23
0
ファイル: admin.py プロジェクト: teschmitt/mukluk
    Products are created.
    """

    inlines = (DesignAssetAdmin, DesignedProductAdmin)
    form = DesignAdminForm
    fieldsets = design_fieldsets

    def save_model(self, request, obj, form, change):
        """
        Store the design ID for creating designed_products
        in save_formset.
        """
        super(DesignAdmin, self).save_model(request, obj, form, change)
        self._design_id = obj.id

    def save_formset(self, request, form, formset, change):
        design = self.model.objects.get(id=self._design_id)
        super(DesignAdmin, self).save_formset(request, form, formset, change)

        if formset.model == DesignedProduct:
            bases = request.POST.getlist('base')
            design.designed_products.create_from_bases(
                design=design, bases=bases)


site.unregister(Product)
site.register(Product, MuklukProductAdmin)
site.register(VendorShop, VendorShopAdmin)
site.register(Brand)
site.register(Design, DesignAdmin)
コード例 #24
0
ファイル: admin.py プロジェクト: ruslanosipov/rblog
"""Unregister Group and Site apps."""

from django.contrib.admin import site
from django.contrib.auth import models as auth_models
from django.contrib.sites import models as sites_models

site.unregister(auth_models.Group)
site.unregister(sites_models.Site)
コード例 #25
0
    SolarSchedule,
)
from social_django.models import Association, Nonce, UserSocialAuth
from taggit.models import Tag

from nautobot.utilities.forms import BootstrapMixin
import nautobot.utilities.forms.widgets as widgets


# Override default AdminSite attributes so we can avoid creating and
# registering our own class
admin_site.site_header = "Nautobot Administration"
admin_site.site_title = "Nautobot"

# Unregister the unused stock Tag model provided by django-taggit
admin_site.unregister(Tag)

# Remove Celery Beat from admin menu
admin_site.unregister(ClockedSchedule)
admin_site.unregister(CrontabSchedule)
admin_site.unregister(IntervalSchedule)
admin_site.unregister(PeriodicTask)
admin_site.unregister(SolarSchedule)

# Unregister SocialAuth from Django admin menu
admin_site.unregister(Association)
admin_site.unregister(Nonce)
admin_site.unregister(UserSocialAuth)


# Customize Constance admin
コード例 #26
0
ファイル: admin.py プロジェクト: danielbraga/hcap
from allauth.account.models import EmailAddress
from allauth.socialaccount.models import SocialApp, SocialToken, SocialAccount
from django.contrib.admin import AdminSite, site
from django.contrib.auth.models import Group
from django.contrib.sites.models import Site
from material.frontend.models import Module as MaterialFrontendModule

AdminSite.index_title = "Painel Administrativo"
AdminSite.site_header = "Capacidade Hospitalar - Administração"
AdminSite.site_title = "Capacidade Hospitalar"

site.unregister(EmailAddress)
site.unregister(SocialAccount)
site.unregister(SocialApp)
site.unregister(SocialToken)
site.unregister(Group)
site.unregister(Site)
site.unregister(MaterialFrontendModule)
コード例 #27
0
from django.contrib.admin import site
from django.contrib.auth.models import User
from django.contrib.auth.admin import UserAdmin

from real_estate_app.admin.options import FaceBoxModelAdmin


class UserAdminRealEstateApp(UserAdmin, FaceBoxModelAdmin):
    def has_change_permission(self, request, obj=None):
        """
			User can edit your own profile.
		"""
        if isinstance(obj, User) and obj.id == request.user.id:
            return True

        opts = self.opts
        return request.user.has_perm(opts.app_label + '.' +
                                     opts.get_change_permission())


site.unregister(User)
site.register(User, UserAdminRealEstateApp)
コード例 #28
0
            {
                'data': data,
                'size': "50x50"
            })
        big = "http://api.qrserver.com/v1/create-qr-code/?%s" % urllib.urlencode(
            {
                'data': data,
                'size': "1000x1000"
            })
        return "<a href='%s'><img src='%s' width='50' height='50' /></a>" % (
            big, small)

    qr_code.allow_tags = True


site.register(PointOfInterest, PointOfInterestAdmin)


class SliderPictureAdmin(OrderedModelAdmin):
    list_display = (
        'area',
        'image',
        'move_up_down_links',
    )
    list_display_links = ('image', )
    list_filter = ('area', )


site.register(SliderPicture, SliderPictureAdmin)
site.unregister(Site)