Skip to content

Commit 6114635

Browse files
committed
Implement participant registration feature and update activity structure
1 parent 748ec4c commit 6114635

File tree

4 files changed

+362
-59
lines changed

4 files changed

+362
-59
lines changed

src/app.py

Lines changed: 55 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -19,66 +19,37 @@
1919
app.mount("/static", StaticFiles(directory=os.path.join(Path(__file__).parent,
2020
"static")), name="static")
2121

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+
2234
# 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-
"participants": ["[email protected]", "[email protected]"]
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-
"participants": ["[email protected]", "[email protected]"]
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-
"participants": ["[email protected]", "[email protected]"]
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-
"participants": ["[email protected]", "[email protected]"]
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-
"participants": ["[email protected]", "[email protected]"]
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-
"participants": ["[email protected]", "[email protected]"]
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-
"participants": ["[email protected]", "[email protected]"]
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-
"participants": ["[email protected]", "[email protected]"]
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-
"participants": ["[email protected]", "[email protected]"]
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
8253

8354

8455
@app.get("/")
@@ -108,3 +79,28 @@ def signup_for_activity(activity_name: str, email: str):
10879
# Add student
10980
activity["participants"].append(email)
11081
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)

src/static/app.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,47 @@ document.addEventListener("DOMContentLoaded", () => {
8181
}
8282
});
8383

84+
// Handle the registration form submission
85+
const registrationForm = document.getElementById("registration-form");
86+
if (registrationForm) {
87+
registrationForm.addEventListener("submit", function (e) {
88+
const activityId = document.getElementById("activity-select").value;
89+
const participantName = document.getElementById("participant-name").value;
90+
91+
if (!activityId || !participantName) {
92+
e.preventDefault();
93+
showMessage("Please fill in all fields", "error");
94+
}
95+
});
96+
}
97+
98+
// Check for URL parameters to show success/error messages
99+
const urlParams = new URLSearchParams(window.location.search);
100+
const errorMessage = urlParams.get("error");
101+
const successMessage = urlParams.get("message");
102+
103+
if (errorMessage) {
104+
showMessage(errorMessage, "error");
105+
}
106+
107+
if (successMessage) {
108+
showMessage(successMessage, "success");
109+
}
110+
111+
// Function to show messages
112+
function showMessage(text, type) {
113+
const messageDiv = document.getElementById("message");
114+
if (messageDiv) {
115+
messageDiv.textContent = text;
116+
messageDiv.className = `message ${type}`;
117+
messageDiv.classList.remove("hidden");
118+
119+
setTimeout(() => {
120+
messageDiv.classList.add("hidden");
121+
}, 5000);
122+
}
123+
}
124+
84125
// Initialize app
85126
fetchActivities();
86127
});

src/static/styles.css

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,57 @@ section h3 {
7474
margin-bottom: 8px;
7575
}
7676

77+
/* Participants section styling */
78+
.participants-section {
79+
margin-top: 15px;
80+
border-top: 1px dashed #ddd;
81+
padding-top: 10px;
82+
}
83+
84+
.participants-section h5 {
85+
color: #1a237e;
86+
margin-bottom: 8px;
87+
font-size: 0.95rem;
88+
}
89+
90+
.participants-list {
91+
list-style-type: none;
92+
margin-left: 5px;
93+
}
94+
95+
.participants-list li {
96+
padding: 4px 0;
97+
display: flex;
98+
align-items: center;
99+
}
100+
101+
.participants-list li:before {
102+
content: "•";
103+
color: #3949ab;
104+
font-weight: bold;
105+
display: inline-block;
106+
width: 1em;
107+
margin-right: 5px;
108+
}
109+
110+
.participant-badge {
111+
background-color: #e8eaf6;
112+
border-radius: 15px;
113+
padding: 4px 10px;
114+
font-size: 0.85rem;
115+
color: #3949ab;
116+
display: inline-block;
117+
margin-right: 5px;
118+
border: 1px solid #c5cae9;
119+
}
120+
121+
/* Empty participants message */
122+
.no-participants {
123+
font-style: italic;
124+
color: #757575;
125+
font-size: 0.9rem;
126+
}
127+
77128
.form-group {
78129
margin-bottom: 15px;
79130
}

0 commit comments

Comments
 (0)