From 3d2301b94cd87f1c64515e1f799369309c0ee09b Mon Sep 17 00:00:00 2001 From: OndraRehounek <ondra.rehounek@seznam.cz> Date: Thu, 21 Apr 2022 11:26:38 +0200 Subject: [PATCH] Redmine: Fix issue links --- .../0056_alter_districtprogrampage_content.py | 159 ++++++++++++++++++ .../district/blocks/program_block.html | 27 ++- redmine_utils/functions.py | 3 + .../0031_alter_regionprogrampage_content.py | 159 ++++++++++++++++++ shared/blocks.py | 1 + 5 files changed, 342 insertions(+), 7 deletions(-) create mode 100644 district/migrations/0056_alter_districtprogrampage_content.py create mode 100644 region/migrations/0031_alter_regionprogrampage_content.py diff --git a/district/migrations/0056_alter_districtprogrampage_content.py b/district/migrations/0056_alter_districtprogrampage_content.py new file mode 100644 index 00000000..5f3f8304 --- /dev/null +++ b/district/migrations/0056_alter_districtprogrampage_content.py @@ -0,0 +1,159 @@ +# Generated by Django 4.0.3 on 2022-04-21 09:25 + +import wagtail.core.blocks +import wagtail.core.fields +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("district", "0055_alter_districtarticlepage_content_and_more"), + ] + + operations = [ + migrations.AlterField( + model_name="districtprogrampage", + name="content", + field=wagtail.core.fields.StreamField( + [ + ( + "static_program_block", + wagtail.core.blocks.StructBlock( + [ + ( + "headline", + wagtail.core.blocks.CharBlock( + label="Titulek bloku", required=True + ), + ), + ( + "perex", + wagtail.core.blocks.TextBlock( + label="Krátký text pod nadpisem", required=True + ), + ), + ( + "person", + wagtail.core.blocks.PageChooserBlock( + label="Garant", + page_type=["district.DistrictPersonPage"], + ), + ), + ( + "completion_percentage", + wagtail.core.blocks.IntegerBlock( + label="Procento dokončení", required=True + ), + ), + ( + "program_items", + wagtail.core.blocks.ListBlock( + wagtail.core.blocks.StructBlock( + [ + ( + "title", + wagtail.core.blocks.CharBlock( + label="Název", required=True + ), + ), + ( + "completion_percentage", + wagtail.core.blocks.IntegerBlock( + label="Procento dokončení", + required=True, + ), + ), + ( + "issue_link", + wagtail.core.blocks.URLBlock( + label="Odkaz na Redmine issue", + required=False, + ), + ), + ] + ), + label="Seznam bodů", + ), + ), + ] + ), + ), + ( + "redmine_program_block", + wagtail.core.blocks.StructBlock( + [ + ( + "headline", + wagtail.core.blocks.CharBlock( + label="Titulek bloku", required=True + ), + ), + ( + "perex", + wagtail.core.blocks.TextBlock( + label="Krátký text pod nadpisem", required=True + ), + ), + ( + "person", + wagtail.core.blocks.PageChooserBlock( + label="Garant", + page_type=["district.DistrictPersonPage"], + ), + ), + ( + "redmine_issue", + wagtail.core.blocks.IntegerBlock( + label="Číslo Redmine issue", required=True + ), + ), + ( + "completion_percentage", + wagtail.core.blocks.IntegerBlock( + help_text="Hodnota se automaticky načte s Redmine", + label="Procento dokončení - bude doplněno automaticky", + required=False, + ), + ), + ( + "program_items", + wagtail.core.blocks.ListBlock( + wagtail.core.blocks.StructBlock( + [ + ( + "title", + wagtail.core.blocks.CharBlock( + label="Název", required=True + ), + ), + ( + "completion_percentage", + wagtail.core.blocks.IntegerBlock( + label="Procento dokončení", + required=True, + ), + ), + ( + "issue_link", + wagtail.core.blocks.URLBlock( + label="Odkaz na Redmine issue", + required=False, + ), + ), + ] + ), + help_text="Hodnota se automaticky načte s Redmine", + label="Seznam bodů - bude doplněno automaticky", + required=False, + ), + ), + ] + ), + ), + ], + blank=True, + verbose_name="obsah stránky", + ), + ), + ] diff --git a/district/templates/district/blocks/program_block.html b/district/templates/district/blocks/program_block.html index caf0108a..ecffe0b8 100644 --- a/district/templates/district/blocks/program_block.html +++ b/district/templates/district/blocks/program_block.html @@ -18,10 +18,17 @@ <div class="content-block"> <div class="space-y-4 mt-8"> <div> - <a href="https://redmine.pirati.cz/issues/28177" class="contact-line icon-link content-block--nostyle"> - <i class="ico--info"></i> - <span>Plnění programu: {{ self.completion_percentage | default_if_none:'' }}%</span> - </a> + {% if self.redmine_issue %} + <a href="https://redmine.pirati.cz/issues/{{ self.redmine_issue }}" class="contact-line icon-link content-block--nostyle"> + <i class="ico--info"></i> + <span>Plnění programu: {{ self.completion_percentage | default_if_none:'' }}%</span> + </a> + {% else %} + <span class="contact-line content-block--nostyle"> + <i class="ico--info"></i> + <span>Plnění programu: {{ self.completion_percentage | default_if_none:'' }}%</span> + </span> + {% endif %} </div> </div> </div> @@ -42,9 +49,15 @@ {% for item in self.program_items %} <tr> <td> - <a href="{{ item.issue_link }}" target="_blank"> - {{ item.title | default_if_none:'' }} - </a> + {% if item.issue_link %} + <a href="{{ item.issue_link }}" target="_blank"> + {{ item.title | default_if_none:'' }} + </a> + {% else %} + <span> + {{ item.title | default_if_none:'' }} + </span> + {% endif %} </td> <td>{{ item.completion_percentage | default_if_none:'' }} %</td> </tr> diff --git a/redmine_utils/functions.py b/redmine_utils/functions.py index f4e12ec8..b7e2ae62 100644 --- a/redmine_utils/functions.py +++ b/redmine_utils/functions.py @@ -40,6 +40,9 @@ def fill_program_items_from_redmine(program_block_value: dict, issue_id: int): { "completion_percentage": issue.get("done_ratio", None), "title": issue.get("subject", ""), + "issue_link": "https://redmine.pirati.cz/issues/{}".format( + issue.get("id", "") + ), } ) program_block_value["program_items"].append(sv) diff --git a/region/migrations/0031_alter_regionprogrampage_content.py b/region/migrations/0031_alter_regionprogrampage_content.py new file mode 100644 index 00000000..702e1582 --- /dev/null +++ b/region/migrations/0031_alter_regionprogrampage_content.py @@ -0,0 +1,159 @@ +# Generated by Django 4.0.3 on 2022-04-21 09:25 + +import wagtail.core.blocks +import wagtail.core.fields +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("region", "0030_alter_regionarticlepage_content_and_more"), + ] + + operations = [ + migrations.AlterField( + model_name="regionprogrampage", + name="content", + field=wagtail.core.fields.StreamField( + [ + ( + "static_program_block", + wagtail.core.blocks.StructBlock( + [ + ( + "headline", + wagtail.core.blocks.CharBlock( + label="Titulek bloku", required=True + ), + ), + ( + "perex", + wagtail.core.blocks.TextBlock( + label="Krátký text pod nadpisem", required=True + ), + ), + ( + "person", + wagtail.core.blocks.PageChooserBlock( + label="Garant", + page_type=["region.RegionPersonPage"], + ), + ), + ( + "completion_percentage", + wagtail.core.blocks.IntegerBlock( + label="Procento dokončení", required=True + ), + ), + ( + "program_items", + wagtail.core.blocks.ListBlock( + wagtail.core.blocks.StructBlock( + [ + ( + "title", + wagtail.core.blocks.CharBlock( + label="Název", required=True + ), + ), + ( + "completion_percentage", + wagtail.core.blocks.IntegerBlock( + label="Procento dokončení", + required=True, + ), + ), + ( + "issue_link", + wagtail.core.blocks.URLBlock( + label="Odkaz na Redmine issue", + required=False, + ), + ), + ] + ), + label="Seznam bodů", + ), + ), + ] + ), + ), + ( + "redmine_program_block", + wagtail.core.blocks.StructBlock( + [ + ( + "headline", + wagtail.core.blocks.CharBlock( + label="Titulek bloku", required=True + ), + ), + ( + "perex", + wagtail.core.blocks.TextBlock( + label="Krátký text pod nadpisem", required=True + ), + ), + ( + "person", + wagtail.core.blocks.PageChooserBlock( + label="Garant", + page_type=["region.RegionPersonPage"], + ), + ), + ( + "redmine_issue", + wagtail.core.blocks.IntegerBlock( + label="Číslo Redmine issue", required=True + ), + ), + ( + "completion_percentage", + wagtail.core.blocks.IntegerBlock( + help_text="Hodnota se automaticky načte s Redmine", + label="Procento dokončení - bude doplněno automaticky", + required=False, + ), + ), + ( + "program_items", + wagtail.core.blocks.ListBlock( + wagtail.core.blocks.StructBlock( + [ + ( + "title", + wagtail.core.blocks.CharBlock( + label="Název", required=True + ), + ), + ( + "completion_percentage", + wagtail.core.blocks.IntegerBlock( + label="Procento dokončení", + required=True, + ), + ), + ( + "issue_link", + wagtail.core.blocks.URLBlock( + label="Odkaz na Redmine issue", + required=False, + ), + ), + ] + ), + help_text="Hodnota se automaticky načte s Redmine", + label="Seznam bodů - bude doplněno automaticky", + required=False, + ), + ), + ] + ), + ), + ], + blank=True, + verbose_name="obsah stránky", + ), + ), + ] diff --git a/shared/blocks.py b/shared/blocks.py index ecb3382a..4a3ba423 100644 --- a/shared/blocks.py +++ b/shared/blocks.py @@ -63,6 +63,7 @@ class ProgramItemBlock(blocks.StructBlock): completion_percentage = blocks.IntegerBlock( label="Procento dokončení", required=True ) + issue_link = blocks.URLBlock(label="Odkaz na Redmine issue", required=False) class YouTubeVideoBlock(blocks.StructBlock): -- GitLab