RamezIssac / django-slick-reporting

The Reporting Engine for Django. Create dashboards and standalone Reports and Charts.
https://django-slick-reporting.com/
BSD 3-Clause "New" or "Revised" License
559 stars 46 forks source link

get_widget_from_url Dashboard shows Reports structure but no data #107

Closed Parthian closed 4 months ago

Parthian commented 4 months ago

Hi Ramez, See https://django-slick-reporting.com/dashboard/ Note that the Reports are there but they don't contain any useful data.

I have the same problem with my own project. I can see the structure of the report - chart and table but all data is 0. I note that the Filters Section at the top with the dates is missing. I wonder if these need dates to work, Or the Filters

    {% get_widget_from_url url_name="employee-demographic" %}

And as suspected a Report that doesn't need dates works perfectly. class EmployeeServiceReport(ListReportView): # ListReportViews don't show Filters?

So ReportViews fail and ListReportViews work when called by get_widget_from_url

Maybe I need some extra_params? As here: https://django-slick-reporting.readthedocs.io/en/latest/topics/widgets.html

RamezIssac commented 4 months ago

Hello Noted.. Wil check and get back to you Thanks

RamezIssac commented 4 months ago

@Parthian I checked and it's about the dates of the recorded data , in the case of the dashboard the data generated is outdated. Can you check if this is not the case with your data ? Edit: Above dashboard link now shows data

Parthian commented 4 months ago

Great that you've got a super demo again. I wonder if your code in the demo has an explicit end_date? I'm using a start_date of 1900 set in get_initial. Perhaps I need to set initial["end_date"] - tried it and it didn't work.

In Summary - my reports work fine standalone and appear on my dashboard but without meaningful data. Except the ListReport which has a nice table of data as expected.

def get_initial(self):
    # set the start_date
    initial = super().get_initial()
    initial["start_date"] = '1900-01-01 00:00:00'
    return initial

but I'm using the settings.py default date as so: SLICK_REPORTING_SETTINGS = {
"DEFAULT_START_DATE_TIME": '2001-01-01 00:00:00', "DEFAULT_END_DATE_TIME": datetime.datetime.today() # today

RamezIssac commented 4 months ago

I still suspect date related / filter thingy...

Let me double check i understand correctly: Same report load data correctly when viewed via a url, and shows empty on widget ?

RamezIssac commented 4 months ago

I still suspect date related / filter thingy...

Let me double check i understand correctly: Same report load data correctly when viewed via a url, and shows empty on widget ?

Parthian commented 4 months ago

Correct, Nice data on urls, pie charts, bar graphs etc. But when shown in dashboard style the Chart appears but with all data at 0. Except the list tables which work fine. So tables don't have dates and they work - charts need dates and don't show any information.

RamezIssac commented 4 months ago

The widget is just a call to the ReportView + any extra parameters set to the widget. Can you identify the request and its parameters made by the widget loader ? Maybe you'll find some extra unintended parameters being sent ...

Parthian commented 4 months ago

Found an oddity. The working standalone reports GET request has query params appended for start_date and end_date. The Dashboard widgets called via {% get_widget_from_url url_name="employee-demographic" %} do not have query params for dates. Odd, as I see nothing in the reports.py or urls.py which adds dates.

Looking at your Dashboard the same happens. No query params but your data appears.

When I look at a normal urls report there are two GET requests. http://127.0.0.1:8000/employee-report/ http://127.0.0.1:8000/employee-report/?start_date=2001-01-01%2000%3A00%3A00&end_date=2024-06-15%2012%3A05%3A04 The latter appears to be created because the Filter section exists.

Maybe my {% get_widget_from_url url_name="employee-demographic" %} should pass start_date and end_date. But your Dashboard doesn't do this.

I've also tried a simple Employee Report with a ReportView (not ListReportView) but without a chart (to rule out a chart problem). But the table is empty. I have a get_queryset and it runs and returns useful data (logged it out to a text file) so stuff is happening but it gets lost at some point.

urls.py - path("employee-report/", EmployeeReport.as_view(), name="employee-report"), The following works fine as a url but fails as the widget. But even when it fails the get_queryset returns the expected data.

class EmployeeReport(ReportView):
    report_model = Employee
    report_title = _("Employee Report")
    date_field = "dob"
    group_by = "location"
    columns = [  'location_name', 'status', 'sign', 'location_code'    ]

    def get_queryset(self): # show only the users own employee record. Superuser can see all.
        qs = super().get_queryset() # Can't pass in request without error about too many parameters.
        logMessage(f'DASHBOARD Reports g_qs Request User = {self.request.user}')
        if self.request.user.is_superuser or self.request.user.groups.filter(name='Level 1 (Admin)').exists():
            logMessage(f'DASHBOARD SUPER Reports g_qs Request User = {qs}')
            return qs # just return everything
        if self.request.user.has_perm('humanresources.view_employee'):
            logMessage(f'DASHBOARD HAS_PERM Reports g_qs Request User = {qs}')
            return qs
        return qs.filter(user=self.request.user) # only show the table results for the actual logged in user.
RamezIssac commented 4 months ago

https://django-slick-reporting.readthedocs.io/en/latest/topics/widgets.html Check Arguments section extra_params and report_form_selector .. Should help make your dashboard more configurable.

Parthian commented 4 months ago

Success. {% get_widget_from_url url_name="employee-demographic" extra_params="start_date=1900-01-01&end_date=2024-06-15" %} Maybe an example in the docs would be good. A strange one. Works for your dashboard presumably without the extra_params. I had a look for report_form_selector but can't find anything in the docs or in the code. Must be related to this : https://django-slick-reporting.readthedocs.io/en/latest/topics/filter_form.html#the-generated-form Could be handy to add the Filters back on for these widgets.

Cheers Stuart