Remove some confusing complexity from restrictions

This commit is contained in:
Raphael Michel
2015-01-07 22:02:08 +01:00
parent a5a976b16a
commit 6b5027e412
5 changed files with 39 additions and 12 deletions
+9 -5
View File
@@ -179,11 +179,9 @@ In our example, the implementation could look like this::
applied_to = list(restriction.variations.all())
# Only take this restriction into consideration if it either
# is directly applied to this variation OR is applied to all
# variations (e.g. the applied_to list is empty)
if len(applied_to) > 0:
if 'variation' not in v or v['variation'] not in applied_to:
continue
# is directly applied to this variation
if 'variation' not in v or v['variation'] not in applied_to:
continue
if restriction.timeframe_from <= now() <= restriction.timeframe_to:
# Selling this item is currently possible
@@ -236,6 +234,9 @@ You are expected to return a dict containing the following items:
``title``
A title for your formset (normally your plugin name)
``description``
An short, explanatory text about your restriction.
Our time restriction example looks like this::
@@ -280,6 +281,9 @@ Our time restriction example looks like this::
'title': _('Restriction by time'),
'formsetclass': formset,
'prefix': 'timerestriction',
'description': 'If you use this restriction type, the system will only '
'sell variations, which are covered by at least one of the '
'timeframes you define below.'
}
@@ -4,5 +4,15 @@ $(function () {
animateForms: true,
reorderMode: 'animate'
});
$(document).on("click", ".variations .variations-select-all", function (e) {
$(this).parent().parent().find("input[type=checkbox]").prop("checked", true);
e.stopPropagation();
return false;
});
$(document).on("click", ".variations .variations-select-none", function (e) {
$(this).parent().parent().find("input[type=checkbox]").prop("checked", false);
e.stopPropagation();
return false;
});
$('.collapse').collapse();
});
@@ -3,11 +3,16 @@
{% load bootstrap3 %}
{% load formset_tags %}
{% block inside %}
<p>{% blocktrans trimmed %}
In this area, you can choose of a set of "restriction types" to restrict the availability of your item with
certain conditions.
{% endblocktrans %}</p>
<form action="" method="post">
{% csrf_token %}
{% for set in formsets %}
<fieldset>
<legend>{{ set.title }}</legend>
<p>{{ set.description }}</p>
<div data-formset class="restriction-formset" data-formset-prefix="{{ set.formset.prefix }}">
<div data-formset-body class="panel-group collapse" id="accordion_{{ set.formset.prefix }}">
{{ set.formset.management_form }}
+7 -1
View File
@@ -214,7 +214,13 @@ class VariationsFieldRenderer(forms.widgets.CheckboxFieldRenderer):
output.append(format_html('<td><label><input{0} /></label></td>', flatatt(final_attrs)))
output.append('</td>')
output.append('</tbody></table>')
output.append('</div>')
output.append(
('<div class="help-block"><a href="#" class="variations-select-all">{0}</a> · '
'<a href="#" class="variations-select-none">{1}</a></div></div>').format(
_("Select all"),
_("Deselect all")
)
)
return mark_safe('\n'.join(output))
+8 -6
View File
@@ -81,12 +81,10 @@ def availability_handler(sender, **kwargs):
for restriction in restrictions:
applied_to = list(restriction.variations.current.all())
# Only take this restriction into consideration if it either
# is directly applied to this variation OR is applied to all
# variations (e.g. the applied_to list is empty)
if len(applied_to) > 0:
if 'variation' not in v or v['variation'] not in applied_to:
continue
# Only take this restriction into consideration if it
# is directly applied to this variation
if 'variation' not in v or v['variation'] not in applied_to:
continue
if restriction.timeframe_from <= now() <= restriction.timeframe_to:
# Selling this item is currently possible
@@ -140,4 +138,8 @@ def formset_handler(sender, **kwargs):
'title': _('Restriction by time'),
'formsetclass': formset,
'prefix': 'timerestriction',
'description': 'If you use this restriction type, the system will only sell variations, which are covered '
'by at least one of the timeframes you define below. You can also change the price of '
'variations for within the given timeframe. Please note, that if you change the price of '
'variations here, this will overrule the price set in the "Variations" section.'
}