From ec1f36a72742c38198b1b4c7087b39e75f2495da Mon Sep 17 00:00:00 2001
From: Mikko Heikkinen
Date: Tue, 23 Jul 2024 16:40:52 +0300
Subject: [PATCH] Add school challenge type, without additional taxa
---
README.md | 6 +-
app/controllers/participation.py | 86 ++++++++++++++++------------
app/data/challenge_vocabulary.json | 8 ++-
app/data/data_models.txt | 2 +-
app/templates/form_challenge100.html | 9 ++-
5 files changed, 65 insertions(+), 46 deletions(-)
diff --git a/README.md b/README.md
index c134fba..e6e5dbe 100644
--- a/README.md
+++ b/README.md
@@ -42,11 +42,11 @@ Note that in order to create MariaDB database on Rahti, PHPMyAdmin data dump doe
- Setting up new challenge
- Provide list of basic taxa to `app/data/`, e.g. `plantae_2024.json` or use one of the existing ones.
- Provide list of all allowed taxa to `app/data/` (for backend) and `static/taxa/` (for frontend autocomplete), e.g. `plantae_2024_all.json`. This must contain all taxa that the basic list above contains, icnluding non-species.
-- Challenge has field for autocomplete-parameters, but these are not currently used. Instead autocomplete uses static file as described above. This is to
+- Challenges-table has field for autocomplete-parameters, but these are not currently used. Instead autocomplete uses static file as described above. This is to
- Make it faster than API calls (nearly instantaneous)
- Allow more flexibility, e.g. having only few higher taxa in addition to species
- The UI prevents setting dates that are outside the challenge dates, and dates in the future. This relies on min & max attributes on the date field and browser validation and error messages, and has limitations based on browser.
- - If a challenge for 2025 is published in 2024, users have to clear dates which they might have added by clicking the species name (i.e. dates that are in 2024). Better solution would be to edit the Javascript so that it wont add today's date if it's outside the allowed range.
+ - TODO: If a challenge for 2025 is published in 2024, users have to clear dates which they might have added by clicking the species name (i.e. dates that are in 2024). Better solution would be to edit the Javascript so that it wont add today's date if it's outside the allowed range.
- When challenge is in draft or closed state, editing it still needs to be possible, e.g. to anonymize or trash it. Therefore only editing species list is disabled by setting the date fields disabled, and not enabling Javascript to change them either.
#### Future: To have a new challenge type, you would need to:
@@ -103,8 +103,6 @@ Note that in order to create MariaDB database on Rahti, PHPMyAdmin data dump doe
- Handling higher taxa (is uses adds rikkavoikukka, don't add voikukat to taxon_count)
- Accessibility
- Challenge sort order (int) for the front page - larger number shown on top
-- School challenge:
- - No additional taxa (setting to challenge, modify form)
- Later / nice:
- Move login_url, api_url, target id yms. konfiguraatiotiedostoon
- Own data dump download
diff --git a/app/controllers/participation.py b/app/controllers/participation.py
index 554e4a0..fb4d91a 100644
--- a/app/controllers/participation.py
+++ b/app/controllers/participation.py
@@ -100,46 +100,56 @@ def make_taxa_html(challenge, taxa_dates_json = None):
del taxa_dates[taxon_id]
- # 2) Loop remaining taxa_dates, i.e. the additional taxa user has observed
+ # 2) If standard challenge, loop remaining taxa_dates, i.e. the additional taxa user has observed
- # If taxa_dates is empty, set message text
- if not taxa_dates:
- additional_taxa_html = "
Ei peruslistan ulkopuolisia lajeja.
\n"
+ if "challenge100" == challenge["type"]:
+ # If taxa_dates is empty, set message text
+ if not taxa_dates:
+ additional_taxa_html = "
Ei peruslistan ulkopuolisia lajeja.
\n"
+ else:
+ additional_taxa_html = ""
+ print(taxa_dates)
+
+ for observed_taxon_id, observed_taxon_date in taxa_dates.items():
+
+ # Add to additional_taxa_html
+ # Check if taxon exists in all_taxa_names. Might not if
+ # A) It has been added to Laji.fi after the taxon list on this app has been set up (if using API for autocomplete)
+ # B) basic and all taxon files are not in sync (if using files for autocomplete)
+ fin = "" # default
+ swe = "" # default
+ sci = observed_taxon_id # default
+ if observed_taxon_id in all_taxa_names:
+ sci = all_taxa_names[observed_taxon_id]["sci"]
+
+ # Finnish name might not exist
+ if "fin" in all_taxa_names[observed_taxon_id]:
+ fin = all_taxa_names[observed_taxon_id]["fin"]
+
+ # Swedish name might not exist
+ if "swe" in all_taxa_names[observed_taxon_id]:
+ swe = all_taxa_names[observed_taxon_id]["swe"]
+
+ additional_taxa_html += make_species_html(observed_taxon_id, fin, swe, sci, min_date, max_date, observed_taxon_date)
+
+ # Combine into a list
+ html = f"""
+
\n
+
Peruslistan ulkopuoliset lajit:
\n
+ { additional_taxa_html }
+
Peruslistan lajit:
\n
+ { basic_taxa_html }
+
\n
+ """
else:
- additional_taxa_html = ""
- print(taxa_dates)
-
- for observed_taxon_id, observed_taxon_date in taxa_dates.items():
-
- # Add to additional_taxa_html
- # Check if taxon exists in all_taxa_names. Might not if
- # A) It has been added to Laji.fi after the taxon list on this app has been set up (if using API for autocomplete)
- # B) basic and all taxon files are not in sync (if using files for autocomplete)
- fin = "" # default
- swe = "" # default
- sci = observed_taxon_id # default
- if observed_taxon_id in all_taxa_names:
- sci = all_taxa_names[observed_taxon_id]["sci"]
-
- # Finnish name might not exist
- if "fin" in all_taxa_names[observed_taxon_id]:
- fin = all_taxa_names[observed_taxon_id]["fin"]
-
- # Swedish name might not exist
- if "swe" in all_taxa_names[observed_taxon_id]:
- swe = all_taxa_names[observed_taxon_id]["swe"]
-
- additional_taxa_html += make_species_html(observed_taxon_id, fin, swe, sci, min_date, max_date, observed_taxon_date)
+ # Combine into a list
+ html = f"""
+
\n
+
Lajit:
\n
+ { basic_taxa_html }
+
\n
+ """
- # Combine into a list
- html = f"""
-
\n
-
Peruslistan ulkopuoliset lajit:
\n
- { additional_taxa_html }
-
Peruslistan lajit:
\n
- { basic_taxa_html }
-
\n
- """
return html
@@ -322,6 +332,7 @@ def main(challenge_id_untrusted, participation_id_untrusted, form_data = None):
# Get challenge data to see that it exists and if it is draft/open/closed.
challenge = get_challenge(challenge_id)
+ print(challenge)
# CASE X: Challenge cannot be found or participation is closed
if not challenge:
@@ -330,7 +341,6 @@ def main(challenge_id_untrusted, participation_id_untrusted, form_data = None):
return {"redirect": True, "url": "/"}
html["challenge"] = challenge
- print(challenge)
# Case A: User opened an empty form for submitting a new participation.
if not participation_id and not form_data:
diff --git a/app/data/challenge_vocabulary.json b/app/data/challenge_vocabulary.json
index a6ea291..7ebe74d 100644
--- a/app/data/challenge_vocabulary.json
+++ b/app/data/challenge_vocabulary.json
@@ -9,7 +9,13 @@
{
"key": "challenge100",
"label": {
- "fi": "100 lajia -haaste"
+ "fi": "Yleinen 100 lajia -haaste"
+ }
+ },
+ {
+ "key": "school100",
+ "label": {
+ "fi": "Koulujen 100 lajia -haaste"
}
}
]
diff --git a/app/data/data_models.txt b/app/data/data_models.txt
index e6d3548..9db8462 100644
--- a/app/data/data_models.txt
+++ b/app/data/data_models.txt
@@ -10,7 +10,7 @@ CREATE TABLE `challenges` (
`taxon` varchar(16) NOT NULL, Taxon file identifier.
`date_begin` varchar(10) DEFAULT NULL,
`date_end` varchar(10) DEFAULT NULL,
- `type` varchar(16) NOT NULL, Currently only one allowed value: challenge100.
+ `type` varchar(16) NOT NULL.
`title` varchar(255) NOT NULL, Name of the challenge.
`status` varchar(8) NOT NULL, Allowed values: draft, open, closed.
`description` varchar(2048) DEFAULT NULL,
diff --git a/app/templates/form_challenge100.html b/app/templates/form_challenge100.html
index 45e19b5..53eeedc 100644
--- a/app/templates/form_challenge100.html
+++ b/app/templates/form_challenge100.html
@@ -218,6 +218,8 @@
{% block body %}
+
+
{% if html.get('participation', {}).get('trashed') == 1 %}
Olet merkinnyt tämän osallistumisen poistetuksi, joten muut eivät näe sitä. (Voit palauttaa sen näkyville muuttamalla osallistumisen tilan julkiseksi ja tallentamalla.)
@@ -261,7 +263,7 @@
Osallistuminen: {{ html['challenge']['title'] }}
-
+
{{ html['data_fields']['taxa_count'] }} lajia
{% endif %}
{% endif %}
-
+
{% if html['disabled'] != 'disabled' %}