Skip to content

Commit

Permalink
modules: add missing get_blueprint_type_display method
Browse files Browse the repository at this point in the history
fixes #2714
  • Loading branch information
goapunk authored and m4ra committed Jun 20, 2024
1 parent 2c41b6b commit 9a0b147
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
10 changes: 10 additions & 0 deletions adhocracy4/modules/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import warnings

from autoslug import AutoSlugField
from django.conf import settings
from django.db import models
from django.urls import reverse
from django.utils import timezone
Expand Down Expand Up @@ -398,6 +399,15 @@ def get_timeline_index(self):
return count
return 0

@cached_property
def get_blueprint_type_display(self) -> str:
"""Returns the textual description of the blueprint type"""
if hasattr(settings, "A4_BLUEPRINT_TYPES"):
blueprints_dict = dict(settings.A4_BLUEPRINT_TYPES)
if self.blueprint_type in blueprints_dict:
return blueprints_dict[self.blueprint_type]
return ""

# Deprecated properties
@cached_property
def first_phase_start_date(self):
Expand Down
3 changes: 3 additions & 0 deletions changelog/_1112.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Fixed

- add missing get_blueprint_type_display to module model
15 changes: 15 additions & 0 deletions tests/modules/test_module_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import pytest
from dateutil.parser import parse
from django.conf import settings
from django.test.utils import override_settings
from freezegun import freeze_time


Expand Down Expand Up @@ -545,3 +547,16 @@ def test_first_phase_start_date(phase, phase_factory):
module=module, start_date=phase.start_date - timedelta(days=1)
)
assert module.first_phase_start_date == first_phase.start_date


@pytest.mark.django_db
def test_blueprint_type_display_empty_unknown_module(phase):
module = phase.module
assert module.get_blueprint_type_display == ""


@override_settings(A4_BLUEPRINT_TYPES=[("QS", "questions")])
@pytest.mark.django_db
def test_blueprint_type_display(module):
module.blueprint_type = settings.A4_BLUEPRINT_TYPES[0][0]
assert module.get_blueprint_type_display == settings.A4_BLUEPRINT_TYPES[0][1]

0 comments on commit 9a0b147

Please sign in to comment.