-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/all attachment kinds #753
Merged
Merged
Changes from 22 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
4cca9c1
feat: create all InformationLetter kinds
EdoStorm96 9183175
feat: add correct informationletter in checker
EdoStorm96 29a9d1c
feat: check if Study has AV registration
EdoStorm96 d3717ce
fix: bug, where legal basis can be 0 ... woopsie
EdoStorm96 6654c4a
feature: add all possible kinds
EdoStorm96 ba2ddfd
feature: add all slots, through checkers
EdoStorm96 4b27c6d
feat: implement navigation buttons for ProposalsAttachmentsView
EdoStorm96 fc848fc
feature: a lotta translations
EdoStorm96 0f52a65
Merge branch 'feature/attachments-4' into feature/all-attachment-kinds
EdoStorm96 489bb64
style: black sabbath
EdoStorm96 8562556
Merge remote-tracking branch 'origin/feature/attachments-4' into feat…
miggol 91d56d0
fix: Make get_kind_from_str resilient to unknown kinds
miggol 004491a
feat: Rename OtherProposalAttachment
miggol 9a94224
feat: Optionality groups for attachment slots
miggol 465d10f
feat: Render help texts next to slots
miggol 661b418
style: Black and djlint
miggol a6b3dc5
Merge pull request #755 from DH-IT-Portal-Development/feature/all_kin…
EdoStorm96 a95755e
fix: logic of slots
EdoStorm96 4920ba3
feature: implement match + match_and_set
EdoStorm96 db9ea29
feat: has_adults() for Study
EdoStorm96 4028328
feat: base ConsentForm on whether Study.has_adults()
EdoStorm96 cbb0059
style: black betty
EdoStorm96 2314349
fix: Give match_and_set() a return value
miggol 2d1e3fc
fix: potential TypeError: addition of list and set
miggol 63315bf
Merge branch 'feature/attachments-4' into feature/all-attachment-kinds
miggol 159699c
merge: merge translations and do a style pass
miggol File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{% load i18n %} | ||
|
||
<div class="border-start border-4 p-2 m-0 ps-4 pe-0"> | ||
<h6 class="m-0 p-0"> | ||
{% blocktrans trimmed with count=group.count %} | ||
Een van deze {{ count }} documenten is voldoende | ||
{% endblocktrans %} | ||
</h6> | ||
{% for slot in group.members %} | ||
{% include slot %} | ||
{% endfor %} | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,31 @@ | ||
{% load i18n %} | ||
|
||
<div class="row mt-4 mb-4 p-3 border-3 border-bottom rounded {{classes}} bg-light"> | ||
<div class="col-2 align-middle">{{ slot.desiredness }}</div> | ||
<div class="col-7 align-middle"> | ||
<h5>{{ slot.kind.name }}</h5> | ||
{% if slot.attachment %} | ||
{% include slot.attachment with proposal=proposal %} | ||
{% else %} | ||
{% trans "Nog toe te voegen" %} | ||
{% endif %} | ||
{{ kind.reason }} | ||
<div class="uu-form-row mt-4 mb-4"> | ||
<div class=""> | ||
<div class="row border-3 p-3 border-bottom rounded {{ classes }} bg-light"> | ||
<div class="col-2 align-middle">{{ slot.desiredness }}</div> | ||
<div class="col-7 align-middle"> | ||
<h5>{{ slot.kind.name }}</h5> | ||
{% if slot.attachment %} | ||
{% include slot.attachment with proposal=proposal %} | ||
{% else %} | ||
{% trans "Nog toe te voegen" %} | ||
{% endif %} | ||
{{ kind.reason }} | ||
</div> | ||
<div class="col-3 align-middle text-end flex-end"> | ||
{% if slot.attachment %} | ||
<a class="btn btn-primary" href="{{ slot.get_edit_url }}">{% trans "Wijzig" %}</a> | ||
{% else %} | ||
<a class="btn btn-primary" href="{{ slot.get_attach_url }}">{% trans "Voeg toe" %}</a> | ||
{% endif %} | ||
</div> | ||
</div> | ||
</div> | ||
<div class="col-3 align-middle text-end flex-end"> | ||
{% if slot.attachment %} | ||
<a class="btn btn-primary" href="{{ slot.get_edit_url }}">{% trans "Wijzig" %}</a> | ||
{% else %} | ||
<a class="btn btn-primary" href="{{ slot.get_attach_url }}">{% trans "Voeg toe" %}</a> | ||
{% endif %} | ||
<div class="uu-form-help"> | ||
<details> | ||
<summary class="text-muted">Meer info</summary> | ||
{{ slot.kind.description }} | ||
</details> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,25 +35,36 @@ def __init__( | |
attachment=None, | ||
kind=None, | ||
force_desiredness=None, | ||
optionality_group=None, | ||
): | ||
self.attachment = attachment | ||
self.attached_object = attached_object | ||
self.kind = kind | ||
self.force_desiredness = force_desiredness | ||
self.optionality_group = optionality_group | ||
if self.optionality_group: | ||
self.optionality_group.members.add(self) | ||
|
||
def match(self, exclude): | ||
def match(self, exclude=[]): | ||
""" | ||
Tries to fill this slot with an existing attachment that is not | ||
in the exclusion set of already matched attachments. Returns True | ||
or False depending on if the slot was succesfully matched. | ||
Tries to find a matching attachment for this slot. If it finds one, | ||
it returns the attachment, otherwise it returns False. | ||
""" | ||
for instance in self.get_instances_for_slot(): | ||
if instance not in exclude: | ||
self.attachment = instance | ||
self.kind = get_kind_from_str(instance.kind) | ||
return True | ||
return instance | ||
return False | ||
|
||
def match_and_set(self, exclude): | ||
""" | ||
Uses self.match() to find a matching attachment. If it finds one, it | ||
sets self.attachment and self.kind | ||
""" | ||
matched_attachment = self.match(exclude=exclude) | ||
if matched_attachment: | ||
self.attachment = matched_attachment | ||
self.kind = get_kind_from_str(matched_attachment.kind) | ||
|
||
@property | ||
def classes(self): | ||
if self.required: | ||
|
@@ -141,8 +152,60 @@ def get_edit_url( | |
) | ||
|
||
|
||
class OptionalityGroup(renderable): | ||
|
||
template_name = "attachments/optionality_group.html" | ||
|
||
def __init__(self, members=set()): | ||
self.members = set(members) | ||
|
||
@property | ||
def count( | ||
self, | ||
): | ||
return len(self.members) | ||
|
||
def get_context_data(self, **kwargs): | ||
context = super().get_context_data(**kwargs) | ||
context["group"] = self | ||
return context | ||
|
||
|
||
def merge_groups(slots): | ||
""" | ||
Takes a list of slots and merges slots that belong to the same | ||
optionality group together. This results in a mixed output list | ||
of bare slots and optionality groups. | ||
""" | ||
grouped = [] | ||
for slot in slots: | ||
if not slot.optionality_group: | ||
# No group, so we just append it | ||
grouped.append(slot) | ||
continue | ||
if slot.optionality_group not in grouped: | ||
# We only append the group if it's not already in the | ||
# output list to avoid duplication | ||
grouped.append(slot.optionality_group) | ||
# Final pass to remove single-member groups | ||
out = [] | ||
for item in grouped: | ||
if type(item) is OptionalityGroup: | ||
if item.count < 2: | ||
# If we have fewer than two members, we just append | ||
# the members. Addition allows for the empty list edge | ||
# case to work. | ||
out += item.members | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an error by me. I wrote this before turning members into a |
||
continue | ||
out.append(item) | ||
return out | ||
|
||
|
||
def get_kind_from_str(db_name): | ||
from attachments.kinds import ATTACHMENTS | ||
from attachments.kinds import ATTACHMENTS, OtherAttachment | ||
|
||
kinds = {kind.db_name: kind for kind in ATTACHMENTS} | ||
return kinds[db_name] | ||
try: | ||
return kinds[db_name] | ||
except KeyError: | ||
return OtherAttachment |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Match_and_set should actually still return True, or the instance, or anything truthy if it succeeds. Otherwise
stepper.attachment_slots()
will not work.Although in that specific method we do actually want to modify internal slot state.