Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
django-selectable used as autocomplete for collections in admin
Artur Smęt52cdc974e67b
diff --git a/saleor/product/admin.py b/saleor/product/admin.pyindex 72d356d9dd..8c645d3397 100644--- a/saleor/product/admin.py+++ b/saleor/product/admin.py@@ -3,6 +3,7 @@ from mptt.admin import MPTTModelAdminfrom .models import (ProductImage, BagVariant, Bag, ShirtVariant, Shirt,Category, FixedProductDiscount, Color)+from .forms import ShirtAdminFormclass ImageAdminInline(admin.StackedInline):@@ -22,6 +23,9 @@ class ShirtVariant(admin.StackedInline):class ShirtAdmin(admin.ModelAdmin):+ form = ShirtAdminForm+ list_display = ['name', 'collection', 'admin_get_price_min',+ 'admin_get_price_max']inlines = [ShirtVariant, ImageAdminInline]diff --git a/saleor/product/forms.py b/saleor/product/forms.pyindex fc42e0a985..a8da3b13f4 100644--- a/saleor/product/forms.py+++ b/saleor/product/forms.py@@ -1,7 +1,9 @@from django import forms+from selectable.forms import AutoCompleteWidgetfrom ..cart.forms import AddToCartFormfrom .models import Bag, Shirt, ShirtVariant+from .lookups import CollectionLookupclass BagForm(AddToCartForm):@@ -29,9 +31,17 @@ class ShirtForm(AddToCartForm):product__color=self.product.color)+class ShirtAdminForm(forms.ModelForm):+ class Meta:+ model = Shirt+ widgets = {+ 'collection': AutoCompleteWidget(CollectionLookup)+ }++def get_form_class_for_product(product):if isinstance(product, Shirt):return ShirtFormif isinstance(product, Bag):return BagForm- raise NotImplementedError\ No newline at end of file+ raise NotImplementedErrordiff --git a/saleor/product/lookups.py b/saleor/product/lookups.pynew file mode 100644index 0000000000..44441d9640--- /dev/null+++ b/saleor/product/lookups.py@@ -0,0 +1,32 @@+from __future__ import unicode_literals++from selectable.base import LookupBase+from selectable.registry import registry+from django.db.models import Count++from .models import Product+++class CollectionLookup(LookupBase):++ def get_query(self, request, term):+ products = Product.objects.filter(collection__isnull=False,+ collection__istartswith=term)++ qs = products.values('collection').annotate(+ products=Count('collection')+ ).order_by('-products')++ return qs++ def get_item_value(self, item):+ return item['collection']++ def get_item_label(self, item):+ collections = "{collection} ({products} products)".format(+ **item+ )+ return collections+++registry.register(CollectionLookup)\ No newline at end of filediff --git a/saleor/settings.py b/saleor/settings.pyindex 548d86dca6..418c4abc51 100644--- a/saleor/settings.py+++ b/saleor/settings.py@@ -105,7 +105,8 @@ INSTALLED_APPS = ['django_prices','mptt','payments',- 'south'+ 'south',+ 'selectable']LOGGING = {diff --git a/saleor/urls.py b/saleor/urls.pyindex 9f55860d4b..2d6655d0cc 100644--- a/saleor/urls.py+++ b/saleor/urls.py@@ -25,6 +25,7 @@ urlpatterns = patterns(url(r'^order/', include(order_urls, namespace='order')),url(r'^products/', include(product_urls, namespace='product')),url(r'^profile/', include(userprofile_urls, namespace='profile')),+ url(r'^selectable/', include('selectable.urls')),url(r'', include('payments.urls')))diff --git a/setup.py b/setup.pyindex 41938a769e..a8539432fd 100755--- a/setup.py+++ b/setup.py@@ -42,7 +42,9 @@ setup('satchless>=1.1.1,<1.2a0','South>=0.7.6','requests>=1.2.0',- 'unidecode'],+ 'unidecode',+ 'django-selectable==0.8.0'+ ],entry_points={'console_scripts': ['saleor = saleor:manage']},tests_require=[diff --git a/templates/admin/base_site.html b/templates/admin/base_site.htmlnew file mode 100644index 0000000000..eceeaf418d--- /dev/null+++ b/templates/admin/base_site.html@@ -0,0 +1,15 @@+{% extends "admin/base.html" %}++{% block title %}{{ title }} | Saleor{% endblock %}++{% block branding %}+<h1 id="site-name"><a href="{% url 'admin:index' %}">Saleor Admin</a></h1>+{% endblock %}++{% block nav-global %}{% endblock %}++{% block extrahead %}+ {% load selectable_tags %}+ {% include_ui_theme %}+ {% include_jquery_libs %}+{% endblock %}\ No newline at end of filediff --git a/utils/create_random_data.py b/utils/create_random_data.pyindex 88d85a46ce..c092fc8bc1 100644--- a/utils/create_random_data.py+++ b/utils/create_random_data.py@@ -12,7 +12,7 @@ from saleor.product.models import Category, Colorfake = Factory.create()-PRODUCT_COLLECTIONS = fake.words(2)+PRODUCT_COLLECTIONS = fake.words(10)def create_color(**kwargs):@@ -112,6 +112,10 @@ def create_items(placeholder_dir, how_many=10):create_product_image(bag, placeholder_dir)# chance to generate couple of sizesfor size in ShirtVariant.SIZE_CHOICES:+ # Create min. one size+ if shirt.variants.count() == 0:+ create_variant(shirt, size=size[0])+ continueif random.choice([True, False]):create_variant(shirt, size=size[0])