- changed status to open
InboxView(as_view(option='UNREAD_MESSAGES') to get only unread messages
Following another ticket in my single-page application that header would like to send a query to get all unread messages. The template can filter out read ones but it would be much more efficient if the backend only sends unread messages.
It appears that option
would be useful for this purpose but I only see option=OPTION_MESSAGE
which returns all messages. I am wondering if something like
InboxView.as_view(template_name='postman/header_list.html', option='UNREAD_MESSAGES')
is already available or can be added. Thanks,
Comments (12)
-
repo owner -
Yes, that would be perfect. Since we are at it, the inbox could also accept
?page
for support of pagination. -
repo owner The implementation is now committed in repository.
Could you have a try before a public release? -
Thanks! I will test the new features tonight.
What is your opinion about pagination? I am tempted to create a new Folder view just to add pagination to the message list. It looks like all that is needed is something like the following in
FolderMixin
:paginator = Paginator(msgs, self.paginate_by) page_number = request.GET.get('page') context.update( {'page_obj': paginator.get_page(page_number) ... })
-
This option works. However, I am using a separate template to get a list of new messages from the header and have to discard extra messages if there are more than 10 new messages (otherwise the list will get long and ugly). It would be helpful for this URL to accept pagination (
page=1
to get only the first page) and/or a limit (?limit=10
).
-
repo owner About the pagination, my suggestion is that it already can be done with the use of this app: https://pypi.org/project/dj-pagination/
You can find a working skeleton of its usage in postman\templates\postman\base_folder.html. It uses a middleware to do all the stuff.
Have a look also at https://bitbucket.org/psam/django-postman/wiki/tags-filters
-
Thanks for pointing me to that app, which I will have a look. For my simple application (limiting to first ten unread messages in a pop up window from the header), I can already filter out unneeded messages by controlling the for loop in my template, but with a paginator and queryset, supposedly only the first 10 would be retrieved from the database which could be more performant.
-
Had a look, unfortunately we cannot use
dj-paginator
because we are using the jinja2 template engine. Since most of our views supports pagination and we already have a nice template for paginator, I suppose it is easier for us to forkdjango-postman
than messing with the templates. -
repo owner What about the idea of:
<a href="{% url 'postman:inbox' %}?unread&limit=10">
Anyway you don’t need a real navigation based on multiple pages.
-
In our jinja2 template for the header notification message list we have
{% for message in pm_messages[:10] %}
which works fine with the only caveat that all messages will be retrieved from the database. An option such as
limit=10
would be helpful if it can address the problem at the queryset level (not as an after effect after all messages are retrieved).We have also extended the
InboxView
with pagination for our main message interface since we cannot usedj-pagination
. There would be no need for optionlimit
if pagination support is added since?limit=10
is equivalent to?page=1
. Personally I thinkpage
is more common for. a Django list view, more general thanlimit
, and the amount of work is about the same. -
repo owner The implementation of
limit
is now committed in repository. -
repo owner - changed status to resolved
- Log in to comment
The current
option
concept is not designed to be passed as an argument toas_view()
.I think more about an optional query string argument, something like:
<a href="{% url 'postman:inbox' %}?unread">
Would it be OK for your need?