Revision f1bd3b97
b/flowspec/forms.py | ||
---|---|---|
217 | 217 |
if any(self.errors): |
218 | 218 |
return |
219 | 219 |
super(MyRuleFormSet, self).clean() |
220 |
names = [] |
|
220 |
rules = [] |
|
221 |
sources = [] |
|
222 |
destinations = [] |
|
223 |
protocols = [] |
|
224 |
sourceports = [] |
|
225 |
destinationports = [] |
|
226 |
ports = [] |
|
227 |
errors = [] |
|
228 |
same_source_nets = False |
|
229 |
same_dest_nets = False |
|
221 | 230 |
for i in range(0, self.total_form_count()): |
231 |
rule = {} |
|
222 | 232 |
form = self.forms[i] |
223 |
name = form.cleaned_data['name'] |
|
224 |
names.append(name) |
|
225 |
# raise forms.ValidationError("Names %s" %names) |
|
233 |
source = IPNetwork(form.cleaned_data['source']) |
|
234 |
destination = IPNetwork(form.cleaned_data['destination']) |
|
235 |
protocol = form.cleaned_data['protocol'] |
|
236 |
sourceport = form.cleaned_data['sourceport'] |
|
237 |
destinationport = form.cleaned_data['destinationport'] |
|
238 |
port = form.cleaned_data['port'] |
|
239 |
rule = { |
|
240 |
'source' : source, |
|
241 |
'destination' : destination, |
|
242 |
'protocol' : protocol, |
|
243 |
'sourceport' : sourceport, |
|
244 |
'destinationport' : destinationport, |
|
245 |
'port' : port, |
|
246 |
} |
|
247 |
if sources: |
|
248 |
for s in sources: |
|
249 |
if (s in source) or (source in s): |
|
250 |
same_source_nets = True |
|
251 |
else: |
|
252 |
sources.append(source) |
|
253 |
if destinations: |
|
254 |
for d in destinations: |
|
255 |
if (d in destination) or (destination in d): |
|
256 |
same_dest_nets = True |
|
257 |
else: |
|
258 |
destinations.append(destination) |
|
259 |
if same_source_nets: |
|
260 |
raise forms.ValidationError("Detected same sources") |
|
261 |
rules.append(rule) |
|
262 |
raise forms.ValidationError("%s" %rules) |
|
226 | 263 |
|
227 | 264 |
RuleFormSet = modelformset_factory(Route, form=RouteForm, formset=MyRuleFormSet) |
228 | 265 |
|
b/static/js/jquery.formset.js | ||
---|---|---|
70 | 70 |
row.hide(); |
71 | 71 |
forms = $('.' + options.formCssClass).not(':hidden'); |
72 | 72 |
} else { |
73 |
row.remove();
|
|
74 |
// Update the TOTAL_FORMS count:
|
|
73 |
row.remove();
|
|
74 |
// Update the TOTAL_FORMS count:
|
|
75 | 75 |
forms = $('.' + options.formCssClass).not('.formset-custom-template'); |
76 | 76 |
totalForms.val(forms.length); |
77 | 77 |
} |
... | ... | |
116 | 116 |
if (hasChildElements(row)) { |
117 | 117 |
row.addClass(options.formCssClass); |
118 | 118 |
if (row.is(':visible')) { |
119 |
insertDeleteLink(row); |
|
119 |
forms_tmp = $('.' + options.formCssClass).not('.formset-custom-template'); |
|
120 |
if(forms_tmp.length == 1) { |
|
121 |
forms_tmp.find('a.' + options.deleteCssClass).hide(); |
|
122 |
|
|
123 |
} else { |
|
124 |
insertDeleteLink(row); |
|
125 |
} |
|
120 | 126 |
applyExtraClasses(row, i); |
121 | 127 |
} |
122 | 128 |
} |
... | ... | |
174 | 180 |
buttonRow = $($(this).parents('tr.' + options.formCssClass + '-add').get(0) || this); |
175 | 181 |
applyExtraClasses(row, formCount); |
176 | 182 |
row.insertBefore(buttonRow).show(); |
183 |
forms_tmp = $('.' + options.formCssClass).not('.formset-custom-template'); |
|
184 |
if(forms_tmp.length == 1) { |
|
185 |
forms_tmp.find('a.' + options.deleteCssClass).hide(); |
|
186 |
|
|
187 |
} else { |
|
188 |
insertDeleteLink(row); |
|
189 |
} |
|
177 | 190 |
row.find(childElementSelector).each(function() { |
178 | 191 |
updateElementIndex($(this), options.prefix, formCount); |
179 | 192 |
}); |
Also available in: Unified diff