c'est celery qui s'occupera de l'intégration
This commit is contained in:
parent
a47178dac1
commit
5d3881721f
@ -26,6 +26,22 @@ app.config_from_object("django.conf:settings", namespace="CELERY")
|
|||||||
app.autodiscover_tasks()
|
app.autodiscover_tasks()
|
||||||
|
|
||||||
|
|
||||||
|
@app.task(bind=True)
|
||||||
|
def import_events_from_json(self, json, taskid):
|
||||||
|
from agenda_culturel.models import Event
|
||||||
|
|
||||||
|
logger.info("Import events from json: {}".format(taskid))
|
||||||
|
|
||||||
|
# TODO
|
||||||
|
|
||||||
|
|
||||||
|
@app.task(bind=True)
|
||||||
|
def import_events_from_url(self, source, browsable_url, taskid):
|
||||||
|
from agenda_culturel.models import Event
|
||||||
|
|
||||||
|
logger.info("Import events from url: {} {}".format(source, taskid))
|
||||||
|
|
||||||
|
# TODO
|
||||||
|
|
||||||
|
|
||||||
app.conf.timezone = "Europe/Paris"
|
app.conf.timezone = "Europe/Paris"
|
||||||
|
@ -0,0 +1,28 @@
|
|||||||
|
# Generated by Django 4.2.7 on 2023-12-23 10:14
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('agenda_culturel', '0012_remove_batchimportation_running_and_more'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='batchimportation',
|
||||||
|
name='error_message',
|
||||||
|
field=models.CharField(blank=True, max_length=512, null=True, verbose_name='Error message'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='batchimportation',
|
||||||
|
name='nb_imported',
|
||||||
|
field=models.PositiveIntegerField(default=0, verbose_name='Number of imported events'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='batchimportation',
|
||||||
|
name='nb_initial',
|
||||||
|
field=models.PositiveIntegerField(default=0, verbose_name='Number of collected events'),
|
||||||
|
),
|
||||||
|
]
|
@ -236,3 +236,8 @@ class BatchImportation(models.Model):
|
|||||||
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)
|
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)
|
||||||
|
|
||||||
status = models.CharField(_("Status"), max_length=20, choices=STATUS.choices, default=STATUS.RUNNING)
|
status = models.CharField(_("Status"), max_length=20, choices=STATUS.choices, default=STATUS.RUNNING)
|
||||||
|
|
||||||
|
error_message = models.CharField(verbose_name=_('Error message'), max_length=512, blank=True, null=True)
|
||||||
|
|
||||||
|
nb_initial = models.PositiveIntegerField(verbose_name=_('Number of collected events'), default=0)
|
||||||
|
nb_imported = models.PositiveIntegerField(verbose_name=_('Number of imported events'), default=0)
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
<p>
|
<p>
|
||||||
<label for="id_json">JSON (facultatif) :</label>
|
<label for="id_json">JSON (facultatif) :</label>
|
||||||
<textarea id="id_json" name="json" rows="10"></textarea>
|
<textarea id="id_json" name="json" rows="10"></textarea>
|
||||||
<span class="helptext">JSON au format attendu pour l'import. Si le JSON est fourni ici, on ne lancera pas une récupération depuis l'URL donnée en paramètre.</span>
|
<span class="helptext">JSON au format attendu pour l'import. Si le JSON est fourni ici, on ignorera les URL données au dessus, et on utilisera les informations fournies par le json sans réaliser d'importation supplémentaire d'événements depuis l'URL.</span>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<input type="submit" value="Envoyer">
|
<input type="submit" value="Envoyer">
|
||||||
|
@ -32,6 +32,8 @@ from django.contrib.messages.views import SuccessMessageMixin
|
|||||||
from .calendar import CalendarMonth, CalendarWeek
|
from .calendar import CalendarMonth, CalendarWeek
|
||||||
from .extractors import ExtractorAllURLs
|
from .extractors import ExtractorAllURLs
|
||||||
|
|
||||||
|
from .celery import import_events_from_json, import_events_from_url
|
||||||
|
|
||||||
import unicodedata
|
import unicodedata
|
||||||
|
|
||||||
|
|
||||||
@ -491,9 +493,14 @@ class BatchImportationCreateView(SuccessMessageMixin, LoginRequiredMixin, Create
|
|||||||
success_message = _('The import has been run successfully.')
|
success_message = _('The import has been run successfully.')
|
||||||
|
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
# TODO run a celery script
|
response = super().form_valid(form)
|
||||||
|
|
||||||
return super().form_valid(form)
|
if "json" in form.data and form.data["json"] is not None and form.data["json"].strip() != "":
|
||||||
|
import_events_from_json.delay(form.data["json"], self.object.id)
|
||||||
|
else:
|
||||||
|
import_events_from_url.delay(self.object.source, self.object.browsable_url, self.object.id)
|
||||||
|
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
@login_required(login_url="/accounts/login/")
|
@login_required(login_url="/accounts/login/")
|
||||||
|
Loading…
Reference in New Issue
Block a user