Commits

Maciej Wiśniowski committed c36c30f

added automatic selection of manufacturer field type

Comments (0)

Files changed (2)

lfs/manage/views/product/product.py

 from django.utils.translation import ugettext_lazy as _
 from django.views.decorators.http import require_POST
 from django.forms.widgets import HiddenInput
+from django.conf import settings
 
 # lfs imports
 import lfs.core.utils
 from lfs.catalog.models import Category
 from lfs.catalog.models import Product
 from lfs.catalog.settings import VARIANT, PRODUCT_TYPE_FORM_CHOICES, PRODUCT_TEMPLATES
+from lfs.manufacturer.models import Manufacturer
 from lfs.core.utils import LazyEncoder
 from lfs.manage.views.product.images import manage_images
 from lfs.manage.views.product.seo import manage_seo
     def __init__(self, *args, **kwargs):
         super(ProductDataForm, self).__init__(*args, **kwargs)
         self.fields["template"].widget = SelectImage(choices=PRODUCT_TEMPLATES)
-        self.fields["manufacturer"].widget = HiddenInput()
+        man_count = Manufacturer.objects.count()
+        if man_count > getattr(settings, 'LFS_SELECT_LIMIT', 20):
+            # use autocomplete if there is more manufacturers
+            # than LFS_SELECT_LIMIT
+            self.fields["manufacturer"].widget = HiddenInput()
 
     class Meta:
         model = Product

lfs/templates/manage/product/data.html

                         {% endif %}
                     </div>                                        
                 {% endif %}
-            </div>
-
-            <div class="field">
-                <div class="label">
-                    {{ form.manufacturer.label_tag }}:
-                </div>
-
-                {% if form.manufacturer.errors %}
-                    <div class="error">
-                        {{ form.manufacturer }}
-                        {{ form.manufacturer.errors }}
-                    </div>
-                {% else %}
-                    <div>
-                        {% if product.is_variant %}
-                            {{ product.get_manufacturer|default_if_none:"-" }}
-                        {% else %}
-                            {{ form.manufacturer }}
-                            <input type="text" id="id_manufacturer_autocomplete" value="{{ form.instance.manufacturer.name }}" />
-                        {% endif %}
-                    </div>
-                {% endif %}
-            </div>
+            </div>            
         </fieldset>
 
         <fieldset>
                     </div>
                 {% endif %}
             </div>
+
+            <div class="field">
+                <div class="label">
+                    {{ form.manufacturer.label_tag }}:
+                </div>
+
+                {% if form.manufacturer.errors %}
+                    <div class="error">
+                        {{ form.manufacturer }}
+                        {{ form.manufacturer.errors }}
+                    </div>
+                {% else %}
+                    <div>
+                        {% if product.is_variant %}
+                            {{ product.get_manufacturer|default_if_none:"-" }}
+                        {% else %}
+                            {{ form.manufacturer }}
+                            {% if form.manufacturer.is_hidden %}
+                                <input type="text" id="id_manufacturer_autocomplete" value="{{ form.instance.manufacturer.name }}" />
+                            {% endif %}
+                        {% endif %}
+                    </div>
+                {% endif %}
+            </div>
+
             <div class="field">
                 <div class="label">
                     {{ form.sku_manufacturer.label_tag }}: