Skip to content

Commit

Permalink
updated forms validators
Browse files Browse the repository at this point in the history
updated check prot and ip_validator so that they raise the ValidationError now
  • Loading branch information
agmes4 committed Sep 24, 2023
1 parent c00dcc8 commit 6f914f6
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions sipa/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,13 +483,22 @@ class RegisterRoomForm(FlaskForm):


def ip_validatior(form, field: str):
print(field.data)
ip = ipaddress.ip_address(field.data)
"""
checks rather the field contains a valid ip address
"""
try:
ipaddress.ip_address(field.data)
except:
raise ValidationError



def check_prot(form, field):
"""
Checks rather the fild contains a valid protocol
"""
if not field.data == "udp" and not field.data == "tcp":
raise ValueError
raise ValidationError


class AddPortForwardForm(FlaskForm):
Expand All @@ -499,6 +508,9 @@ class AddPortForwardForm(FlaskForm):
prot = StringField(label="port", validators=[check_prot])

def get_list(self) -> list:
"""
retruns the list for the port forward table
"""
return [self.source_port.data, self.dest_port.data, self.ip_address.data, self.prot.data.upper()]


Expand Down

0 comments on commit 6f914f6

Please sign in to comment.