|
25 | 25 | from .types import DropDownChoice
|
26 | 26 |
|
27 | 27 | if TYPE_CHECKING:
|
28 |
| - from openarchiefbeheer.destruction.models import DestructionList |
| 28 | + from openarchiefbeheer.destruction.models import ( |
| 29 | + DestructionList, |
| 30 | + DestructionListReview, |
| 31 | + ) |
29 | 32 |
|
30 | 33 |
|
31 | 34 | def pagination_helper(
|
@@ -112,25 +115,44 @@ def retrieve_zaaktypen_choices() -> list[DropDownChoice]:
|
112 | 115 | return sorted(zaaktypen_choices, key=lambda zaaktype: zaaktype["label"])
|
113 | 116 |
|
114 | 117 |
|
115 |
| -def get_zaaktypen_choices_from_list( |
116 |
| - destruction_list: "DestructionList", |
117 |
| -) -> list[DropDownChoice]: |
118 |
| - items_qs = destruction_list.items.filter(status=ListItemStatus.suggested).distinct( |
119 |
| - "zaak__zaaktype" |
120 |
| - ) |
121 |
| - zaaktypen_to_include = items_qs.values_list( |
122 |
| - "zaak__zaaktype", "zaak___expand__zaaktype__identificatie" |
123 |
| - ) |
| 118 | +def _get_zaaktype_choices(zaaktypen_to_include: dict[list]) -> list[DropDownChoice]: |
| 119 | + """Return formatted zaaktype choices |
124 | 120 |
|
| 121 | + Takes a dictionary where the key is the identificatie of a zaaktype and |
| 122 | + the value is a list of all the URLs for the different versions of that zaaktype.""" |
125 | 123 | zaaktypen = defaultdict(list)
|
126 | 124 | for zaaktype_url, zaaktype_identificatie in zaaktypen_to_include:
|
127 | 125 | zaaktypen[zaaktype_identificatie].append(zaaktype_url)
|
| 126 | + |
128 | 127 | zaaktypen_choices = [
|
129 | 128 | {"label": key, "value": ",".join(value)} for key, value in zaaktypen.items()
|
130 | 129 | ]
|
131 | 130 | return sorted(zaaktypen_choices, key=lambda zaaktype: zaaktype["label"])
|
132 | 131 |
|
133 | 132 |
|
| 133 | +def get_zaaktypen_choices_from_list( |
| 134 | + destruction_list: "DestructionList", |
| 135 | +) -> list[DropDownChoice]: |
| 136 | + zaaktypen_to_include = ( |
| 137 | + destruction_list.items.filter(status=ListItemStatus.suggested) |
| 138 | + .distinct("zaak__zaaktype") |
| 139 | + .values_list("zaak__zaaktype", "zaak___expand__zaaktype__identificatie") |
| 140 | + ) |
| 141 | + return _get_zaaktype_choices(zaaktypen_to_include) |
| 142 | + |
| 143 | + |
| 144 | +def get_zaaktypen_choices_from_review( |
| 145 | + review: "DestructionListReview", |
| 146 | +) -> list[DropDownChoice]: |
| 147 | + zaaktypen_to_include = review.item_reviews.distinct( |
| 148 | + "destruction_list_item__zaak__zaaktype" |
| 149 | + ).values_list( |
| 150 | + "destruction_list_item__zaak__zaaktype", |
| 151 | + "destruction_list_item__zaak___expand__zaaktype__identificatie", |
| 152 | + ) |
| 153 | + return _get_zaaktype_choices(zaaktypen_to_include) |
| 154 | + |
| 155 | + |
134 | 156 | def format_selectielijstklasse_choice(resultaat: Resultaat) -> DropDownChoice:
|
135 | 157 | description = f"{resultaat.get('volledig_nummer', resultaat['nummer'])} - {resultaat['naam']} - {resultaat['waardering']}"
|
136 | 158 | if resultaat.get("bewaartermijn"):
|
|
0 commit comments