danirus / django-comments-xtd

A pluggable Django comments application with thread support, follow-up notifications, mail confirmation, like/dislike flags, moderation, a ReactJS plugin and Bootstrap 5.3.
https://django-comments-xtd.readthedocs.io
BSD 2-Clause "Simplified" License
595 stars 158 forks source link

add ordering filter and submit_date_timestamp to the API #364

Closed PetrDlouhy closed 6 months ago

PetrDlouhy commented 2 years ago

I added OrderingFilter to the comments API to enable sorting by particular fields. I also added submit_date_timestamp to be able to sort by date and it could be also helpful to determine the exact time in some applications (as submit_date is dependend on server timezone).

PetrDlouhy commented 6 months ago

@danirus This PR is very small and simple. Are there any obstacles that are preventing it from being merged?

danirus commented 6 months ago

Hi @PetrDlouhy, sorry for my late reply since you submitted it. I would like to know what is the use case you have in mind to add that extra field. Why having submit_date is not enough?

PetrDlouhy commented 6 months ago

I am feeding that information to dayjs and the problem is, that submit_date is more human readable format and doesn't contain some information - especially the timezone.

danirus commented 6 months ago

You could modify your DATETIME_FORMAT setting to have in the submit_date field the content you need.

danirus commented 6 months ago

You could modify your DATETIME_FORMAT setting to have in the submit_date field the content you need.

There is an issue in the method get_submit_date of ReadCommentSerializer. It has to read the value of settings.DATETIME_FORMAT, instead of passing the string DATETIME_FORMAT. When resolved you could define the format you need in your settings module.

danirus commented 6 months ago

It is fixed in master. It will be fixed in 2.9.12 later today. The idea is to use settings.DATETIME_FORMAT to adapt the submit_date to your project.

PetrDlouhy commented 6 months ago

Does that mean, that I have to change DATETIME_FORMAT in my entire project? That sounds like hundred unexpected consequences to me. And I also want to keep DATETIME_FORMAT in human readable format in all other places except API, where should always be computer readable format in my opinion.

Or is there a way to change DATETIME_FORMAT just for django-comments-xtd?

danirus commented 6 months ago

It could work that way too. A new setting COMMENTS_XTD_API_DATETIME_FORMAT would default to DATETIME_FORMAT. If we want the API to use a specific datetime format for the submit_date in the ReadCommentSerializer, then we can provide COMMENTS_XTD_API_DATETIME_FORMAT.