Ajout d'un drapeau permettant de décider si les événements sont publiés par défaut

This commit is contained in:
Jean-Marie Favreau 2024-01-26 14:18:53 +01:00
parent 8d5dca4910
commit 2275203ff9
4 changed files with 26 additions and 3 deletions

View File

@ -109,10 +109,11 @@ def run_recurrent_import(self, pk):
category = str(rimport.defaultCategory)
location = rimport.defaultLocation
tags = rimport.defaultTags
published = rimport.defaultPublished
try:
# get events from website
events = u2e.process(url, browsable_url, default_values = {"category": category, "location": location, "tags": tags}, published = True)
events = u2e.process(url, browsable_url, default_values = {"category": category, "location": location, "tags": tags}, published = published)
# convert it to json
json_events = json.dumps(events, default=str)

View File

@ -0,0 +1,18 @@
# Generated by Django 4.2.7 on 2024-01-26 12:43
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('agenda_culturel', '0030_recurrentimport_downloader'),
]
operations = [
migrations.AddField(
model_name='recurrentimport',
name='defaultPublished',
field=models.BooleanField(default=True, help_text='Status of each imported event (published or draft)', verbose_name='Published'),
),
]

View File

@ -397,7 +397,10 @@ class Event(models.Model):
del event_structure["uuid"]
if "published" in event_structure and event_structure["published"] is not None:
event_structure["status"] = Event.STATUS.PUBLISHED
if event_structure["published"]:
event_structure["status"] = Event.STATUS.PUBLISHED
else:
event_structure["status"] = Event.STATUS.DRAFT
del event_structure["published"]
else:
event_structure["status"] = Event.STATUS.DRAFT
@ -728,8 +731,8 @@ class RecurrentImport(models.Model):
source = models.URLField(verbose_name=_('Source'), help_text=_("URL of the source document"), max_length=1024)
browsable_url = models.URLField(verbose_name=_('Browsable url'), help_text=_("URL of the corresponding document that will be shown to visitors."), max_length=1024, blank=True, null=True)
defaultPublished = models.BooleanField(verbose_name=_('Published'), help_text=_('Status of each imported event (published or draft)'), default=True)
defaultLocation = models.CharField(verbose_name=_('Location'), help_text=_('Address for each imported event'), max_length=512, null=True, blank=True)
defaultCategory = models.ForeignKey(Category, verbose_name=_('Category'), help_text=_('Category of each imported event'), blank=True, null=True, on_delete=models.SET_NULL)
defaultTags = ArrayField(models.CharField(max_length=64), verbose_name=_('Tags for each imported event'), help_text=_("A list of tags that describe each imported event."), blank=True, null=True)

View File

@ -30,6 +30,7 @@
<li><strong>Adresse naviguable&nbsp;:</strong> <a href="{{ object.browsable_url }}">{{ object.browsable_url }}</a></li>
<li><strong>Valeurs par défaut&nbsp;:</strong>
<ul>
<li><strong>Publié&nbsp;:</strong> {{ object.defaultPublished }}</li>
<li><strong>Localisation&nbsp;:</strong> {{ object.defaultLocation }}</li>
<li><strong>Catégorie&nbsp;:</strong> {{ object.defaultCategory }}</li>
<li><strong>Étiquettes&nbsp;:</strong>