Revision b4401a0c flowspec/forms.py

b/flowspec/forms.py
7 7
from ipaddr import *
8 8
from django.core.urlresolvers import reverse
9 9
from django.contrib.auth.models import User
10
from django.conf import settings
10 11
import datetime
11 12

  
12 13

  
......
43 44

  
44 45
    def clean_destination(self):
45 46
        data = self.cleaned_data['destination']
47
        error = None
46 48
        if data:
47 49
            try:
48 50
                address = IPNetwork(data)
51
                if address.prefixlen < settings.PREFIX_LENGTH:
52
                    error = "Currently no prefix lengths < %s are allowed" %settings.PREFIX_LENGTH
53
                    raise forms.ValidationError('error')
49 54
                return self.cleaned_data["destination"]
50 55
            except Exception:
51
                raise forms.ValidationError('Invalid network address format')
56
                if error:
57
                    error_text = error
58
                else:
59
                    error_text = 'Invalid network address format'
60
                raise forms.ValidationError(error_text)
52 61
    
53 62
    def clean_expires(self):
54 63
        date = self.cleaned_data['expires']

Also available in: Unified diff