Add migrations & use default publication_date
This commit is contained in:
parent
191eb94ece
commit
8ae2743026
4 changed files with 49 additions and 4 deletions
|
|
@ -0,0 +1,28 @@
|
|||
# Generated by Django 3.0.5 on 2020-05-24 10:18
|
||||
|
||||
import django.db.models.deletion
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("django_celery_beat", "0012_periodictask_expire_seconds"),
|
||||
("accounts", "0008_auto_20200422_2243"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="user",
|
||||
name="task",
|
||||
field=models.OneToOneField(
|
||||
blank=True,
|
||||
editable=False,
|
||||
null=True,
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
to="django_celery_beat.PeriodicTask",
|
||||
verbose_name="collection task",
|
||||
),
|
||||
)
|
||||
]
|
||||
|
|
@ -82,8 +82,7 @@ class FeedBuilder(Builder):
|
|||
value = self.truncate_text(model_field, entry[field])
|
||||
|
||||
if field == "published_parsed":
|
||||
aware_datetime, created = build_publication_date(value, tz)
|
||||
data[model_field] = aware_datetime if created else None
|
||||
data[model_field] = build_publication_date(value, tz)
|
||||
elif field == "summary":
|
||||
summary = self.sanitize_fragment(value)
|
||||
data[model_field] = summary
|
||||
|
|
|
|||
|
|
@ -15,9 +15,9 @@ def build_publication_date(dt, tz):
|
|||
naive_datetime = datetime(*dt[:6])
|
||||
published_parsed = timezone.make_aware(naive_datetime, timezone=tz)
|
||||
except (TypeError, ValueError):
|
||||
return None, False
|
||||
return timezone.now()
|
||||
|
||||
return published_parsed.astimezone(pytz.utc), True
|
||||
return published_parsed.astimezone(pytz.utc)
|
||||
|
||||
|
||||
def fetch(url):
|
||||
|
|
|
|||
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 3.0.5 on 2020-05-24 10:18
|
||||
|
||||
import django.utils.timezone
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [("core", "0005_auto_20200412_1955")]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="post",
|
||||
name="publication_date",
|
||||
field=models.DateTimeField(default=django.utils.timezone.now),
|
||||
)
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue