Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -124,26 +124,34 @@ def filter_by_fields(selected_country, selected_city, selected_language):
|
|
| 124 |
with open(DATA_FILE, "r") as f:
|
| 125 |
data = json.load(f)
|
| 126 |
|
| 127 |
-
|
| 128 |
-
if df.empty:
|
| 129 |
return "<p>No data available.</p>"
|
| 130 |
|
| 131 |
-
df
|
| 132 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
if selected_country != "All":
|
| 134 |
-
df = df[df["Country"]
|
| 135 |
if selected_city != "All":
|
| 136 |
-
df = df[df["City"]
|
| 137 |
if selected_language != "All":
|
| 138 |
-
df = df[df["Languages"].str.contains(selected_language)]
|
| 139 |
-
|
| 140 |
-
if "Address" in df.columns:
|
| 141 |
-
df.drop(columns=["Address"], inplace=True)
|
| 142 |
|
| 143 |
if df.empty:
|
| 144 |
return "<p>No participants match your filters.</p>"
|
| 145 |
|
| 146 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
display_names = {
|
| 148 |
"Discord": "Discord",
|
| 149 |
"Name": "Name",
|
|
@@ -159,17 +167,17 @@ def filter_by_fields(selected_country, selected_city, selected_language):
|
|
| 159 |
"Experience": "Experience",
|
| 160 |
"Project Idea": "Project Idea"
|
| 161 |
}
|
| 162 |
-
|
| 163 |
html = '<h3 style="margin-top:20px;">π Find your matching Teammates & Register your team <a href="https://forms.gle/gJEMGD4CEA2emhD18" target="_blank">here</a>ππ</h3>'
|
| 164 |
html += "<table style='width:100%; border-collapse: collapse;'>"
|
| 165 |
|
| 166 |
-
#
|
| 167 |
html += "<tr>"
|
| 168 |
for col in df.columns:
|
| 169 |
-
html += f"<th style='border: 1px solid #ccc; padding: 6px;'>{col}</th>"
|
| 170 |
html += "</tr>"
|
| 171 |
|
| 172 |
-
#
|
| 173 |
for _, row in df.iterrows():
|
| 174 |
html += "<tr>"
|
| 175 |
for col in df.columns:
|
|
@@ -182,6 +190,7 @@ def filter_by_fields(selected_country, selected_city, selected_language):
|
|
| 182 |
html += "</table>"
|
| 183 |
return html
|
| 184 |
|
|
|
|
| 185 |
def delete_by_discord(discord, code):
|
| 186 |
if code != ADMIN_CODE:
|
| 187 |
return "β Invalid admin code."
|
|
|
|
| 124 |
with open(DATA_FILE, "r") as f:
|
| 125 |
data = json.load(f)
|
| 126 |
|
| 127 |
+
if not data:
|
|
|
|
| 128 |
return "<p>No data available.</p>"
|
| 129 |
|
| 130 |
+
df = pd.DataFrame(data)
|
| 131 |
|
| 132 |
+
# Normalize key fields
|
| 133 |
+
df["Country"] = df["Country"].astype(str).str.strip().str.title()
|
| 134 |
+
df["City"] = df["City"].astype(str).str.strip().str.title()
|
| 135 |
+
df["Languages"] = df["Languages"].apply(
|
| 136 |
+
lambda x: ", ".join(x) if isinstance(x, list) else str(x)
|
| 137 |
+
).str.lower().str.strip()
|
| 138 |
+
|
| 139 |
+
# Apply filters
|
| 140 |
if selected_country != "All":
|
| 141 |
+
df = df[df["Country"] == selected_country.strip().title()]
|
| 142 |
if selected_city != "All":
|
| 143 |
+
df = df[df["City"] == selected_city.strip().title()]
|
| 144 |
if selected_language != "All":
|
| 145 |
+
df = df[df["Languages"].str.contains(selected_language.lower())]
|
|
|
|
|
|
|
|
|
|
| 146 |
|
| 147 |
if df.empty:
|
| 148 |
return "<p>No participants match your filters.</p>"
|
| 149 |
|
| 150 |
+
# Optional: hide address
|
| 151 |
+
if "Address" in df.columns:
|
| 152 |
+
df = df.drop(columns=["Address"])
|
| 153 |
+
|
| 154 |
+
# Optional: rename headers
|
| 155 |
display_names = {
|
| 156 |
"Discord": "Discord",
|
| 157 |
"Name": "Name",
|
|
|
|
| 167 |
"Experience": "Experience",
|
| 168 |
"Project Idea": "Project Idea"
|
| 169 |
}
|
| 170 |
+
|
| 171 |
html = '<h3 style="margin-top:20px;">π Find your matching Teammates & Register your team <a href="https://forms.gle/gJEMGD4CEA2emhD18" target="_blank">here</a>ππ</h3>'
|
| 172 |
html += "<table style='width:100%; border-collapse: collapse;'>"
|
| 173 |
|
| 174 |
+
# Table headers
|
| 175 |
html += "<tr>"
|
| 176 |
for col in df.columns:
|
| 177 |
+
html += f"<th style='border: 1px solid #ccc; padding: 6px;'>{display_names.get(col, col)}</th>"
|
| 178 |
html += "</tr>"
|
| 179 |
|
| 180 |
+
# Table rows
|
| 181 |
for _, row in df.iterrows():
|
| 182 |
html += "<tr>"
|
| 183 |
for col in df.columns:
|
|
|
|
| 190 |
html += "</table>"
|
| 191 |
return html
|
| 192 |
|
| 193 |
+
# Delete discord
|
| 194 |
def delete_by_discord(discord, code):
|
| 195 |
if code != ADMIN_CODE:
|
| 196 |
return "β Invalid admin code."
|