From 5778b5dae66c7e7f5c2017f8e51016c2628a80a4 Mon Sep 17 00:00:00 2001 From: Rico Hermans Date: Tue, 18 Jun 2024 19:25:17 +0200 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=A7=B9=20Tags:=20remove=20double=20ge?= =?UTF-8?q?t,=20sort=20tags?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two tiny changes ported over from #5431: - Remove a duplicate database retrieval when looking up the tags of an adventure. - Sort the tags (when they are saved to the database). --- website/tags.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/tags.py b/website/tags.py index 9b8f82350b1..cf5ee11c2be 100644 --- a/website/tags.py +++ b/website/tags.py @@ -30,7 +30,6 @@ def get_public_tags(self, user, adventure_id): adventure_id = request.args.get("adventure_id") adventure = self.db.get_adventure(adventure_id) if adventure: - adventure = self.db.get_adventure(adventure_id) # exclude current adventure's tags public_tags = list(filter(lambda t: t["name"] not in adventure.get("tags", []), public_tags)) @@ -56,6 +55,7 @@ def create(self, user, adventure_id, new_tag=None): adventure_tags = db_adventure.get("tags", []) if tag_name not in adventure_tags: adventure_tags.append(tag_name) + adventure_tags = sorted(adventure_tags, key=lambda tag: tag) self.db.update_adventure(adventure_id, {"tags": adventure_tags}) else: return make_response(gettext("tag_in_adventure"), 400) From 8bf1719f52272d0bdccff68005cf37322699b631 Mon Sep 17 00:00:00 2001 From: Rico Hermans Date: Wed, 19 Jun 2024 21:09:13 +0200 Subject: [PATCH 2/2] Copy test over as well --- .../e2e/for-teacher_page/customize-adventure_page/tags.cy.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/cypress/e2e/for-teacher_page/customize-adventure_page/tags.cy.js b/tests/cypress/e2e/for-teacher_page/customize-adventure_page/tags.cy.js index 8ec22f3ed33..88c7f7ec016 100644 --- a/tests/cypress/e2e/for-teacher_page/customize-adventure_page/tags.cy.js +++ b/tests/cypress/e2e/for-teacher_page/customize-adventure_page/tags.cy.js @@ -66,10 +66,10 @@ describe("Tags of adventures", () => { }).as("deleteTag") cy.wait(500) - cy.get("#tag_2") + cy.get("#tag_1") .should("be.visible") .should("include.text", "statements") - cy.get("#tag_2 .fa-circle-xmark") + cy.get("#tag_1 .fa-circle-xmark") .click() cy.wait("@deleteTag").should('have.nested.property', 'response.statusCode', 200) cy.get("#tags_list li")