Skip to content
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

add delivery-type, year, quarter filter to admin report #401

Open
wants to merge 4 commits into
base: sr/currency
Choose a base branch
from

Conversation

sravfeyn
Copy link
Member

@sravfeyn sravfeyn commented Sep 22, 2024

  • Refactor to htmx based reports
  • Add filters
Screenshot 2024-09-22 at 8 10 13 PM

Copy link
Collaborator

@calellowitz calellowitz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General idea looks good, left a few questions. Nothing is probably blocking for now, but curious about a few choices


{% block javascript %}
{{ block.super }}
<!-- This is required for select2 'user' field-->
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the select2 user field mentioned? i don't see a reference to select2 or users elsewhere in this PR

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I let this be since it's needed in another PR #349


app_name = "reports"

urlpatterns = [
path("delivery_stats", views.delivery_stats_report, name="delivery_stats_report"),
# path("delivery_stats", views.delivery_stats_report, name="delivery_stats_report"),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this left commented in the code for a specific reason? Seems like we can delete it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really, will remove it

table_data.append(data)
table = AdminReportTable(table_data)
return render(request, "reports/admin.html", context={"table": table})
class SuperUserRequiredMixin(LoginRequiredMixin, UserPassesTestMixin):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this will be useful to any view that needs to enforce superusers, and isn't report specific, it would be great to pull this out of this view file and into a util/helper one.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

@@ -33,7 +35,12 @@ def _get_quarters_since_start():
return quarters


def _get_table_data_for_quarter(quarter):
def _get_table_data_for_quarter(quarter, delivery_type):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to your PR except that you are already touching this code, but it would be great if we could cache this fairly aggressively, since its so expensive, although we may actually want to do that one level up and cache the entire loop over the quarters if we can. If not caching each quarter is probably still great

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

Comment on lines +126 to +127
year = django_filters.ChoiceFilter(method="filter_by_ignore")
quarter = django_filters.ChoiceFilter(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the intent of these filters? It seems unlikely to be useful (especially the quarter once since if you filter to year, you have already filtered down to only four rows), but I might be missing something you had in mind

@@ -30,6 +30,9 @@ django-cors-headers
# DRF-spectacular for api documentation
drf-spectacular
django-tables2
django-filter
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the changes in here won't take effect until you compile requirements inv requirements

filterset_class = DeliveryReportFilters

def get_template_names(self):
if self.request.htmx:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rather than add this new dependency and middleware, how would you feel about having the table just render asynchronously through a separate view call, like our other tables. That has the added benefit of not blocking the page render in the browser, which for one this slow, can be a much nicer experience, and hopefully requires less template duplication

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

render asynchronously through a separate view call, like our other tables.

May be I am not following this, this is an async call. The table gets re-rendered when the filters are selected/modified.

I think the advantage of this is that we just need to define a single view that has all the logic in it. I agree this particular view is slow, but may be the priority to should be to improve that?

@@ -0,0 +1,87 @@
{% extends "django_tables2/bootstrap5.html" %}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to reuse (or inherit) from the base report table we already defined?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This template is just the table part, the base report table template includes the filters and other nav-sections etc..

{% endif %}
{% endblock table.thead %}

{% block pagination %}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have pagination in this report? I was unable to find it in the view.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we don't have pagination for this report, but this template is basically the common template that can be used everywhere. Taken from #349 (if this were merged, then this would have just been a DRY reference)

return self.request.user.is_superuser


class DeliveryReportFilters(django_filters.FilterSet):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like we are using django-filters in a pretty nontraditional way, based on all the overrides (filter_by_none, NonModelFilterView, etc), what functionality are we getting from it?

Copy link
Member Author

@sravfeyn sravfeyn Oct 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a bit of a non-traditional filter (in that it's not based on model fields), you can how useful it is in the Events PR #349

Additionally, even in this case, we don't have to worry about creating form/input and extracting it etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants