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

Changes to schedule all reports, even for once #3840

Open
wants to merge 47 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
b991534
Changes to schedule all reports
Rieven Nov 14, 2024
7351eda
remove form id
Rieven Nov 14, 2024
1af0832
Merge with main
Rieven Nov 14, 2024
3f5c77d
fix lang
Rieven Nov 14, 2024
e19b52e
Merge branch 'main' into feature/report_creations_are_scheduled
Rieven Nov 15, 2024
7adc85f
Update rocky/reports/templates/partials/export_report_settings.html
Rieven Nov 18, 2024
bb7ecb3
Update rocky/reports/templates/partials/export_report_settings.html
Rieven Nov 18, 2024
59384d6
Merge branch 'main' into feature/report_creations_are_scheduled
Rieven Nov 18, 2024
2507ef8
Merge branch 'main' into feature/report_creations_are_scheduled
Rieven Nov 20, 2024
f479f2f
set None atttrs
Rieven Nov 20, 2024
6bf723c
Merge branch 'main' of github.com:minvws/nl-kat-coordination into fea…
Rieven Nov 27, 2024
35e153d
Merge branch 'main' into feature/report_creations_are_scheduled
Rieven Nov 27, 2024
2761b30
fix lang
Rieven Nov 27, 2024
b53d3da
Merge branch 'feature/report_creations_are_scheduled' of github.com:m…
Rieven Nov 27, 2024
97248d7
Merge branch 'main' into feature/report_creations_are_scheduled
underdarknl Nov 27, 2024
2458f9f
fix for start dat adn time
Rieven Nov 27, 2024
aa4ab9e
Merge branch 'feature/report_creations_are_scheduled' of github.com:m…
Rieven Nov 27, 2024
ebed7c6
fixes for report schedules
Rieven Nov 27, 2024
025c358
fix lang and text
Rieven Nov 27, 2024
4d9a686
set back modal
Rieven Nov 27, 2024
f0a2459
fix datetime already datetime
Rieven Nov 27, 2024
1a28729
Merge branch 'main' into feature/report_creations_are_scheduled
Rieven Nov 27, 2024
25c74a0
Fix empty td
Rieven Nov 27, 2024
f06637b
Merge branch 'feature/report_creations_are_scheduled' of github.com:m…
Rieven Nov 27, 2024
6d143f8
Add additional check if task already run
jpbruinsslot Nov 27, 2024
b727ec6
Fix report types pils
Rieven Nov 28, 2024
4a98305
Merge branch 'fix/mula/schedule-report-once-check' of github.com:minv…
Rieven Nov 28, 2024
37355de
Merge branch 'main' into feature/report_creations_are_scheduled
Rieven Nov 28, 2024
eca64aa
Fix report names
Rieven Nov 28, 2024
4faa16b
Merge branch 'feature/report_creations_are_scheduled' of github.com:m…
Rieven Nov 28, 2024
a14d931
Merge branch 'main' of github.com:minvws/nl-kat-coordination into fea…
Rieven Nov 28, 2024
496414d
fix function input recipe
Rieven Nov 28, 2024
ca7c88a
fix test
Rieven Dec 2, 2024
d9e44e9
Merge branch 'main' into feature/report_creations_are_scheduled
Rieven Dec 2, 2024
79bb537
Merge branch 'main' into feature/report_creations_are_scheduled
Rieven Dec 2, 2024
ac6ad34
set back uuid string
Rieven Dec 2, 2024
3818812
Merge branch 'feature/report_creations_are_scheduled' of github.com:m…
Rieven Dec 2, 2024
4f8bceb
Merge branch 'main' into feature/report_creations_are_scheduled
Rieven Dec 3, 2024
023eb80
Merge branch 'main' into feature/report_creations_are_scheduled
Rieven Dec 3, 2024
3b1cfae
Merge branch 'main' into feature/report_creations_are_scheduled
Rieven Dec 3, 2024
e174b15
Merge branch 'main' into feature/report_creations_are_scheduled
Rieven Dec 3, 2024
bb235aa
Merge branch 'main' of github.com:minvws/nl-kat-coordination into fea…
Rieven Dec 11, 2024
073156b
fix id in worker for string
Rieven Dec 11, 2024
715d467
Merge branch 'main' into feature/report_creations_are_scheduled
Rieven Dec 12, 2024
f8e8e32
Merge branch 'main' of github.com:minvws/nl-kat-coordination into fea…
Rieven Dec 16, 2024
ad8980a
fix td
Rieven Dec 16, 2024
6dd9d1d
Merge branch 'main' into feature/report_creations_are_scheduled
ammar92 Dec 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion octopoes/octopoes/models/ooi/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ class ReportRecipe(OOI):
parent_report_type: str | None = None
report_types: list[str]

cron_expression: str
cron_expression: str | None = None

_natural_key_attrs = ["recipe_id"]
24 changes: 7 additions & 17 deletions rocky/reports/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,13 @@ class ReportScheduleStartDateForm(BaseRockyForm):
label=_("Recurrence"),
required=True,
widget=forms.Select(attrs={"form": "generate_report"}),
choices=[("daily", _("Daily")), ("weekly", _("Weekly")), ("monthly", _("Monthly")), ("yearly", _("Yearly"))],
choices=[
("once", _("No recurrence, just once")),
("daily", _("Daily")),
("weekly", _("Weekly")),
("monthly", _("Monthly")),
("yearly", _("Yearly")),
],
)

def clean(self):
Expand Down Expand Up @@ -121,19 +127,3 @@ class CustomReportScheduleForm(BaseRockyForm):
end_date = forms.DateField(
label=_(""), widget=forms.HiddenInput(), initial=lambda: datetime.now(tz=timezone.utc).date(), required=False
)


class ParentReportNameForm(BaseRockyForm):
parent_report_name = forms.CharField(
label=_("Report name format"), required=False, initial="${report_type} for ${oois_count} objects"
)


class ChildReportNameForm(BaseRockyForm):
child_report_name = forms.CharField(
label=_("Subreports name format"), required=True, initial="${report_type} for ${ooi}"
)


class ReportNameForm(ParentReportNameForm, ChildReportNameForm):
pass
8 changes: 4 additions & 4 deletions rocky/reports/runner/report_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ def run(self, report_task: ReportTask) -> None:
for ooi in data:
ooi_human_readable = Reference.from_str(ooi).human_readable
subreport_name = now.strftime(
Template(recipe.subreport_name_format).safe_substitute(
ooi=ooi_human_readable, report_type=str(report_type.name)
)
Template(
"" if recipe.subreport_name_format is None else recipe.subreport_name_format
).safe_substitute(ooi=ooi_human_readable, report_type=str(report_type.name))
)
subreport_names.append((subreport_name, subreport_name))

Expand All @@ -112,7 +112,7 @@ def run(self, report_task: ReportTask) -> None:
)

if "${ooi}" in parent_report_name and oois_count == 1:
parent_report_name = Template(parent_report_name).safe_substitute(ooi=ooi[0].human_readable)
parent_report_name = Template(parent_report_name).safe_substitute(ooi=ooi_human_readable)

save_report_data(
self.bytes_client,
Expand Down
2 changes: 1 addition & 1 deletion rocky/reports/runner/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def _start_working(
finally:
try:
# The docker runner could have handled this already
if scheduler.get_task_details(p_item.id).status == TaskStatus.RUNNING:
if scheduler.get_task_details(str(p_item.id)).status == TaskStatus.RUNNING:
scheduler.patch_task(p_item.id, status) # Note that implicitly, we have p_item.id == task_id
logger.info("Set status to %s in the scheduler for task[id=%s]", status, p_item.id)
except HTTPError:
Expand Down
73 changes: 39 additions & 34 deletions rocky/reports/templates/partials/export_report_settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,53 +15,58 @@ <h2>{% translate "Report schedule" %}</h2>
or monthly. If you need the report just for a single occasion, select the one-time option.
{% endblocktranslate %}
</p>
<form class="inline" method="post" action="{{ current }}">
<form id="generate_report" class="inline" method="post" action="{{ next }}">
{% csrf_token %}
{% include "forms/report_form_fields.html" %}
{% include "partials/form/fieldset.html" with fields=report_schedule_form_recurrence_choice %}
{% include "partials/form/fieldset.html" with fields=report_schedule_form_start_date fieldset_parent_class="column-2" %}

{% if is_scheduled_report %}
<div>
<h2>{% translate "Report name" %}</h2>
<p>
{% blocktranslate trimmed %}
Please choose a start date, time and recurrence for scheduling your report(s).
If you select a date on the 28th-31st of the month, it will always be scheduled on the last day of the month.
Define a custom name format for your report(s). This format will be applied to all generated
(sub)reports.
{% endblocktranslate %}
</p>
<p>
{% blocktranslate trimmed %}
The date you select will be the reference date for the data set for your report.
Please allow for up to 24 hours for your report to be ready.
To make the report names more descriptive, you can include placeholders for the
object name, the report type and/or the reference date. For subreports and reports over a single object,
use the placeholder "${ooi}" for the object name, "${report_type}" for the report type and use a
<a href="https://strftime.org/" target="_blank" rel="noopener">Python strftime code</a> for the reference
date. For reports over multiple objects, use "${oois_count}" for the number of objects in the report.
{% endblocktranslate %}
</p>
<div class="column-2">
{% include "partials/form/fieldset.html" with fields=report_schedule_form_start_date %}

<p>
{% blocktranslate trimmed %}
For example, the format "${report_type} for ${ooi} at %x" could generate:
"DNS Report for example.com at 01/01/25".
{% endblocktranslate %}
</p>
</div>
<fieldset>
<div>
<label for="parent_report_name_format">{% translate "Report name format" %}</label>
<input type="text"
id="parent_report_name_format"
name="parent_report_name_format"
value="{{ initial_report_names.0 }}">
</div>
</fieldset>
{% if initial_report_names.1 %}
<fieldset>
<div>
<label for="subreport_name_format">{% translate "Subreports name format" %}</label>
<input type="text"
id="subreport_name_format"
name="subreport_name_format"
value="{{ initial_report_names.1 }}">
</div>
</fieldset>
{% endif %}
</form>
<form id="generate_report" class="inline" method="post" action="{{ next }}">
{% csrf_token %}
{% include "forms/report_form_fields.html" %}

{% if not is_scheduled_report %}
{% include "partials/report_names_header.html" %}
{% include "partials/report_names_form.html" %}

<button type="submit" form="generate_report">
{% translate "Generate report" %}<span class="icon ti-chevron-right" aria-hidden="true"></span>
</button>
{% else %}
{% include "partials/report_names_header.html" with recurrence=True %}
{% include "partials/form/fieldset.html" with fields=report_parent_name_form %}

{% if reports|length > 1 %}
{% include "partials/form/fieldset.html" with fields=report_child_name_form %}

{% endif %}
<button type="submit" form="generate_report">
{% translate "Generate report" %}<span class="icon ti-chevron-right" aria-hidden="true"></span>
</button>
{% endif %}
<button type="submit">
{% translate "Generate report" %}<span class="icon ti-chevron-right" aria-hidden="true"></span>
</button>
</form>
{% else %}
{% include "partials/return_button.html" with btn_text="Go back" %}
Expand Down
35 changes: 0 additions & 35 deletions rocky/reports/templates/partials/report_names_header.html

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@
</td>
<td class="nowrap report_reference_date">{{ report.parent_report.observed_at|date }}</td>
<td class="nowrap report_creation_date">{{ report.parent_report.date_generated }}</td>
{% if report.children_reports %}
<td class="sticky-cell">
<td class="sticky-cell">
{% if report.children_reports %}
<button type="button"
class="expando-button icon ti-chevron-down"
data-icon-open-class="icon ti-chevron-down"
Expand All @@ -144,8 +144,8 @@
aria-expanded="false">
{% translate "Open children report object details" %}
</button>
</td>
{% endif %}
{% endif %}
</td>
</tr>
{% if report.children_reports %}
<tr class="expando-row">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,40 +27,44 @@
{% if schedule.recipe %}
<tr>
<td class="nowrap">{{ schedule.recipe.report_name_format }}</td>
<td>
<td class="nowrap">
<ul class="tags horizontal-view">
{% if schedule.recipe.parent_report_type == "aggregate-organisation-report" %}
<li class="label tags-color-{{ schedule.recipe.parent_report_type|get_report_type_label_style }}">
{{ schedule.recipe.parent_report_type|get_report_type_name }}
<li>
<span class="label tags-color-{{ schedule.recipe.parent_report_type|get_report_type_label_style }}">{{ schedule.recipe.parent_report_type|get_report_type_name }}</span>
</li>
{% else %}
{% for report_type in schedule.recipe.report_types %}
{% if forloop.counter0 < 2 %}
<li class="label tags-color-{{ report_type|get_report_type_label_style }}">{{ report_type|get_report_type_name }}</li>
<li>
<span class="label tags-color-{{ report_type|get_report_type_label_style }}">{{ report_type|get_report_type_name }}</span>
</li>
{% endif %}
{% if forloop.counter0 == 2 %}
<li class="label tags-color-grey-2">+ {{ schedule.recipe.report_types|length|add:"-2" }}</li>
<li>
<span class="label tags-color-grey-2">+ {{ schedule.recipe.report_types|length|add:"-2" }}</span>
</li>
{% endif %}
{% endfor %}
{% endif %}
</ul>
</td>
<td class="nowrap">{{ schedule.deadline_at }}</td>
<td class="nowrap">
{% if not schedule.enabled %}
-
{% if schedule.cron is None %}
{% translate "Once" %}
{% else %}
{{ schedule.deadline_at }}
{{ schedule.cron }}
{% endif %}
</td>
<td class="nowrap">{{ schedule.cron }}</td>
<td class="nowrap">
{% if schedule.enabled %}
<span class="label system-tag color-2">{% translate "Enabled" %}</span>
{% else %}
<span class="label system-tag color-3">{% translate "Disabled" %}</span>
{% endif %}
</td>
<td class="actions sticky-cell">
<td class="nowrap actions sticky-cell">
<button class="expando-button"
data-icon-open-class="icon ti-chevron-down"
data-icon-close-class="icon ti-chevron-up"
Expand Down
Loading
Loading