Skip to content

Commit

Permalink
Merge pull request #1111 from linea-it/subscription-fixes-06
Browse files Browse the repository at this point in the history
Subscription fixes 6
  • Loading branch information
rcboufleur authored Nov 30, 2024
2 parents 0e8c5fe + 5edf786 commit a42751a
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 42 deletions.
1 change: 0 additions & 1 deletion backend/coreAdmin/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
from rest_framework.authtoken.views import obtain_auth_token
from rest_framework.routers import DefaultRouter, SimpleRouter
from skybot.views import PositionViewSet

from tno.views import (
AsteroidJobViewSet,
AsteroidViewSet,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
class Migration(migrations.Migration):

dependencies = [
('newsletter', '0030_auto_20241118_1235'),
("newsletter", "0030_auto_20241118_1235"),
]

operations = [
migrations.RemoveField(
model_name='submission',
name='sending',
model_name="submission",
name="sending",
),
]
13 changes: 9 additions & 4 deletions backend/newsletter/migrations/0032_submission_sending_date.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@
class Migration(migrations.Migration):

dependencies = [
('newsletter', '0031_remove_submission_sending'),
("newsletter", "0031_remove_submission_sending"),
]

operations = [
migrations.AddField(
model_name='submission',
name='sending_date',
field=models.DateTimeField(blank=True, help_text='Data do envio da submissao.', null=True, verbose_name='Seding Datte'),
model_name="submission",
name="sending_date",
field=models.DateTimeField(
blank=True,
help_text="Data do envio da submissao.",
null=True,
verbose_name="Seding Datte",
),
),
]
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
class Migration(migrations.Migration):

dependencies = [
('newsletter', '0032_submission_sending_date'),
("newsletter", "0032_submission_sending_date"),
]

operations = [
migrations.RemoveField(
model_name='submission',
name='sending_date',
model_name="submission",
name="sending_date",
),
]
22 changes: 15 additions & 7 deletions backend/newsletter/migrations/0034_auto_20241122_1243.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
# Generated by Django 3.2.18 on 2024-11-22 12:43

from django.db import migrations, models
import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('newsletter', '0033_remove_submission_sending_date'),
("newsletter", "0033_remove_submission_sending_date"),
]

operations = [
migrations.RemoveField(
model_name='submission',
name='title',
model_name="submission",
name="title",
),
migrations.AddField(
model_name='eventfilter',
name='attachment',
field=models.ForeignKey(blank=True, help_text='Attachment associated with this event filter.', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='event_filters', to='newsletter.attachment', verbose_name='Attachment'),
model_name="eventfilter",
name="attachment",
field=models.ForeignKey(
blank=True,
help_text="Attachment associated with this event filter.",
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="event_filters",
to="newsletter.attachment",
verbose_name="Attachment",
),
),
]
36 changes: 20 additions & 16 deletions backend/newsletter/process_event_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,17 +261,18 @@ def process_subscription_filter(self, filter_set, output_path, force_run=False):
date_start = (now + relativedelta(months=1)).replace(
day=1, hour=0, minute=0, second=0, microsecond=0
)
allow_process = True if (date_start - now).days <= 7 else False
already_processed = (
latest_processing_date is not None
and (date_start - latest_processing_date).days < 7
processing_window = True if (date_start - now).days <= 7 else False

allow_process = (latest_processing_date is None) or not (
(date_start - relativedelta(days=7) <= latest_processing_date)
and (latest_processing_date <= date_start)
)

if force_run:
date_end = (
date_start + relativedelta(months=1) - relativedelta(microseconds=1)
)
elif allow_process and not already_processed:
elif processing_window and allow_process:
date_end = (
date_start + relativedelta(months=1) - relativedelta(microseconds=1)
)
Expand All @@ -285,20 +286,22 @@ def process_subscription_filter(self, filter_set, output_path, force_run=False):
date_start = (now + relativedelta(weekday=SU(+1))).replace(
hour=0, minute=0, second=0, microsecond=0
)
allow_process = (

processing_window = (
True if (date_start - now).days <= 3 else False
) # verifica se deve ser processado
already_processed = (
latest_processing_date is not None
and (date_start - latest_processing_date).days < 3

allow_process = (latest_processing_date is None) or not (
(date_start - relativedelta(days=3) <= latest_processing_date)
and (latest_processing_date <= date_start)
)
if force_run:
date_end = (
date_start
+ relativedelta(weekday=SU(+2))
- relativedelta(microseconds=1)
)
elif allow_process and not already_processed:
elif processing_window and allow_process:
date_end = (
date_start
+ relativedelta(weekday=SU(+2))
Expand All @@ -313,18 +316,19 @@ def process_subscription_filter(self, filter_set, output_path, force_run=False):
date_start = (now + relativedelta(days=1)).replace(
hour=0, minute=0, second=0, microsecond=0
)
self.log.info("Processing daily filter.")
processing_window = True if (date_start - now).seconds < 86400 else False

allow_process = True if (date_start - now).seconds < 86400 else False

already_processed = (
latest_processing_date is not None
and (date_start - latest_processing_date).seconds < 86400
allow_process = (latest_processing_date is None) or not (
(date_start - relativedelta(days=1) <= latest_processing_date)
and (latest_processing_date <= date_start)
)

if force_run:
date_end = (
date_start + relativedelta(days=1) - relativedelta(microseconds=1)
)
elif allow_process and not already_processed:
elif processing_window and allow_process:
date_end = (
date_start + relativedelta(days=1) - relativedelta(microseconds=1)
)
Expand Down
16 changes: 8 additions & 8 deletions backend/newsletter/templates/results.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<td>
<!-- Centered and Rounded Table -->
<div
style="margin: 0 auto; max-width: 90%; background-color: #ffffff; border-radius: 10px; overflow: hidden; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);">
style="margin: 0 auto; max-width: 95%; background-color: #ffffff; border-radius: 10px; overflow: hidden; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);">
<table width="100%" style="border-collapse: collapse; margin: 0px 0;">
<thead style="background-color: #0076BC; color: #fff;">
<tr>
Expand All @@ -33,27 +33,27 @@
<tbody style="background-color: #ffffff; color: #0c0c0c;">
{% for row in data %}
<tr class="clickable-row">
<td style="padding: 10px; font-size: 12px; text-align: center;">
<td style="padding: 3px; font-size: 12px; text-align: center;">
{{ row.date_time|default:"-" }}
</td>
<td style="padding: 6px; font-size: 12px; text-align: center;">
<td style="padding: 3px; font-size: 12px; text-align: center;">
{{row.name|default:"-" }}
</td>
<td style="padding: 6px; font-size: 12px; text-align: center;">
<td style="padding: 3px; font-size: 12px; text-align: center;">
{% if row.velocity %}
{{ row.velocity|floatformat:1 }}
{% else %}
-
{% endif %}
</td>
<td style="padding: 6px; font-size: 12px; text-align: center;">
<td style="padding: 3px; font-size: 12px; text-align: center;">
{% if row.closest_approach %}
{{ row.closest_approach|floatformat:3 }}
{% else %}
-
{% endif %}
</td>
<td style="padding: 6px; font-size: 12px; text-align: center;">
<td style="padding: 3px; font-size: 12px; text-align: center;">
{% if row.closest_approach_uncertainty_km %}
{% if row.closest_approach_uncertainty_km > 12500 %}
Very High
Expand All @@ -64,14 +64,14 @@
-
{% endif %}
</td>
<td style="padding: 6px; font-size: 12px; text-align: center;">
<td style="padding: 3px; font-size: 12px; text-align: center;">
{% if row.gaia_magnitude %}
{{ row.gaia_magnitude|floatformat:1 }}
{% else %}
-
{% endif %}
</td>
<td style="padding: 8px; font-size: 11px; text-align: center;">
<td style="padding: 3px; font-size: 11px; text-align: center;">
<a href='{{ host }}/prediction-event-detail/{{ row.id }}'>[URL]</a>
</td>
</tr>
Expand Down

0 comments on commit a42751a

Please sign in to comment.