Skip to content

Commit

Permalink
Validate emails
Browse files Browse the repository at this point in the history
  • Loading branch information
symroe committed Apr 12, 2023
1 parent 1d6104a commit c57515a
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions v1/models/base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import datetime
from typing import List, Optional

from email_validator import validate_email
from pydantic import (
BaseModel,
EmailStr,
Expand Down Expand Up @@ -71,6 +72,14 @@ class Person(BaseModel):
photo_url: Optional[HttpUrl] = Field()
leaflets: Optional[List[Leaflet]]

@validator("email", pre=True)
def validate_email(cls, value):
if not value:
return
try:
validate_email(value)
except ValueError:
return None

class PreviousParty(BaseModel):
...
Expand All @@ -90,11 +99,11 @@ class VotingSystem(BaseModel):

class Husting(BaseModel):
title: str = Field()
url: Optional[HttpUrl] = Field()
url: Optional[str] = Field()
starts: Optional[str] = Field()
ends: Optional[str] = Field()
location: Optional[str] = Field()
postevent_url: Optional[HttpUrl] = Field()
postevent_url: Optional[str] = Field(min_length=0)


class Ballot(BaseModel):
Expand Down

0 comments on commit c57515a

Please sign in to comment.