-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #103 from opportunity-hack/develop
[Admin] Support adding new hackathon and editing existing without edi…
- Loading branch information
Showing
3 changed files
with
119 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import re | ||
from urllib.parse import urlparse | ||
import logging | ||
from datetime import datetime | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
@@ -80,6 +81,28 @@ def sanitize_string(input_string, max_length=None): | |
|
||
# You can add more validator functions as needed | ||
|
||
def validate_hackathon_data(data): | ||
required_fields = ["title", "description", "location", "start_date", "end_date", "type", "image_url", "event_id"] | ||
for field in required_fields: | ||
if field not in data or not data[field]: | ||
raise ValueError(f"Missing required field: {field}") | ||
|
||
# Validate dates | ||
try: | ||
start_date = datetime.fromisoformat(data["start_date"]) | ||
end_date = datetime.fromisoformat(data["end_date"]) | ||
if end_date <= start_date: | ||
raise ValueError("End date must be after start date") | ||
except ValueError as e: | ||
raise ValueError(f"Invalid date format: {str(e)}") | ||
|
||
# Validate constraints | ||
constraints = data.get("constraints", {}) | ||
if not all(isinstance(constraints.get(k), int) for k in ["max_people_per_team", "max_teams_per_problem", "min_people_per_team"]): | ||
raise ValueError("Constraints must be integers") | ||
|
||
# Add more specific validations as needed | ||
|
||
if __name__ == "__main__": | ||
# Simple tests | ||
print(validate_email("[email protected]")) # Should print True | ||
|