Permalink
Browse files

Merged 0.6 branch.

  • Loading branch information...
2 parents 4d36503 + 3228d0e commit b018d5b29805925390d9a631aa8778c4b760c507 @diefenbach diefenbach committed Mar 7, 2012
@@ -1313,6 +1313,14 @@ def get_sku(self):
else:
return self.sku
+ def get_manufacturer(self):
+ """Always return parent manufacturer for variants.
+ """
+ if self.is_variant():
+ return self.parent.manufacturer
+ else:
+ return self.manufacturer
+
def has_related_products(self):
"""Returns True if the product has related products.
"""
View
@@ -28,6 +28,7 @@
url(r'^edit-product-manufacturer/(?P<manufacturer_id>\d*)/(?P<product_id>\d*)$', "edit_product", name="lfs_manufacturer_edit_product"),
url(r'^category-state-manufacturer/(?P<manufacturer_id>\d*)/(?P<category_id>\d*)$', "category_state", name="lfs_manufacturer_category_state"),
url(r'^manufacturer-inline/(?P<manufacturer_id>\d*)/(?P<category_id>\d*)$', "manufacturer_inline", name="lfs_manufacturer_inline"),
+ url(r'^manufacturers-ajax/$', "manufacturers_ajax", name="lfs_manufacturers_ajax"),
)
# Marketing
@@ -11,6 +11,7 @@
from django.utils import simplejson
from django.utils.translation import ugettext_lazy as _
from django.views.decorators.http import require_POST
+from django.views.decorators.cache import never_cache
# lfs imports
import lfs.core.utils
@@ -20,7 +21,6 @@
from lfs.catalog.models import Product
from lfs.core.utils import LazyEncoder
from lfs.manufacturer.models import Manufacturer
-from lfs.manufacturer.models import Manufacturer
class ManufacturerDataForm(ModelForm):
@@ -279,3 +279,20 @@ def _get_category_state(manufacturer, category):
klass = ""
return (checked, klass)
+
+
+@never_cache
+@permission_required("core.manage_shop", login_url="/login/")
+def manufacturers_ajax(request):
+ """ Returns list of manufacturers for autocomplete
+ """
+ term = request.GET.get('term', '')
+ manufacturers = Manufacturer.objects.filter(name__istartswith=term)[:10]
+
+ out = []
+ for man in manufacturers:
+ out.append({'label': man.name,
+ 'value': man.pk})
+
+ result = simplejson.dumps(out, cls=LazyEncoder)
+ return HttpResponse(result)
@@ -16,6 +16,8 @@
from django.utils import simplejson
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
@@ -34,6 +36,7 @@
from lfs.manage.views.product.attachments import manage_attachments
from lfs.manage.views.lfs_portlets import portlets_inline
from lfs.manage.utils import get_current_page
+from lfs.manufacturer.models import Manufacturer
from lfs.utils.widgets import SelectImage
@@ -68,10 +71,13 @@ def __init__(self, *args, **kwargs):
super(ProductDataForm, self).__init__(*args, **kwargs)
self.fields["template"].widget = SelectImage(choices=PRODUCT_TEMPLATES)
self.fields["active_base_price"].widget = CheckboxInput()
+ man_count = Manufacturer.objects.count()
+ if man_count > getattr(settings, 'LFS_SELECT_LIMIT', 20):
+ self.fields["manufacturer"].widget = HiddenInput()
class Meta:
model = Product
- fields = ("active", "name", "slug", "sku", "sku_manufacturer", "price", "tax", "price_calculator",
+ fields = ("active", "name", "slug", "manufacturer", "sku", "sku_manufacturer", "price", "tax", "price_calculator",
"short_description", "description", "for_sale", "for_sale_price", "static_block", "template",
"active_price_calculation", "price_calculation", "price_unit", "unit", "type_of_quantity_field",
"active_base_price", "base_price_unit", "base_price_amount")
@@ -98,7 +104,7 @@ class VariantDataForm(forms.ModelForm):
"""
class Meta:
model = Product
- fields = ("active", "active_name", "name", "slug", "active_sku", "sku", "sku_manufacturer",
+ fields = ("active", "active_name", "name", "slug", "manufacturer", "active_sku", "sku", "sku_manufacturer",
"active_price", "price", "price_calculator", "active_short_description", "short_description", "active_description",
"description", "for_sale", "for_sale_price", "active_for_sale", "active_for_sale_price",
"active_related_products", "active_static_block", "static_block", "template",
@@ -157,13 +163,11 @@ def manage_product(request, product_id, template_name="manage/product/product.ht
"""
Displays the whole manage/edit form for the product with the passed id.
"""
- AMOUNT = 20
product = lfs_get_object_or_404(Product, pk=product_id)
products = _get_filtered_products_for_product_view(request)
- paginator = Paginator(products, AMOUNT)
-
+ paginator = Paginator(products, 25)
temp = product.parent if product.is_variant() else product
- page = get_current_page(request, products, temp, AMOUNT)
+ page = get_current_page(request, products, temp, 25)
try:
page = paginator.page(page)
@@ -401,7 +405,7 @@ def edit_product_data(request, product_id, template_name="manage/product/data.ht
"""
product = lfs_get_object_or_404(Product, pk=product_id)
products = _get_filtered_products_for_product_view(request)
- paginator = Paginator(products, 20)
+ paginator = Paginator(products, 25)
page = paginator.page(request.REQUEST.get("page", 1))
# Transform empty field / "on" from checkbox to integer
@@ -471,7 +475,7 @@ def reset_filters(request):
del request.session["product_filters"]
products = _get_filtered_products(request)
- paginator = Paginator(products, 20)
+ paginator = Paginator(products, 25)
page = paginator.page(request.REQUEST.get("page", 1))
product_id = request.REQUEST.get("product-id", 0)
@@ -495,7 +499,7 @@ def save_products(request):
Saves products with passed ids (by request body).
"""
products = _get_filtered_products(request)
- paginator = Paginator(products, 20)
+ paginator = Paginator(products, 25)
page = paginator.page(request.REQUEST.get("page", 1))
if request.POST.get("action") == "delete":
@@ -579,7 +583,7 @@ def set_name_filter(request):
request.session["product_filters"] = product_filters
products = _get_filtered_products_for_product_view(request)
- paginator = Paginator(products, 20)
+ paginator = Paginator(products, 25)
page = paginator.page(request.REQUEST.get("page", 1))
product_id = request.REQUEST.get("product-id", 0)
@@ -550,7 +550,8 @@ select.categories {
/* input fields */
#id_name, #id_slug, #id_sku, #id_shop_owner, #id_from_email, #id_title, #id_redirect_to, #id_sku_manufacturer, #redirect_to, #id_position, #id_unit,
#id_priority, #id_price, #id_for_sale_price, #id_tax, #id_module, #id_link, #id_parent, #id_static_block, #id_price_unit, #id_template, #id_meta_title,
-#id_type, #id_step_type, #id_delivery_time, #id_type_of_quantity_field, #id_price_calculator, #id_base_price_unit, #id_base_price_amount, #id_active_base_price {
+#id_type, #id_step_type, #id_delivery_time, #id_type_of_quantity_field, #id_price_calculator, #id_base_price_unit, #id_base_price_amount, #id_active_base_price,
+#id_manufacturer_autocomplete, #id_manufacturer, #id_price_calculator {
width: 200px;
}
@@ -145,8 +145,16 @@ $(function() {
// ReferenceError due to undefined tinymce
}
show_ajax_loading();
+
+ // trigger form-save-start event when form is about to be submitted
+ var form = $(this).closest("form");
+ var form_id = form.get(0).id;
+ var event = jQuery.Event("form-save-start");
+ event.form_id = form_id;
+ $('body').trigger(event);
+
var action = $(this).attr("name")
- $(this).parents("form:first").ajaxSubmit({
+ form.ajaxSubmit({
data : {"action" : action},
success : function(data) {
data = $.parseJSON(data);
@@ -162,6 +170,11 @@ $(function() {
}
hide_ajax_loading();
update_editor();
+
+ // trigger form-save-end event when new HTML has already been injected into page
+ var event = jQuery.Event("form-save-end");
+ event.form_id = form_id;
+ $('body').trigger(event);
}
})
return false;
@@ -288,66 +301,64 @@ $(function() {
knot.parent().find(".category-state").html("");
};
- $(function() {
- $(".category-ajax-link").live("click", function() {
- var url = $(this).attr("href");
+ $(".category-ajax-link").live("click", function() {
+ var url = $(this).attr("href");
- // Loads children of clicked category.
- if ($(this).hasClass("collapsed")) {
- $.post(url, function(data) {
- data = $.parseJSON(data);
- for (var html in data["html"])
- $(data["html"][html][0]).html(data["html"][html][1]);
- })
- $(this).removeClass("collapsed");
- $(this).addClass("expanded");
- }
- // Removes children of clicked category.
- else {
- $(this).siblings("div").html("")
- $(this).removeClass("expanded");
- $(this).addClass("collapsed");
- }
- return false;
- });
+ // Loads children of clicked category.
+ if ($(this).hasClass("collapsed")) {
+ $.post(url, function(data) {
+ data = $.parseJSON(data);
+ for (var html in data["html"])
+ $(data["html"][html][0]).html(data["html"][html][1]);
+ })
+ $(this).removeClass("collapsed");
+ $(this).addClass("expanded");
+ }
+ // Removes children of clicked category.
+ else {
+ $(this).siblings("div").html("")
+ $(this).removeClass("expanded");
+ $(this).addClass("collapsed");
+ }
+ return false;
+ });
- $(".export-category-input").live("click", function() {
+ $(".export-category-input").live("click", function() {
- // select / deselect all child nodes
- var input = $(this);
- var parent_checked = this.checked;
- $(this).parent().find("input").each(function() { this.checked = parent_checked; })
+ // select / deselect all child nodes
+ var input = $(this);
+ var parent_checked = this.checked;
+ $(this).parent().find("input").each(function() { this.checked = parent_checked; })
- // Updates child and parent categories of clicked category
- var url = $(this).attr("data");
- if (parent_checked == true) {
- $.post(url, {"action" : "add"}, function(data) {
- update_sub_categories(input);
- update_parent_categories(input);
- });
- }
- else {
- $.post(url, {"action" : "remove"}, function(data) {
- update_sub_categories(input);
- update_parent_categories(input);
- });
- }
- });
+ // Updates child and parent categories of clicked category
+ var url = $(this).attr("data");
+ if (parent_checked == true) {
+ $.post(url, {"action" : "add"}, function(data) {
+ update_sub_categories(input);
+ update_parent_categories(input);
+ });
+ }
+ else {
+ $.post(url, {"action" : "remove"}, function(data) {
+ update_sub_categories(input);
+ update_parent_categories(input);
+ });
+ }
+ });
- $(".export-product-input").live("click", function() {
- // Add / Remove product
- var input = $(this);
- var url = $(this).attr("data");
- var checked = this.checked;
+ $(".export-product-input").live("click", function() {
+ // Add / Remove product
+ var input = $(this);
+ var url = $(this).attr("data");
+ var checked = this.checked;
- // Updates parent catgories of clicked product
- if (checked == true) {
- $.post(url, {"action" : "add"}, function(data) { update_parent_categories(input) } );
- }
- else {
- $.post(url, {"action" : "remove"}, function(data) { update_parent_categories(input) });
- }
- });
+ // Updates parent catgories of clicked product
+ if (checked == true) {
+ $.post(url, {"action" : "add"}, function(data) { update_parent_categories(input) } );
+ }
+ else {
+ $.post(url, {"action" : "remove"}, function(data) { update_parent_categories(input) });
+ }
});
$(".category-variants-options").live("change", function() {
@@ -0,0 +1,44 @@
+/* Handle autocomplete on manufacturer field at product management page
+ * Uses jquery UI autocomplete implementation
+ */
+$(function() {
+ var MANUFACTURER_AUTOCOMPLETE_SETTINGS = {
+ source: MANUFACTURERS_AJAX_URL,
+ select: function(event, ui){
+ $('#id_manufacturer').val(ui.item.value);
+ $('#id_manufacturer_autocomplete').val(ui.item.label);
+ return false;
+ },
+ focus: function(event, ui){
+ $('#id_manufacturer').val(ui.item.value);
+ $('#id_manufacturer_autocomplete').val(ui.item.label);
+ return false;
+ },
+ change: function(event, ui){
+ if (ui.item === null){
+ // only accept items selected from the list
+ $('#id_manufacturer').val('');
+ $('#id_manufacturer_autocomplete').val('');
+ }
+ return false;
+ },
+ minLength: 1
+ };
+
+ $('#id_manufacturer_autocomplete').autocomplete(MANUFACTURER_AUTOCOMPLETE_SETTINGS);
+ $('body').bind('form-save-start', function(evt){
+ if (evt.form_id == 'product-data-form'){
+ // ensure that manufacturer_id is cleared if autocomplete field is empty
+ if ($('#id_manufacturer_autocomplete').val() === ''){
+ $('#id_manufacturer').val('');
+ }
+ }
+ });
+
+ // when form is reloaded we have to reattach autocomplete
+ $('body').bind('form-save-end', function(evt){
+ if (evt.form_id == 'product-data-form'){
+ $('#id_manufacturer_autocomplete').autocomplete(MANUFACTURER_AUTOCOMPLETE_SETTINGS);
+ }
+ });
+})
@@ -103,6 +103,31 @@
</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 }}:
Oops, something went wrong.

0 comments on commit b018d5b

Please sign in to comment.