Welcome to Django Report Scaffold’s documentation!¶
Contents:
Quickstart Guide¶
Installation¶
pip install django-report-scaffold
- Add
scaffold_report
toINSTALLED_APPS
- Add
(r'^reports/', include('scaffold_report.urls')),
tourls.py
. I choose to name it “reports” but make it whatever you want. - It’s installed but won’t do anything yet!
Creating your first report¶
Create a file called scaffold_reports.py
in your projects app folder. Here is a sample report to get started.:
from foo.models import Order
from scaffold_report.report import ScaffoldReport, scaffold_reports
class FooReport(ScaffoldReport):
name = "Reports"
model = Order
filters = (
)
scaffold_reports.register('foo_report', FooReport)
Now go to /reports/foo_report/
to view it in a browser.
Setting up templates¶
Next you want to customize your templates to make the reports feel at home.
The default template to use is admin_base.html
which could be a base template for your project.
You could also rename it.
Here is a example admin_base.html:
{% extends 'base.html' %}
{% load static %}
{% block scripts %}
{% include "scaffold_report/includes/header.html" %}
{% endblock %}
{% block content %}
{% endblock %}
base.html is a base template for the Foo project. This can be anything you want. In my base.html I have blocks called scripts and content. The content block is needed actually!
This method is easy but to customize further you could copy and change any of the scaffold report templates.
API Reference¶
ScaffoldReport¶
-
class
scaffold_report.report.
ScaffoldReport
[source]¶ Bases:
object
Base class for any actual scaffold reports A scaffold report is named after UI effects for moving various filters and previews into the report building screen. All reports require customized options set by the programmer.
-
name
= ''¶ Unique name of report.
-
name_verbose
= None¶ Verbose name of report to show users.
-
model
= None¶ Base model for this report’s queryset.
-
preview_fields
= ['id']¶ Array of field names to show on previews.
-
num_preview
= 3¶ How many objects in the queryset should be show in preview.
-
filters
= []¶ Filters that can be applied to the report.
Buttons will show in sidebar area. These can be premade reports and give the user more options than just clicking submit
-
permissions_required
= []¶ Report is only viewable to those with these permissions. Will default to the model’s change permission if not set
-
appy_template
= None¶ A statically defined template. Could override get_template instead.
-
get_appy_template
()[source]¶ Return a appy template This could be hard coded or perhaps get report_context from a filter.
-
get_name
¶ Return name_verbose if it has been set; otherwise return name. Replaces all spaces with underscores.
-
-
class
scaffold_report.report.
ReportButton
[source]¶ Bases:
object
An alternative way to submit a report. Could be used for one off reports that behave differently.
-
name
= ''¶ For button name attr
-
value
= ''¶ For button value attr
-
accepts_queryset
= True¶ When true the queryset is processed first (so filters will run) and passed to get_report
-
get_name
¶ Return name_verbose if it has been set; otherwise return name. Replaces all spaces with underscores.
-
Filters¶
-
class
scaffold_report.filters.
Filter
(**kwargs)[source]¶ Bases:
object
A customized filter for querysets
-
name
= None¶ Unique name of filter
-
verbose_name
= None¶ Human readable name of filter
-
template_name
= None¶ If set the filter will render using this django template If not set the filter will render using scaffold_report/filter.html
-
fields
= None¶ Define fields here that will be appended together to make a generic form
-
form_class
= None¶ Optional form class to use.
-
form
= None¶ Optional form. If not set, an instance of the form_class will be used
-
raw_form_data
= None¶ uncleaned_form data from the post
-
add_fields
= []¶ Add these fields to the preview and spreadsheet reports
-
default
= False¶ Show this filter as on by default
-
can_remove
= True¶ User is able to delete this filter. Should be used with default = True.
-
can_add
= True¶ User is able to add this filter
-
queryset_filter
(queryset, report_context=None, form=None)[source]¶ Allow custom handeling of queryset Must return the queryset.
-
-
class
scaffold_report.filters.
DecimalCompareFilter
(**kwargs)[source]¶ Bases:
scaffold_report.filters.Filter
X greater, less, etc than decimal field
-
class
scaffold_report.filters.
ModelChoiceFilter
(**kwargs)[source]¶ Bases:
scaffold_report.filters.Filter
Select object from a queryset
-
compare_field_string
= None¶ String used in the Django orm filter function. See queryset_filter()
-
model
= None¶ Model used for queryset. Set this for any object of such model.
-
queryset
= None¶ queryset that populates the widget. Model is not needed if this is set.
-
-
class
scaffold_report.filters.
ModelMultipleChoiceFilter
(**kwargs)[source]¶ Bases:
scaffold_report.filters.ModelChoiceFilter
Select multiple objects from a queryset
-
class
scaffold_report.filters.
IntCompareFilter
(**kwargs)[source]¶ Bases:
scaffold_report.filters.DecimalCompareFilter
x greater, less, etc than int field
What is Django Report Scaffold?¶
You have an app and it probably needs reports. Scaffold reports will help you streamline the process and present users with a consistent interface. Think of it like Django admin for reports. It features:
- Stock report filtering
- Highly extentable - Keep with stock filters or make your own.
- Export to xlsx, admin change list page, django-report-builder, or appy POD templates. Extend and add your own exports!
- Ready to go user interface allows users to quickly filter reports.
- Filter system encourages you to keep your report logic organized. Filters can change a queryset or change report contextthat might affect other filters.