Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Remove django admin

Krzysztof Wolski05be3b0bccf2
diff --git a/saleor/order/admin.py b/saleor/order/admin.py
deleted file mode 100644
index 3ba17484bb..0000000000
--- a/saleor/order/admin.py
+++ /dev/null
@@ -1,105 +0,0 @@
-from django.contrib import admin
-from django.contrib.admin.options import ModelAdmin
-from django.forms.models import BaseInlineFormSet
-from django.template.loader import render_to_string
-from django.utils.safestring import mark_safe
-
-from .models import Order, OrderedItem, Payment
-
-
-def format_address(address):
- address = render_to_string('userprofile/snippets/address-details.html',
- {'address': address})
- # avoid django's linebreaks breaking the result
- return address.replace('\n', '')
-
-
-class OrderModelAdmin(ModelAdmin):
-
- def get_inline_instances(self, request, order=None):
- inlines = super(OrderModelAdmin, self).get_inline_instances(request,
- order)
- if order:
- inlines.extend([
- DeliveryInlineAdmin(self.model, self.admin_site, group)
- for group in order])
- return inlines
-
-
-class PaymentInlineAdmin(admin.TabularInline):
-
- model = Payment
- extra = 0
- readonly_fields = ['variant', 'status', 'transaction_id', 'currency',
- 'total', 'delivery', 'description', 'tax',
- 'billing_first_name', 'billing_last_name',
- 'billing_address_1', 'billing_address_2',
- 'billing_city', 'billing_country_code',
- 'billing_country_area', 'billing_postcode']
- exclude = ['token', 'extra_data']
- can_delete = False
-
-
-class DeliveryFormSet(BaseInlineFormSet):
-
- def __init__(self, *args, **kwargs):
- kwargs['instance'] = self.instance_obj
- super(DeliveryFormSet, self).__init__(*args, **kwargs)
-
-
-class DeliveryInlineAdmin(admin.TabularInline):
-
- model = OrderedItem
- formset = DeliveryFormSet
-
- def __init__(self, parent_model, admin_site, delivery):
- self.delivery = delivery
- delivery_class = delivery.__class__
- if hasattr(delivery, 'address'):
- address = format_address(delivery.address)
- self.verbose_name_plural = (
- mark_safe(
- '%s: %s %s<br>%s' % (
- delivery,
- delivery.price.gross,
- delivery.price.currency,
- address)))
- if hasattr(delivery, 'email'):
- self.verbose_name_plural = (
- mark_safe(
- '%s: %s %s<br>%s' % (
- delivery,
- delivery.price.gross,
- delivery.price.currency,
- delivery.email)))
- super(DeliveryInlineAdmin, self).__init__(delivery_class, admin_site)
-
- def get_formset(self, request, obj=None, **kwargs):
- obj = obj if not self.delivery else self.delivery
- formset = super(DeliveryInlineAdmin, self).get_formset(request, obj,
- **kwargs)
- formset.instance_obj = obj
- return formset
-
-
-class OrderAdmin(OrderModelAdmin):
-
- inlines = [PaymentInlineAdmin]
- exclude = ['token']
- readonly_fields = ['customer', 'total']
- list_display = ['__str__', 'status', 'created', 'user']
-
- def customer(self, obj):
- return format_address(obj.billing_address)
- customer.allow_tags = True
-
- def total(self, obj):
- total = obj.get_total()
- return '%s %s' % (total.gross, total.currency)
- total.short_description = 'Total'
-
- def has_add_permission(self, request, obj=None):
- return False
-
-
-admin.site.register(Order, OrderAdmin)
diff --git a/saleor/product/admin.py b/saleor/product/admin.py
deleted file mode 100644
index a28082e77e..0000000000
--- a/saleor/product/admin.py
+++ /dev/null
@@ -1,19 +0,0 @@
-from django.contrib import admin
-from mptt.admin import MPTTModelAdmin
-
-from ..discount.models import Sale
-from .models import (ProductImage, Category)
-from .forms import ImageInline
-
-
-class ImageAdminInline(admin.StackedInline):
- model = ProductImage
- formset = ImageInline
-
-
-class ProductCollectionAdmin(admin.ModelAdmin):
- search_fields = ['name']
-
-
-admin.site.register(Category, MPTTModelAdmin)
-admin.site.register(Sale)
diff --git a/saleor/settings.py b/saleor/settings.py
index a317136883..463f936806 100644
--- a/saleor/settings.py
+++ b/saleor/settings.py
@@ -141,7 +141,6 @@ INSTALLED_APPS = [
'django.contrib.sitemaps',
'django.contrib.sites',
'django.contrib.staticfiles',
- 'django.contrib.admin',
'django.contrib.auth',
'django.contrib.postgres',
diff --git a/saleor/urls.py b/saleor/urls.py
index 984feb0db1..f913be4f27 100644
--- a/saleor/urls.py
+++ b/saleor/urls.py
@@ -1,7 +1,6 @@
from django.conf import settings
from django.conf.urls import url, include
from django.conf.urls.static import static
-from django.contrib import admin
from django.contrib.sitemaps.views import sitemap
from django.contrib.staticfiles.views import serve
from django.views.i18n import javascript_catalog
@@ -21,13 +20,10 @@ from .data_feeds.urls import urlpatterns as feed_urls
from .dashboard.urls import urlpatterns as dashboard_urls
-admin.autodiscover()
-
urlpatterns = [
url(r'^', include(core_urls)),
url(r'^account/', include('allauth.urls')),
url(r'^account/login', login_view, name="account_login"),
- url(r'^admin/', include(admin.site.urls)),
url(r'^cart/', include(cart_urls, namespace='cart')),
url(r'^checkout/', include(checkout_urls, namespace='checkout')),
url(r'^dashboard/', include(dashboard_urls, namespace='dashboard')),
diff --git a/saleor/userprofile/admin.py b/saleor/userprofile/admin.py
deleted file mode 100644
index c444238b99..0000000000
--- a/saleor/userprofile/admin.py
+++ /dev/null
@@ -1,5 +0,0 @@
-from django.contrib import admin
-
-from .models import User
-
-admin.site.register(User)