Skip to content

Commit

Permalink
WIP attachments list in account settings
Browse files Browse the repository at this point in the history
  • Loading branch information
rafalp committed Jan 23, 2025
1 parent 64fbf03 commit b5d33c4
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 73 deletions.
1 change: 1 addition & 0 deletions frontend/src/style/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
@import "misago/auth-pages.less";
@import "misago/message-pages.less";
@import "misago/threads-lists.less";
@import "misago/attachment-list.less";
@import "misago/attachment-details.less";
@import "misago/notifications-list.less";
@import "misago/notifications-dropdown.less";
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/style/misago/attachment-list.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.attachment-list-item {
background-color: #f00;
}
58 changes: 55 additions & 3 deletions misago/account/views/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
from ...core.mail import build_mail
from ...pagination.cursor import EmptyPageError, paginate_queryset
from ...pagination.redirect import redirect_to_last_page
from ...permissions.attachments import check_delete_attachment_permission
from ...permissions.checkutils import check_permissions
from ...permissions.posts import check_see_post_permission
from ...threads.privatethreads import prefetch_private_thread_member_ids
from ...users.datadownloads import (
request_user_data_download,
user_has_data_download_request,
Expand Down Expand Up @@ -481,11 +485,59 @@ def get_storage_usage(self, request: HttpRequest) -> dict:
"unused_pc": unused_pc,
}

def get_attachments(self, request: HttpRequest):
queryset = Attachment.objects.filter(uploader=request.user).select_related(
def get_attachments(self, request: HttpRequest) -> dict:
queryset = Attachment.objects.filter(uploader=request.user).prefetch_related(
"category", "thread", "post"
)
return paginate_queryset(request, queryset, 20, "-id")

result = paginate_queryset(request, queryset, 20, "-id")
prefetch_private_thread_member_ids(
[attachment.thread for attachment in result.items if attachment.thread]
)

show_post_column = False
show_delete_column = False

items: list[dict] = []
for attachment in result.items:
attachment.uploader = request.user

with check_permissions() as can_see_post:
check_see_post_permission(
request.user_permissions,
attachment.category,
attachment.thread,
attachment.post,
)

with check_permissions() as can_delete:
check_delete_attachment_permission(
request.user_permissions,
attachment.category,
attachment.thread,
attachment.post,
attachment,
)

if can_see_post:
show_post_column = True
if can_delete:
show_delete_column = True

items.append(
{
"attachment": attachment,
"show_post": can_see_post,
"show_delete": can_delete,
}
)

return {
"paginator": result,
"items": result.items,
"show_post_column": show_post_column,
"show_delete_column": show_delete_column,
}


class AccountDownloadDataView(AccountSettingsView):
Expand Down
2 changes: 1 addition & 1 deletion misago/static/misago/css/misago.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion misago/static/misago/css/misago.css.map

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ <h3 class="panel-title">
{% include "misago/account/settings/attachments_usage.html" %}
<ul class="list-group">
{% for attachment in attachments.items %}
<li class="list-group-item">{{ attachment.name }}</li>
<li class="list-group-item attachment-list-item">{{ attachment.name }}</li>
{% endfor %}
</ul>
</div>
Expand Down
136 changes: 69 additions & 67 deletions misago/templates/misago/account/settings/attachments_toolbar.html
Original file line number Diff line number Diff line change
@@ -1,70 +1,72 @@
{% load i18n %}
{% if attachments.has_previous or attachments.has_next %}
<nav class="toolbar">
<div class="toolbar-section">
<div class="toolbar-item">
<div
class="misago-pagination"
hx-push-url="true"
hx-target="#misago-htmx-root"
hx-swap="outerHTML show:#misago-page-scroll-target:top"
>
{% if attachments.has_previous %}
<a
href="{% url 'misago:account-attachments' %}"
class="btn btn-default btn-outline btn-icon"
title="{% trans 'Go to first page' context 'attachments list paginator' %}"
hx-get="{% url 'misago:account-attachments' %}"
>
<span class="material-icon">first_page</span>
</a>
<a
href="{% url 'misago:account-attachments' %}{{ attachments.previous_cursor_query }}"
class="btn btn-default btn-outline btn-icon"
title="{% trans 'Go to previous page' context 'username history paginator' %}"
hx-get="{% url 'misago:account-attachments' %}{{ attachments.previous_cursor_query }}"
>
<span class="material-icon">chevron_left</span>
</a>
{% else %}
<button
class="btn btn-default btn-outline btn-icon"
title="{% trans 'Go to first page' context 'username history paginator' %}"
type="button"
disabled
>
<span class="material-icon">first_page</span>
</button>
<button
class="btn btn-default btn-outline btn-icon"
title="{% trans 'Go to previous page' context 'username history paginator' %}"
type="button"
disabled
>
<span class="material-icon">chevron_left</span>
</button>
{% endif %}
{% if attachments.has_next %}
<a
href="{% url 'misago:account-attachments' %}{{ attachments.next_cursor_query }}"
class="btn btn-default btn-outline btn-icon"
title="{% trans 'Go to next page' context 'username history paginator' %}"
hx-get="{% url 'misago:account-attachments' %}{{ attachments.next_cursor_query }}"
>
<span class="material-icon">chevron_right</span>
</a>
{% else %}
<button
class="btn btn-default btn-outline btn-icon"
title="{% trans 'Go to next page' context 'username history paginator' %}"
type="button"
disabled
>
<span class="material-icon">chevron_right</span>
</button>
{% endif %}
{% with paginator=attachments.paginator %}
{% if paginator.has_previous or paginator.has_next %}
<nav class="toolbar">
<div class="toolbar-section">
<div class="toolbar-item">
<div
class="misago-pagination"
hx-push-url="true"
hx-target="#misago-htmx-root"
hx-swap="outerHTML show:#misago-page-scroll-target:top"
>
{% if paginator.has_previous %}
<a
href="{% url 'misago:account-attachments' %}"
class="btn btn-default btn-outline btn-icon"
title="{% trans 'Go to first page' context 'attachments list paginator' %}"
hx-get="{% url 'misago:account-attachments' %}"
>
<span class="material-icon">first_page</span>
</a>
<a
href="{% url 'misago:account-attachments' %}{{ paginator.previous_cursor_query }}"
class="btn btn-default btn-outline btn-icon"
title="{% trans 'Go to previous page' context 'username history paginator' %}"
hx-get="{% url 'misago:account-attachments' %}{{ paginator.previous_cursor_query }}"
>
<span class="material-icon">chevron_left</span>
</a>
{% else %}
<button
class="btn btn-default btn-outline btn-icon"
title="{% trans 'Go to first page' context 'username history paginator' %}"
type="button"
disabled
>
<span class="material-icon">first_page</span>
</button>
<button
class="btn btn-default btn-outline btn-icon"
title="{% trans 'Go to previous page' context 'username history paginator' %}"
type="button"
disabled
>
<span class="material-icon">chevron_left</span>
</button>
{% endif %}
{% if paginator.has_next %}
<a
href="{% url 'misago:account-attachments' %}{{ paginator.next_cursor_query }}"
class="btn btn-default btn-outline btn-icon"
title="{% trans 'Go to next page' context 'username history paginator' %}"
hx-get="{% url 'misago:account-attachments' %}{{ paginator.next_cursor_query }}"
>
<span class="material-icon">chevron_right</span>
</a>
{% else %}
<button
class="btn btn-default btn-outline btn-icon"
title="{% trans 'Go to next page' context 'username history paginator' %}"
type="button"
disabled
>
<span class="material-icon">chevron_right</span>
</button>
{% endif %}
</div>
</div>
</div>
</div>
</nav>
{% endif %}
</nav>
{% endif %}
{% endwith %}

0 comments on commit b5d33c4

Please sign in to comment.