|
19 | 19 | app.mount("/static", StaticFiles(directory=os.path.join(Path(__file__).parent, |
20 | 20 | "static")), name="static") |
21 | 21 |
|
| 22 | + |
| 23 | +# Update the Activity class to include participants |
| 24 | +class Activity: |
| 25 | + def __init__(self, id, name, date, location, description): |
| 26 | + self.id = id |
| 27 | + self.name = name |
| 28 | + self.date = date |
| 29 | + self.location = location |
| 30 | + self.description = description |
| 31 | + self.participants = [] # Add a list to store participants |
| 32 | + |
| 33 | + |
22 | 34 | # In-memory activity database |
23 | | -activities = { |
24 | | - "Chess Club": { |
25 | | - "description": "Learn strategies and compete in chess tournaments", |
26 | | - "schedule": "Fridays, 3:30 PM - 5:00 PM", |
27 | | - "max_participants": 12, |
28 | | - |
29 | | - }, |
30 | | - "Programming Class": { |
31 | | - "description": "Learn programming fundamentals and build software projects", |
32 | | - "schedule": "Tuesdays and Thursdays, 3:30 PM - 4:30 PM", |
33 | | - "max_participants": 20, |
34 | | - |
35 | | - }, |
36 | | - "Gym Class": { |
37 | | - "description": "Physical education and sports activities", |
38 | | - "schedule": "Mondays, Wednesdays, Fridays, 2:00 PM - 3:00 PM", |
39 | | - "max_participants": 30, |
40 | | - |
41 | | - }, |
42 | | - # Sports related activities |
43 | | - "Soccer Team": { |
44 | | - "description": "Join the school soccer team and compete in matches", |
45 | | - "schedule": "Wednesdays, 4:00 PM - 5:30 PM", |
46 | | - "max_participants": 22, |
47 | | - |
48 | | - }, |
49 | | - "Basketball Club": { |
50 | | - "description": "Practice basketball skills and play friendly games", |
51 | | - "schedule": "Mondays, 3:30 PM - 5:00 PM", |
52 | | - "max_participants": 15, |
53 | | - |
54 | | - }, |
55 | | - # Artistic activities |
56 | | - "Art Workshop": { |
57 | | - "description": "Explore painting, drawing, and sculpture techniques", |
58 | | - "schedule": "Thursdays, 4:00 PM - 5:30 PM", |
59 | | - "max_participants": 18, |
60 | | - |
61 | | - }, |
62 | | - "Drama Club": { |
63 | | - "description": "Act, direct, and produce school plays and performances", |
64 | | - "schedule": "Tuesdays, 3:30 PM - 5:00 PM", |
65 | | - "max_participants": 20, |
66 | | - |
67 | | - }, |
68 | | - # Intellectual activities |
69 | | - "Math Olympiad": { |
70 | | - "description": "Prepare for math competitions and solve challenging problems", |
71 | | - "schedule": "Fridays, 4:00 PM - 5:30 PM", |
72 | | - "max_participants": 16, |
73 | | - |
74 | | - }, |
75 | | - "Science Club": { |
76 | | - "description": "Conduct experiments and explore scientific concepts", |
77 | | - "schedule": "Wednesdays, 3:30 PM - 5:00 PM", |
78 | | - "max_participants": 14, |
79 | | - |
80 | | - } |
81 | | -} |
| 35 | +activities = [ |
| 36 | + Activity(1, "Hiking at Mountain Trail", "2023-10-15", "Mountain Park", |
| 37 | + "A beginner-friendly hiking trip with beautiful views."), |
| 38 | + Activity(2, "Community Cleanup", "2023-10-22", "City Beach", |
| 39 | + "Help keep our beach clean! Supplies will be provided."), |
| 40 | + Activity(3, "Charity Run", "2023-11-05", "Downtown", |
| 41 | + "5k run to raise funds for the local animal shelter.") |
| 42 | +] |
| 43 | + |
| 44 | + |
| 45 | +# Add function to add a participant to an activity |
| 46 | +def add_participant_to_activity(activity_id, participant_name): |
| 47 | + for activity in activities: |
| 48 | + if activity.id == int(activity_id): |
| 49 | + if participant_name not in activity.participants: |
| 50 | + activity.participants.append(participant_name) |
| 51 | + return True |
| 52 | + return False |
82 | 53 |
|
83 | 54 |
|
84 | 55 | @app.get("/") |
@@ -108,3 +79,28 @@ def signup_for_activity(activity_name: str, email: str): |
108 | 79 | # Add student |
109 | 80 | activity["participants"].append(email) |
110 | 81 | return {"message": f"Signed up {email} for {activity_name}"} |
| 82 | + |
| 83 | + |
| 84 | +# Add route to handle participant registration |
| 85 | +@app.route('/register', methods=['POST']) |
| 86 | +def register(): |
| 87 | + activity_id = request.form.get('activity_id') |
| 88 | + participant_name = request.form.get('participant_name') |
| 89 | + |
| 90 | + if not activity_id or not participant_name: |
| 91 | + return redirect(url_for('index', error="Please fill in all fields")) |
| 92 | + |
| 93 | + success = add_participant_to_activity(activity_id, participant_name) |
| 94 | + |
| 95 | + if success: |
| 96 | + return redirect(url_for('index', message="Successfully registered for the activity!")) |
| 97 | + else: |
| 98 | + return redirect(url_for('index', error="Activity not found or registration failed")) |
| 99 | + |
| 100 | + |
| 101 | +# Update the index route to pass error/success messages |
| 102 | +@app.route('/') |
| 103 | +def index(): |
| 104 | + error = request.args.get('error') |
| 105 | + message = request.args.get('message') |
| 106 | + return render_template('index.html', activities=activities, error=error, message=message) |
0 commit comments