Revision f1bd3b97 flowspec/forms.py

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

  

Also available in: Unified diff