Skip to content

Commit

Permalink
style
Browse files Browse the repository at this point in the history
  • Loading branch information
miggol committed Jan 7, 2025
1 parent d2f3958 commit 70f7421
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
5 changes: 4 additions & 1 deletion attachments/templates/attachments/attachment_model.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@
<a href="{% url "proposals:download_attachment_original" proposal_pk=proposal.pk attachment_pk=attachment.pk %}">
{{ attachment.upload.original_filename }}</a>
{% if normalized_filename %}
<span class="ms-2o"><br /><a href="{% url "proposals:download_attachment" proposal_pk=proposal.pk attachment_pk=attachment.pk %}">{{ normalized_filename }}</a></span>{% endif %}
<span class="ms-2o">
<br />
<a href="{% url "proposals:download_attachment" proposal_pk=proposal.pk attachment_pk=attachment.pk %}">{{ normalized_filename }}</a></span>
{% endif %}
11 changes: 7 additions & 4 deletions attachments/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,19 +353,22 @@ def generate_filename(slot):

return "-".join(fn_parts) + extension


def enumerate_slots(slots):
"""
Provides an order attribute to all attachment slots whose kind
appears more than once in the provided list.
"""
# Create seperate slot lists per attached_object
per_ao = sort_into_dict(
slots, lambda x: x.attached_object,
slots,
lambda x: x.attached_object,
).values()
# Assign orders to them separately
for ao_slots in per_ao:
assign_orders(ao_slots)


def sort_into_dict(iterable, key_func):
"""
Split iterable into separate lists in a dict whose keys
Expand All @@ -380,11 +383,10 @@ def sort_into_dict(iterable, key_func):
out_dict[key].append(item)
return out_dict


def assign_orders(slots):
# Count total kind occurrences
totals = Counter(
[slot.kind for slot in slots]
)
totals = Counter([slot.kind for slot in slots])
# Create counter to increment gradually
kind_counter = Counter()
# Loop through the slots
Expand All @@ -395,6 +397,7 @@ def assign_orders(slots):
kind_counter[slot.kind] += 1
slot.order = kind_counter[slot.kind]


def get_kind_from_str(db_name):
from attachments.kinds import ATTACHMENTS, OtherAttachment

Expand Down
6 changes: 2 additions & 4 deletions proposals/utils/stepper.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,9 @@ def attachment_slots(

@property
def filled_slots(
self,
self,
):
return [
slot for slot in self.attachment_slots if slot.attachment
]
return [slot for slot in self.attachment_slots if slot.attachment]

def get_context_data(self):
context = super().get_context_data()
Expand Down

0 comments on commit 70f7421

Please sign in to comment.