diff --git a/src/agenda_culturel/celery.py b/src/agenda_culturel/celery.py index 0405806..edb93e8 100644 --- a/src/agenda_culturel/celery.py +++ b/src/agenda_culturel/celery.py @@ -199,6 +199,45 @@ def weekly_imports(self): run_recurrent_import.delay(imp.pk) +@app.task(base=ChromiumTask, bind=True) +def import_events_from_urls(self, urls_and_cats): + from agenda_culturel.models import Event, Category + + for ucat in urls_and_cats: + if ucat is not None: + url = ucat[0] + cat = ucat[1] + + url = Extractor.clean_url(url) + + # we check if the url is known + existing = Event.objects.filter(uuids__contains=[url]) + # if it's unknown + if len(existing) == 0: + + u2e = URL2Events(ChromiumHeadlessDownloader(), single_event=True) + events_structure = u2e.process( + url, published=False + ) + # TODO: use celery to import the associated events + if ( + events_structure is not None + and "events" in events_structure + and len(events_structure["events"]) > 0 + ): + event = Event.from_structure( + events_structure["events"][0], + events_structure["header"]["url"], + ) + if event is not None: + if (event.category is None or event.category == Category.get_default_category()): + if cat is not None: + event.category = Category.objects.filter(name=cat).first() + + + event.save() + logger.info('Successful import from ' + url) + app.conf.beat_schedule = { "daily_imports": { "task": "agenda_culturel.celery.daily_imports", diff --git a/src/agenda_culturel/locale/fr/LC_MESSAGES/django.po b/src/agenda_culturel/locale/fr/LC_MESSAGES/django.po index 7b7ec47..7cbdca6 100644 --- a/src/agenda_culturel/locale/fr/LC_MESSAGES/django.po +++ b/src/agenda_culturel/locale/fr/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: agenda_culturel\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-05-03 09:48+0000\n" +"POT-Creation-Date: 2024-08-15 22:30+0200\n" "PO-Revision-Date: 2023-10-29 14:16+0000\n" "Last-Translator: Jean-Marie Favreau \n" "Language-Team: Jean-Marie Favreau \n" @@ -17,144 +17,141 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -#: agenda_culturel/forms.py:112 +#: agenda_culturel/forms.py:44 agenda_culturel/models.py:149 +#: agenda_culturel/models.py:316 agenda_culturel/models.py:1294 +#: agenda_culturel/models.py:1380 +msgid "Category" +msgstr "Catégorie" + +#: agenda_culturel/forms.py:46 +msgid "Unknown" +msgstr "Inconnue" + +#: agenda_culturel/forms.py:118 msgid "The end date must be after the start date." msgstr "La date de fin doit être après la date de début." -#: agenda_culturel/forms.py:128 +#: agenda_culturel/forms.py:134 msgid "The end time cannot be earlier than the start time." msgstr "L'heure de fin ne peut pas être avant l'heure de début." -#: agenda_culturel/forms.py:138 +#: agenda_culturel/forms.py:144 msgid "JSON in the format expected for the import." msgstr "JSON dans le format attendu pour l'import" -#: agenda_culturel/forms.py:397 +#: agenda_culturel/forms.py:403 msgid "Apply category {} to the event {}" msgstr "Appliquer la catégorie {} à l'événement {}" -#: agenda_culturel/forms.py:412 agenda_culturel/models.py:235 +#: agenda_culturel/forms.py:418 agenda_culturel/models.py:240 msgid "Place" msgstr "Lieu" -#: agenda_culturel/forms.py:414 +#: agenda_culturel/forms.py:420 msgid "Create a missing place" msgstr "Créer un lieu manquant" -#: agenda_culturel/forms.py:424 +#: agenda_culturel/forms.py:430 msgid "Add \"{}\" to the aliases of the place" msgstr "Ajouter « {} » aux alias du lieu" -#: agenda_culturel/forms.py:448 +#: agenda_culturel/forms.py:457 msgid "On saving, use aliases to detect all matching events with missing place" msgstr "" "Lors de l'enregistrement, utiliser des alias pour détecter tous les " "événements correspondants dont la place est manquante." -#: agenda_culturel/import_tasks/extractor_ical.py:54 -msgid "The source is empty" -msgstr "La source est vide" - -#: agenda_culturel/import_tasks/generic_extractors.py:197 -msgid "Cannot extract event from url {}" -msgstr "Impossible d'extraire l'événement depuis l'url {}" - -#: agenda_culturel/models.py:42 agenda_culturel/models.py:86 -#: agenda_culturel/models.py:214 agenda_culturel/models.py:1104 -#: agenda_culturel/models.py:1167 +#: agenda_culturel/models.py:44 agenda_culturel/models.py:88 +#: agenda_culturel/models.py:219 agenda_culturel/models.py:1176 +#: agenda_culturel/models.py:1240 msgid "Name" msgstr "Nom" -#: agenda_culturel/models.py:43 agenda_culturel/models.py:86 +#: agenda_culturel/models.py:45 agenda_culturel/models.py:88 msgid "Category name" msgstr "Nom de la catégorie" -#: agenda_culturel/models.py:48 +#: agenda_culturel/models.py:50 msgid "Content" msgstr "Contenu" -#: agenda_culturel/models.py:48 +#: agenda_culturel/models.py:50 msgid "Text as shown to the visitors" msgstr "Text tel que présenté aux visiteureuses" -#: agenda_culturel/models.py:51 +#: agenda_culturel/models.py:53 msgid "URL path" msgstr "Chemin URL" -#: agenda_culturel/models.py:52 +#: agenda_culturel/models.py:54 msgid "URL path where the content is included." msgstr "Chemin URL où le contenu est présent." -#: agenda_culturel/models.py:56 +#: agenda_culturel/models.py:58 msgid "Static content" msgstr "Contenu statique" -#: agenda_culturel/models.py:57 +#: agenda_culturel/models.py:59 msgid "Static contents" msgstr "Contenus statiques" -#: agenda_culturel/models.py:89 +#: agenda_culturel/models.py:91 msgid "Alternative Name" msgstr "Nom alternatif" -#: agenda_culturel/models.py:90 +#: agenda_culturel/models.py:92 msgid "Alternative name used with a time period" msgstr "Nom alternatif utilisé avec une période de temps" -#: agenda_culturel/models.py:94 +#: agenda_culturel/models.py:96 msgid "Short name" msgstr "Nom court" -#: agenda_culturel/models.py:95 +#: agenda_culturel/models.py:97 msgid "Short name of the category" msgstr "Nom court de la catégorie" -#: agenda_culturel/models.py:99 +#: agenda_culturel/models.py:101 msgid "Color" msgstr "Couleur" -#: agenda_culturel/models.py:100 +#: agenda_culturel/models.py:102 msgid "Color used as background for the category" msgstr "Couleur utilisée comme fond de la catégorie" -#: agenda_culturel/models.py:147 agenda_culturel/models.py:307 -#: agenda_culturel/models.py:1221 agenda_culturel/models.py:1307 -msgid "Category" -msgstr "Catégorie" - -#: agenda_culturel/models.py:148 +#: agenda_culturel/models.py:150 msgid "Categories" msgstr "Catégories" -#: agenda_culturel/models.py:153 agenda_culturel/models.py:154 +#: agenda_culturel/models.py:155 agenda_culturel/models.py:156 msgid "Duplicated events" msgstr "Événements dupliqués" -#: agenda_culturel/models.py:214 +#: agenda_culturel/models.py:219 msgid "Name of the place" msgstr "Nom du lieu" -#: agenda_culturel/models.py:216 +#: agenda_culturel/models.py:221 msgid "Address" msgstr "Adresse" -#: agenda_culturel/models.py:217 +#: agenda_culturel/models.py:222 msgid "Address of this place (without city name)" msgstr "Adresse de ce lieu (sans le nom de la ville)" -#: agenda_culturel/models.py:221 +#: agenda_culturel/models.py:226 msgid "City" msgstr "Ville" -#: agenda_culturel/models.py:221 +#: agenda_culturel/models.py:226 msgid "City name" msgstr "Nom de la ville" -#: agenda_culturel/models.py:226 +#: agenda_culturel/models.py:231 msgid "Alternative names" msgstr "Noms alternatifs" -#: agenda_culturel/models.py:228 +#: agenda_culturel/models.py:233 msgid "" "Alternative names or addresses used to match a place with the free-form " "location of an event." @@ -162,77 +159,77 @@ msgstr "" "Noms et adresses alternatives qui seront utilisées pour associer une adresse " "avec la localisation en forme libre d'un événement" -#: agenda_culturel/models.py:236 +#: agenda_culturel/models.py:241 msgid "Places" msgstr "Lieux" -#: agenda_culturel/models.py:285 agenda_culturel/models.py:1208 +#: agenda_culturel/models.py:294 agenda_culturel/models.py:1281 msgid "Published" msgstr "Publié" -#: agenda_culturel/models.py:286 +#: agenda_culturel/models.py:295 msgid "Draft" msgstr "Brouillon" -#: agenda_culturel/models.py:287 +#: agenda_culturel/models.py:296 msgid "Trash" msgstr "Corbeille" -#: agenda_culturel/models.py:298 +#: agenda_culturel/models.py:307 msgid "Title" msgstr "Titre" -#: agenda_culturel/models.py:298 +#: agenda_culturel/models.py:307 msgid "Short title" msgstr "Titre court" -#: agenda_culturel/models.py:302 agenda_culturel/models.py:1275 +#: agenda_culturel/models.py:311 agenda_culturel/models.py:1348 msgid "Status" msgstr "Status" -#: agenda_culturel/models.py:308 +#: agenda_culturel/models.py:317 msgid "Category of the event" msgstr "Catégorie de l'événement" -#: agenda_culturel/models.py:315 +#: agenda_culturel/models.py:324 msgid "Day of the event" msgstr "Date de l'événement" -#: agenda_culturel/models.py:318 agenda_culturel/models.py:319 +#: agenda_culturel/models.py:327 agenda_culturel/models.py:328 msgid "Starting time" msgstr "Heure de début" -#: agenda_culturel/models.py:325 +#: agenda_culturel/models.py:334 msgid "End day of the event" msgstr "Fin de l'événement" -#: agenda_culturel/models.py:327 +#: agenda_culturel/models.py:336 msgid "End day of the event, only required if different from the start day." msgstr "" "Date de fin de l'événement, uniquement nécessaire s'il est différent du " "premier jour de l'événement" -#: agenda_culturel/models.py:333 +#: agenda_culturel/models.py:342 msgid "Final time" msgstr "Heure de fin" -#: agenda_culturel/models.py:337 +#: agenda_culturel/models.py:346 msgid "Recurrence" msgstr "Récurrence" -#: agenda_culturel/models.py:342 agenda_culturel/models.py:1213 +#: agenda_culturel/models.py:351 agenda_culturel/models.py:1286 msgid "Location" msgstr "Localisation" -#: agenda_culturel/models.py:343 +#: agenda_culturel/models.py:352 msgid "Address of the event" msgstr "Adresse de l'événement" -#: agenda_culturel/models.py:349 +#: agenda_culturel/models.py:358 msgid "Location (free form)" msgstr "Localisation (forme libre)" -#: agenda_culturel/models.py:351 +#: agenda_culturel/models.py:360 msgid "" "Address of the event in case its not available in the already known places " "(free form)" @@ -240,187 +237,191 @@ msgstr "" "Addresse d'un événement si elle n'est pas déjà présente dans la liste des " "lieux disponible (forme libre)" -#: agenda_culturel/models.py:358 +#: agenda_culturel/models.py:367 msgid "Description" msgstr "Description" -#: agenda_culturel/models.py:359 +#: agenda_culturel/models.py:368 msgid "General description of the event" msgstr "Description générale de l'événement" -#: agenda_culturel/models.py:365 +#: agenda_culturel/models.py:374 msgid "Illustration (local image)" msgstr "Illustration (image locale)" -#: agenda_culturel/models.py:366 +#: agenda_culturel/models.py:375 msgid "Illustration image stored in the agenda server" msgstr "Image d'illustration stockée sur le serveur de l'agenda" -#: agenda_culturel/models.py:373 +#: agenda_culturel/models.py:382 msgid "Illustration" msgstr "Illustration" -#: agenda_culturel/models.py:374 +#: agenda_culturel/models.py:383 msgid "URL of the illustration image" msgstr "URL de l'image illustrative" -#: agenda_culturel/models.py:380 +#: agenda_culturel/models.py:389 msgid "Illustration description" msgstr "Description de l'illustration" -#: agenda_culturel/models.py:381 +#: agenda_culturel/models.py:390 msgid "Alternative text used by screen readers for the image" msgstr "Texte alternatif utiliser par les lecteurs d'écrans pour l'image" -#: agenda_culturel/models.py:389 +#: agenda_culturel/models.py:398 msgid "Importation source" msgstr "Source d'importation" -#: agenda_culturel/models.py:390 +#: agenda_culturel/models.py:399 msgid "Importation source used to detect removed entries." msgstr "Source d'importation utilisée pour détecter les éléments supprimés/" -#: agenda_culturel/models.py:396 +#: agenda_culturel/models.py:405 msgid "UUIDs" msgstr "UUIDs" -#: agenda_culturel/models.py:397 +#: agenda_culturel/models.py:406 msgid "UUIDs from import to detect duplicated entries." msgstr "UUIDs utilisés pendant l'import pour détecter les entrées dupliquées" -#: agenda_culturel/models.py:403 +#: agenda_culturel/models.py:412 msgid "URLs" msgstr "URLs" -#: agenda_culturel/models.py:404 +#: agenda_culturel/models.py:413 msgid "List of all the urls where this event can be found." msgstr "Liste de toutes les urls où l'événement peut être trouvé." -#: agenda_culturel/models.py:411 +#: agenda_culturel/models.py:420 msgid "Tags" msgstr "Étiquettes" -#: agenda_culturel/models.py:412 +#: agenda_culturel/models.py:421 msgid "A list of tags that describe the event." msgstr "Une liste d'étiquettes décrivant l'événement" -#: agenda_culturel/models.py:419 +#: agenda_culturel/models.py:428 msgid "Possibly duplicated" msgstr "Possibles doublons" -#: agenda_culturel/models.py:468 +#: agenda_culturel/models.py:477 msgid "Event" msgstr "Événement" -#: agenda_culturel/models.py:469 +#: agenda_culturel/models.py:478 msgid "Events" msgstr "Événements" -#: agenda_culturel/models.py:1095 +#: agenda_culturel/models.py:1167 msgid "Contact message" msgstr "Message de contact" -#: agenda_culturel/models.py:1096 +#: agenda_culturel/models.py:1168 msgid "Contact messages" msgstr "Messages de contact" -#: agenda_culturel/models.py:1099 +#: agenda_culturel/models.py:1171 msgid "Subject" msgstr "Sujet" -#: agenda_culturel/models.py:1100 +#: agenda_culturel/models.py:1172 msgid "The subject of your message" msgstr "Sujet de votre message" -#: agenda_culturel/models.py:1105 +#: agenda_culturel/models.py:1177 msgid "Your name" msgstr "Votre nom" -#: agenda_culturel/models.py:1111 +#: agenda_culturel/models.py:1183 msgid "Email address" msgstr "Adresse email" -#: agenda_culturel/models.py:1112 +#: agenda_culturel/models.py:1184 msgid "Your email address" msgstr "Votre adresse email" -#: agenda_culturel/models.py:1117 +#: agenda_culturel/models.py:1189 msgid "Message" msgstr "Message" -#: agenda_culturel/models.py:1117 +#: agenda_culturel/models.py:1189 msgid "Your message" msgstr "Votre message" -#: agenda_culturel/models.py:1122 agenda_culturel/views.py:655 +#: agenda_culturel/models.py:1194 agenda_culturel/views.py:798 msgid "Closed" msgstr "Fermé" -#: agenda_culturel/models.py:1124 +#: agenda_culturel/models.py:1196 msgid "this message has been processed and no longer needs to be handled" msgstr "Ce message a été traité et ne nécessite plus d'être pris en charge" -#: agenda_culturel/models.py:1129 +#: agenda_culturel/models.py:1201 msgid "Comments" msgstr "Commentaires" -#: agenda_culturel/models.py:1130 +#: agenda_culturel/models.py:1202 msgid "Comments on the message from the moderation team" msgstr "Commentaires sur ce message par l'équipe de modération" -#: agenda_culturel/models.py:1142 agenda_culturel/models.py:1266 +#: agenda_culturel/models.py:1214 agenda_culturel/models.py:1339 msgid "Recurrent import" msgstr "Import récurrent" -#: agenda_culturel/models.py:1143 +#: agenda_culturel/models.py:1215 msgid "Recurrent imports" msgstr "Imports récurrents" -#: agenda_culturel/models.py:1147 +#: agenda_culturel/models.py:1219 msgid "ical" msgstr "ical" -#: agenda_culturel/models.py:1148 +#: agenda_culturel/models.py:1220 msgid "ical no busy" msgstr "ical sans busy" -#: agenda_culturel/models.py:1149 +#: agenda_culturel/models.py:1221 msgid "ical no VC" msgstr "ical sans VC" -#: agenda_culturel/models.py:1150 +#: agenda_culturel/models.py:1222 msgid "lacoope.org" msgstr "lacoope.org" -#: agenda_culturel/models.py:1151 +#: agenda_culturel/models.py:1223 msgid "la comédie" msgstr "la comédie" -#: agenda_culturel/models.py:1152 +#: agenda_culturel/models.py:1224 msgid "le fotomat" msgstr "le fotomat" -#: agenda_culturel/models.py:1153 +#: agenda_culturel/models.py:1225 msgid "la puce à loreille" msgstr "la puce à loreille" -#: agenda_culturel/models.py:1156 +#: agenda_culturel/models.py:1226 +msgid "Plugin wordpress MEC" +msgstr "Plugin wordpress MEC" + +#: agenda_culturel/models.py:1229 msgid "simple" msgstr "simple" -#: agenda_culturel/models.py:1157 +#: agenda_culturel/models.py:1230 msgid "Headless Chromium" msgstr "chromium sans interface" -#: agenda_culturel/models.py:1162 +#: agenda_culturel/models.py:1235 msgid "daily" msgstr "chaque jour" -#: agenda_culturel/models.py:1164 +#: agenda_culturel/models.py:1237 msgid "weekly" msgstr "chaque semaine" -#: agenda_culturel/models.py:1169 +#: agenda_culturel/models.py:1242 msgid "" "Recurrent import name. Be careful to choose a name that is easy to " "understand, as it will be public and displayed on the sites About page." @@ -428,127 +429,127 @@ msgstr "" "Nom de l'import récurrent. Attention à choisir un nom compréhensible, car il " "sera public, et affiché sur la page à propos du site." -#: agenda_culturel/models.py:1176 +#: agenda_culturel/models.py:1249 msgid "Processor" msgstr "Processeur" -#: agenda_culturel/models.py:1179 +#: agenda_culturel/models.py:1252 msgid "Downloader" msgstr "Téléchargeur" -#: agenda_culturel/models.py:1186 +#: agenda_culturel/models.py:1259 msgid "Import recurrence" msgstr "Récurrence d'import" -#: agenda_culturel/models.py:1193 +#: agenda_culturel/models.py:1266 msgid "Source" msgstr "Source" -#: agenda_culturel/models.py:1194 +#: agenda_culturel/models.py:1267 msgid "URL of the source document" msgstr "URL du document source" -#: agenda_culturel/models.py:1198 +#: agenda_culturel/models.py:1271 msgid "Browsable url" msgstr "URL navigable" -#: agenda_culturel/models.py:1200 +#: agenda_culturel/models.py:1273 msgid "URL of the corresponding document that will be shown to visitors." msgstr "URL correspondant au document et qui sera montrée aux visiteurs" -#: agenda_culturel/models.py:1209 +#: agenda_culturel/models.py:1282 msgid "Status of each imported event (published or draft)" msgstr "Status de chaque événement importé (publié ou brouillon)" -#: agenda_culturel/models.py:1214 +#: agenda_culturel/models.py:1287 msgid "Address for each imported event" msgstr "Adresse de chaque événement importé" -#: agenda_culturel/models.py:1222 +#: agenda_culturel/models.py:1295 msgid "Category of each imported event" msgstr "Catégorie de chaque événement importé" -#: agenda_culturel/models.py:1228 +#: agenda_culturel/models.py:1301 msgid "Tags for each imported event" msgstr "Étiquettes de chaque événement importé" -#: agenda_culturel/models.py:1229 +#: agenda_culturel/models.py:1302 msgid "A list of tags that describe each imported event." msgstr "Une liste d'étiquettes décrivant chaque événement importé" -#: agenda_culturel/models.py:1252 +#: agenda_culturel/models.py:1325 msgid "Running" msgstr "En cours" -#: agenda_culturel/models.py:1253 +#: agenda_culturel/models.py:1326 msgid "Canceled" msgstr "Annulé" -#: agenda_culturel/models.py:1254 +#: agenda_culturel/models.py:1327 msgid "Success" msgstr "Succès" -#: agenda_culturel/models.py:1255 +#: agenda_culturel/models.py:1328 msgid "Failed" msgstr "Erreur" -#: agenda_culturel/models.py:1258 +#: agenda_culturel/models.py:1331 msgid "Batch importation" msgstr "Importation par lot" -#: agenda_culturel/models.py:1259 +#: agenda_culturel/models.py:1332 msgid "Batch importations" msgstr "Importations par lot" -#: agenda_culturel/models.py:1267 +#: agenda_culturel/models.py:1340 msgid "Reference to the recurrent import processing" msgstr "Référence du processus d'import récurrent" -#: agenda_culturel/models.py:1279 +#: agenda_culturel/models.py:1352 msgid "Error message" msgstr "Votre message" -#: agenda_culturel/models.py:1283 +#: agenda_culturel/models.py:1356 msgid "Number of collected events" msgstr "Nombre d'événements collectés" -#: agenda_culturel/models.py:1286 +#: agenda_culturel/models.py:1359 msgid "Number of imported events" msgstr "Nombre d'événements importés" -#: agenda_culturel/models.py:1289 +#: agenda_culturel/models.py:1362 msgid "Number of updated events" msgstr "Nombre d'événements mis à jour" -#: agenda_culturel/models.py:1292 +#: agenda_culturel/models.py:1365 msgid "Number of removed events" msgstr "Nombre d'événements supprimés" -#: agenda_culturel/models.py:1300 +#: agenda_culturel/models.py:1373 msgid "Weight" msgstr "Poids" -#: agenda_culturel/models.py:1301 +#: agenda_culturel/models.py:1374 msgid "The lower is the weight, the earlier the filter is applied" msgstr "Plus le poids est léger, plus le filtre sera appliqué tôt" -#: agenda_culturel/models.py:1308 +#: agenda_culturel/models.py:1381 msgid "Category applied to the event" msgstr "Catégorie appliquée à l'événement" -#: agenda_culturel/models.py:1313 +#: agenda_culturel/models.py:1386 msgid "Contained in the title" msgstr "Contenu dans le titre" -#: agenda_culturel/models.py:1314 +#: agenda_culturel/models.py:1387 msgid "Text contained in the event title" msgstr "Texte contenu dans le titre de l'événement" -#: agenda_culturel/models.py:1320 +#: agenda_culturel/models.py:1393 msgid "Exact title extract" msgstr "Extrait exact du titre" -#: agenda_culturel/models.py:1322 +#: agenda_culturel/models.py:1395 msgid "" "If checked, the extract will be searched for in the title using the exact " "form (capitals, accents)." @@ -556,19 +557,19 @@ msgstr "" "Si coché, l'extrait sera recherché dans le titre en utilisant la forme " "exacte (majuscules, accents)" -#: agenda_culturel/models.py:1328 +#: agenda_culturel/models.py:1401 msgid "Contained in the description" msgstr "Contenu dans la description" -#: agenda_culturel/models.py:1329 +#: agenda_culturel/models.py:1402 msgid "Text contained in the description" msgstr "Texte contenu dans la description" -#: agenda_culturel/models.py:1335 +#: agenda_culturel/models.py:1408 msgid "Exact description extract" msgstr "Extrait exact de description" -#: agenda_culturel/models.py:1337 +#: agenda_culturel/models.py:1410 msgid "" "If checked, the extract will be searched for in the description using the " "exact form (capitals, accents)." @@ -576,19 +577,19 @@ msgstr "" "Si coché, l'extrait sera recherché dans la description en utilisant la forme " "exacte (majuscules, accents)" -#: agenda_culturel/models.py:1343 +#: agenda_culturel/models.py:1416 msgid "Contained in the location" msgstr "Contenu dans la localisation" -#: agenda_culturel/models.py:1344 +#: agenda_culturel/models.py:1417 msgid "Text contained in the event location" msgstr "Texte contenu dans la localisation de l'événement" -#: agenda_culturel/models.py:1350 +#: agenda_culturel/models.py:1423 msgid "Exact location extract" msgstr "Extrait exact de localisation" -#: agenda_culturel/models.py:1352 +#: agenda_culturel/models.py:1425 msgid "" "If checked, the extract will be searched for in the location using the exact " "form (capitals, accents)." @@ -596,52 +597,52 @@ msgstr "" "Si coché, l'extrait sera recherché dans la localisation en utilisant la " "forme exacte (majuscules, accents)" -#: agenda_culturel/models.py:1358 +#: agenda_culturel/models.py:1431 msgid "Categorisation rule" msgstr "Règle de catégorisation" -#: agenda_culturel/models.py:1359 +#: agenda_culturel/models.py:1432 msgid "Categorisation rules" msgstr "Règles de catégorisation" -#: agenda_culturel/models.py:1421 agenda_culturel/models.py:1453 +#: agenda_culturel/models.py:1494 agenda_culturel/models.py:1526 msgid "Question" msgstr "Question" -#: agenda_culturel/models.py:1422 agenda_culturel/models.py:1460 +#: agenda_culturel/models.py:1495 agenda_culturel/models.py:1533 msgid "Text that will be shown to moderators" msgstr "Text tel que présenté aux modérateurices" -#: agenda_culturel/models.py:1428 +#: agenda_culturel/models.py:1501 msgid "Moderation question" msgstr "Question de modération" -#: agenda_culturel/models.py:1429 +#: agenda_culturel/models.py:1502 msgid "Moderation questions" msgstr "Questions de modération" -#: agenda_culturel/models.py:1454 +#: agenda_culturel/models.py:1527 msgid "Associated question from moderation" msgstr "Question associée pour la modération" -#: agenda_culturel/models.py:1459 +#: agenda_culturel/models.py:1532 msgid "Answer" msgstr "Réponse" -#: agenda_culturel/models.py:1466 +#: agenda_culturel/models.py:1539 msgid "Adds tags" msgstr "Ajoute les étiquettes" -#: agenda_culturel/models.py:1467 +#: agenda_culturel/models.py:1540 msgid "A list of tags that will be added if you choose this answer." msgstr "" "Une liste d'étiquettes qui seront ajoutées si vous choisissez cette réponse." -#: agenda_culturel/models.py:1473 +#: agenda_culturel/models.py:1546 msgid "Removes tags" msgstr "Retire les étiquettes" -#: agenda_culturel/models.py:1474 +#: agenda_culturel/models.py:1547 msgid "A list of tags that will be removed if you choose this answer." msgstr "" "Une liste d'étiquettes qui seront retirées si vous choisissez cette réponse." @@ -654,47 +655,39 @@ msgstr "anglais" msgid "French" msgstr "français" -#: agenda_culturel/views.py:88 +#: agenda_culturel/views.py:126 msgid "Recurrent import name" msgstr "Nome de l'import récurrent" -#: agenda_culturel/views.py:89 +#: agenda_culturel/views.py:127 msgid "Add another" msgstr "Ajouter un autre" -#: agenda_culturel/views.py:90 +#: agenda_culturel/views.py:128 msgid "Browse..." msgstr "Naviguer..." -#: agenda_culturel/views.py:91 -msgid "Naviguer..." -msgstr "" - -#: agenda_culturel/views.py:92 +#: agenda_culturel/views.py:129 msgid "No file selected." msgstr "Pas de fichier sélectionné." -#: agenda_culturel/views.py:373 +#: agenda_culturel/views.py:432 msgid "The static content has been successfully updated." msgstr "Le contenu statique a été modifié avec succès." -#: agenda_culturel/views.py:382 agenda_culturel/views.py:427 +#: agenda_culturel/views.py:441 agenda_culturel/views.py:486 msgid "The event has been successfully modified." msgstr "L'événement a été modifié avec succès." -#: agenda_culturel/views.py:396 +#: agenda_culturel/views.py:455 msgid "The event has been successfully deleted." msgstr "L'événement a été supprimé avec succès" -#: agenda_culturel/views.py:453 +#: agenda_culturel/views.py:511 msgid "The status has been successfully modified." msgstr "Le status a été modifié avec succès." -#: agenda_culturel/views.py:480 -msgid "The event is saved." -msgstr "L'événement est enregistré." - -#: agenda_culturel/views.py:486 +#: agenda_culturel/views.py:533 agenda_culturel/views.py:548 msgid "" "The event has been submitted and will be published as soon as it has been " "validated by the moderation team." @@ -702,88 +695,78 @@ msgstr "" "L'événement a été soumis et sera publié dès qu'il aura été validé par " "l'équipe de modération." -#: agenda_culturel/views.py:543 +#: agenda_culturel/views.py:542 +msgid "The event is saved." +msgstr "L'événement est enregistré." + +#: agenda_culturel/views.py:636 agenda_culturel/views.py:689 +msgid "{} has not been submitted since its already known: {}." +msgstr "{} n'a pas été soumis car il est déjà connu: {}." + +#: agenda_culturel/views.py:641 agenda_culturel/views.py:695 msgid "" -"The event has been successfully extracted, and you can now modify it if " -"necessary." +"{} has not been submitted since its already known and currently into " +"moderation process." msgstr "" -"L'événement a été extrait avec succès, vous pouvez maintenant le modifier " -"au besoin." +"{} n'a pas été soumis car il est déjà connu et en cours de modération" -#: agenda_culturel/views.py:559 -msgid "" -"Unable to extract an event from the proposed URL. Please use the form below " -"to submit the event." -msgstr "" -"Impossible d'extraire un événement depuis l'URL proposée. Veuillez utiliser " -"le formulaire ci-dessous pour soumettre l'événement." +#: agenda_culturel/views.py:652 +msgid "Integrating {} url(s) into our import process." +msgstr "Integration de {} url(s) dans notre processus d'import." -#: agenda_culturel/views.py:579 -msgid "This URL has already been submitted, and you can find the event below." -msgstr "" -"Cette URL a déjà été soumise, et vous trouverez l'événement ci-dessous." +#: agenda_culturel/views.py:702 +msgid "Integrating {} into our import process." +msgstr "Integration de {} dans notre processus d'import." -#: agenda_culturel/views.py:588 -msgid "This URL has already been submitted and is awaiting moderation." -msgstr "Cette URL a déjà été soumise, et est en attente de modération" - -#: agenda_culturel/views.py:595 -msgid "" -"This URL has already been submitted, but has not been selected for " -"publication by the moderation team." -msgstr "" -"Cette URL a déjà été soumise, mais n'a pas été retenue par l'équipe de " -"modération pour la publication." - -#: agenda_culturel/views.py:622 +#: agenda_culturel/views.py:765 msgid "Your message has been sent successfully." msgstr "Votre message a été envoyé avec succès." -#: agenda_culturel/views.py:639 +#: agenda_culturel/views.py:782 msgid "The contact message properties has been successfully modified." msgstr "Les propriétés du message de contact ont été modifié avec succès." -#: agenda_culturel/views.py:655 +#: agenda_culturel/views.py:798 msgid "Open" msgstr "Ouvert" -#: agenda_culturel/views.py:711 +#: agenda_culturel/views.py:854 msgid "Search" msgstr "Rechercher" -#: agenda_culturel/views.py:881 +#: agenda_culturel/views.py:1038 msgid "The import has been run successfully." msgstr "L'import a été lancé avec succès" -#: agenda_culturel/views.py:900 +#: agenda_culturel/views.py:1057 msgid "The import has been canceled." msgstr "L'import a été annulé" -#: agenda_culturel/views.py:949 +#: agenda_culturel/views.py:1106 msgid "The recurrent import has been successfully modified." msgstr "L'import récurrent a été modifié avec succès." -#: agenda_culturel/views.py:958 +#: agenda_culturel/views.py:1115 msgid "The recurrent import has been successfully deleted." msgstr "L'import récurrent a été supprimé avec succès" -#: agenda_culturel/views.py:998 +#: agenda_culturel/views.py:1155 msgid "The import has been launched." msgstr "L'import a été lancé" -#: agenda_culturel/views.py:1015 +#: agenda_culturel/views.py:1172 msgid "Imports has been launched." msgstr "Les imports ont été lancés" -#: agenda_culturel/views.py:1089 +#: agenda_culturel/views.py:1249 msgid "The merge has been successfully completed." msgstr "La fusion a été réalisée avec succès." -#: agenda_culturel/views.py:1123 +#: agenda_culturel/views.py:1283 msgid "Events have been marked as unduplicated." msgstr "Les événements ont été marqués comme non dupliqués." -#: agenda_culturel/views.py:1145 +#: agenda_culturel/views.py:1305 msgid "" "The selected event has been retained, while the other has been moved to the " "recycle bin." @@ -791,7 +774,7 @@ msgstr "" "L'événement sélectionné a été conservé, l'autre a été déplacé dans la " "corbeille." -#: agenda_culturel/views.py:1152 +#: agenda_culturel/views.py:1312 msgid "" "The selected event has been retained, while the others have been moved to " "the recycle bin." @@ -799,19 +782,19 @@ msgstr "" "L'événement sélectionné a été conservé, les autres ont été déplacés dans la " "corbeille." -#: agenda_culturel/views.py:1163 +#: agenda_culturel/views.py:1323 msgid "The event has been withdrawn from the group and made independent." msgstr "L'événement a été retiré du groupe et rendu indépendant." -#: agenda_culturel/views.py:1196 +#: agenda_culturel/views.py:1356 msgid "Cleaning up duplicates: {} item(s) removed." msgstr "Nettoyage des dupliqués: {} élément(s) supprimés." -#: agenda_culturel/views.py:1240 +#: agenda_culturel/views.py:1400 msgid "The event was successfully duplicated." msgstr "L'événement a été marqué dupliqué avec succès." -#: agenda_culturel/views.py:1248 +#: agenda_culturel/views.py:1408 msgid "" "The event has been successfully flagged as a duplicate. The moderation team " "will deal with your suggestion shortly." @@ -819,62 +802,62 @@ msgstr "" "L'événement a été signalé comme dupliqué avec succès. Votre suggestion sera " "prochainement prise en charge par l'équipe de modération." -#: agenda_culturel/views.py:1301 +#: agenda_culturel/views.py:1461 msgid "The categorisation rule has been successfully modified." msgstr "La règle de catégorisation a été modifiée avec succès." -#: agenda_culturel/views.py:1310 +#: agenda_culturel/views.py:1470 msgid "The categorisation rule has been successfully deleted." msgstr "La règle de catégorisation a été supprimée avec succès" -#: agenda_culturel/views.py:1333 agenda_culturel/views.py:1380 +#: agenda_culturel/views.py:1493 agenda_culturel/views.py:1540 msgid "The rules were successfully applied and 1 event was categorised." msgstr "" "Les règles ont été appliquées avec succès et 1 événement a été catégorisé" -#: agenda_culturel/views.py:1340 agenda_culturel/views.py:1387 +#: agenda_culturel/views.py:1500 agenda_culturel/views.py:1547 msgid "The rules were successfully applied and {} events were categorised." msgstr "" "Les règles ont été appliquées avec succès et {} événements ont été " "catégorisés" -#: agenda_culturel/views.py:1347 agenda_culturel/views.py:1394 +#: agenda_culturel/views.py:1507 agenda_culturel/views.py:1554 msgid "The rules were successfully applied and no events were categorised." msgstr "" "Les règles ont été appliquées avec succès et aucun événement n'a été " "catégorisé" -#: agenda_culturel/views.py:1434 +#: agenda_culturel/views.py:1594 msgid "The moderation question has been created with success." msgstr "La question de modération a été créée avec succès." -#: agenda_culturel/views.py:1540 agenda_culturel/views.py:1602 -#: agenda_culturel/views.py:1640 +#: agenda_culturel/views.py:1706 agenda_culturel/views.py:1768 +#: agenda_culturel/views.py:1806 msgid "{} events have been updated." msgstr "{} événements ont été mis à jour." -#: agenda_culturel/views.py:1543 agenda_culturel/views.py:1604 -#: agenda_culturel/views.py:1643 +#: agenda_culturel/views.py:1709 agenda_culturel/views.py:1770 +#: agenda_culturel/views.py:1809 msgid "1 event has been updated." msgstr "1 événement a été mis à jour" -#: agenda_culturel/views.py:1545 agenda_culturel/views.py:1606 -#: agenda_culturel/views.py:1645 +#: agenda_culturel/views.py:1711 agenda_culturel/views.py:1772 +#: agenda_culturel/views.py:1811 msgid "No events have been modified." msgstr "Aucun événement n'a été modifié." -#: agenda_culturel/views.py:1554 +#: agenda_culturel/views.py:1720 msgid "The place has been successfully updated." msgstr "Le lieu a été modifié avec succès." -#: agenda_culturel/views.py:1563 +#: agenda_culturel/views.py:1729 msgid "The place has been successfully created." msgstr "Le lieu a été créé avec succès." -#: agenda_culturel/views.py:1628 +#: agenda_culturel/views.py:1794 msgid "The selected place has been assigned to the event." msgstr "Le lieu sélectionné a été assigné à l'événement." -#: agenda_culturel/views.py:1632 +#: agenda_culturel/views.py:1798 msgid "A new alias has been added to the selected place." msgstr "Un nouvel alias a été créé pour le lieu sélectionné." diff --git a/src/agenda_culturel/static/images/merci.svg b/src/agenda_culturel/static/images/merci.svg new file mode 100644 index 0000000..53f1686 --- /dev/null +++ b/src/agenda_culturel/static/images/merci.svg @@ -0,0 +1,181 @@ + + + + diff --git a/src/agenda_culturel/templates/agenda_culturel/event_import.html b/src/agenda_culturel/templates/agenda_culturel/event_import.html index 26bd6a2..b09b733 100644 --- a/src/agenda_culturel/templates/agenda_culturel/event_import.html +++ b/src/agenda_culturel/templates/agenda_culturel/event_import.html @@ -23,7 +23,8 @@

On peut importer automatiquement un événement depuis d'autres sites internet (principalement depuis Facebook pour l'instant), à partir de l'adresse (url) de la page de l'événement.

- Importer depuis une url + Importer un événement depuis son url + Importer des événements depuis leurs urls

Si l'événement n'est pas disponible en ligne, ou si l'import ne fonctionne pas, on peut ajouter un événement en utilisant un formulaire complet. diff --git a/src/agenda_culturel/templates/agenda_culturel/import.html b/src/agenda_culturel/templates/agenda_culturel/import.html index 92318fb..d093b7d 100644 --- a/src/agenda_culturel/templates/agenda_culturel/import.html +++ b/src/agenda_culturel/templates/agenda_culturel/import.html @@ -4,20 +4,6 @@ {% load static %} -{% block entete_header %} - - - - - - - - - - - -{% endblock %} - {% block fluid %}{% endblock %} @@ -26,7 +12,7 @@

Importer un événement

- {% url 'event_import_form' as local_url %} + {% url 'event_import_url' as local_url %} {% include "agenda_culturel/static_content.html" with name="import" url_path=local_url %}
@@ -34,15 +20,13 @@ {% csrf_token %} {{ form.media }} {{ form.as_p }} - + +

Si tu as plein d'événements à ajouter, tu peux les ajouter par lots.

-

Si l'import automatique ne marche pas, ou si l'événement n'est pas en ligne, vous pouvez + +

Si l'import automatique ne marche pas, ou si l'événement n'est pas en ligne, tu peux tout de même ajouter l'événement en le décrivant sur la page d'ajout d'événement.

- -
- Veuillez patienter, lien en cours d'importation... -
-
+ {% endblock %} diff --git a/src/agenda_culturel/templates/agenda_culturel/import_set.html b/src/agenda_culturel/templates/agenda_culturel/import_set.html new file mode 100644 index 0000000..04052a9 --- /dev/null +++ b/src/agenda_culturel/templates/agenda_culturel/import_set.html @@ -0,0 +1,38 @@ +{% extends "agenda_culturel/page.html" %} + +{% block title %}Importer un ensemble d'événements{% endblock %} + +{% load static %} + + + +{% block fluid %}{% endblock %} + + +{% block content %} + +
+
+

Importer un ensemble d'événements

+ {% url 'event_import_urls' as local_url %} + {% include "agenda_culturel/static_content.html" with name="import_set" url_path=local_url %} +
+
+ {{ formset.management_form }} + {% csrf_token %} + {% for form in formset %} +

Nouvel événement #{{ forloop.counter }}

+ {{ form.as_p }} + {% endfor %} + +
+ +

Si l'import automatique ne marche pas, ou si l'événement n'est pas en ligne, vous pouvez + tout de même ajouter l'événement en le décrivant sur la page d'ajout d'événement.

+
+ +
+ Veuillez patienter, lien en cours d'importation... +
+
+{% endblock %} diff --git a/src/agenda_culturel/templates/agenda_culturel/thank_you.html b/src/agenda_culturel/templates/agenda_culturel/thank_you.html new file mode 100644 index 0000000..b8984a2 --- /dev/null +++ b/src/agenda_culturel/templates/agenda_culturel/thank_you.html @@ -0,0 +1,32 @@ +{% extends "agenda_culturel/page.html" %} + +{% block title %}Merci !{% endblock %} + +{% load static %} + +{% block entete_header %} + +{% endblock %} + +{% block fluid %}{% endblock %} + + +{% block content %} + +
+
+

Merci !

+ {% url 'thank_you' as local_url %} +
+
+
quelques pommes et leur pépins
+
+ {% include "agenda_culturel/static_content.html" with name="thank-you" url_path=local_url %} + +
+ +
+
+{% endblock %} diff --git a/src/agenda_culturel/urls.py b/src/agenda_culturel/urls.py index c550fa1..ab8a303 100644 --- a/src/agenda_culturel/urls.py +++ b/src/agenda_culturel/urls.py @@ -39,6 +39,7 @@ urlpatterns = [ path("event//moderate", EventModerateView.as_view(), name="moderate_event"), path("ajouter", import_event_proxy, name="add_event"), path("ajouter/url", import_from_url, name="add_event_url"), + path("ajouter/urls", import_from_urls, name="add_event_urls"), path("ajouter/details", EventCreateView.as_view(), name="add_event_details"), path("admin/", admin.site.urls), path("accounts/", include("django.contrib.auth.urls")), @@ -57,6 +58,7 @@ urlpatterns = [ path("rechercher/complet/", event_search_full, name="event_search_full"), path("mentions-legales", mentions_legales, name="mentions_legales"), path("a-propos", about, name="about"), + path("merci", thank_you, name="thank_you"), path("contact", ContactMessageCreateView.as_view(), name="contact"), path("contactmessages", contactmessages, name="contactmessages"), path( diff --git a/src/agenda_culturel/views.py b/src/agenda_culturel/views.py index aae17cc..717c77d 100644 --- a/src/agenda_culturel/views.py +++ b/src/agenda_culturel/views.py @@ -14,6 +14,8 @@ from django.http import HttpResponseRedirect, HttpResponse from django.urls import reverse from collections import Counter +from django.forms import formset_factory + from .forms import ( URLSubmissionForm, EventForm, @@ -46,6 +48,7 @@ from .models import ( Place, ) from django.utils import timezone +from django.utils.html import escape from datetime import date, timedelta from django.db.models import Q @@ -69,6 +72,7 @@ from .celery import ( import_events_from_json, run_recurrent_import, run_all_recurrent_imports, + import_events_from_urls, ) import urllib @@ -122,7 +126,6 @@ to_be_translated = [ _("Recurrent import name"), _("Add another"), _("Browse..."), - _("Naviguer..."), _("No file selected."), ] @@ -141,6 +144,9 @@ def page_not_found(request, exception=None): def internal_server_error(request): return render(request, "page-erreur.html", status=500, context={"error": 500}) +def thank_you(request): + return render(request, "agenda_culturel/thank_you.html") + class CategoryCheckboxSelectMultiple(forms.CheckboxSelectMultiple): template_name = "agenda_culturel/forms/category-checkbox.html" @@ -548,155 +554,162 @@ def import_from_details(request): request, "agenda_culturel/event_form.html", context={"form": form} ) +# A class to evaluate the URL according to the existing events and the authentification +# level of the user +class URLEventEvaluation: -def import_from_url(request): - import logging + def __init__(self, form, is_authenticated): + self.form = form + self.is_authenticated = is_authenticated - logging.getLogger(__name__) + self.cat = None + self.existing = None + self.url = form.cleaned_data.get('url') + self.event = None + if self.url is not None: + self.url = Extractor.clean_url(self.url) + # we check if the url is known + self.existing = Event.objects.filter(uuids__contains=[self.url]) + # if it's unknown + if len(self.existing) == 0: + self.existing = None + self.cat = form.cleaned_data.get('category') + if self.cat is not None: + self.cat = self.cat.name - # if a form has been sent and contains an event - if request.method == "POST" and "title" in request.POST: - # the result of this form is checked - form = EventForm(request.POST, is_authenticated=request.user.is_authenticated) - if form.is_valid(): - new_event = form.save() - if request.user.is_authenticated: - messages.success(request, _("The event is saved.")) - return HttpResponseRedirect(new_event.get_absolute_url()) else: - messages.success( - request, - _( - "The event has been submitted and will be published as soon as it has been validated by the moderation team." - ), - ) - return HttpResponseRedirect(reverse("home")) - else: - return render( - request, "agenda_culturel/event_form.html", context={"form": form} - ) + published = [ + e for e in self.existing if e.status == Event.STATUS.PUBLISHED + ] + drafts = [e for e in self.existing if e.status == Event.STATUS.DRAFT] + trash = [e for e in self.existing if e.status == Event.STATUS.TRASH] - else: - form = URLSubmissionForm() - - initial = { - "start_day": date.today() + timedelta(days=1), - "start_time": "20:00", - "end_time": "22:00", - } - - form_event = EventForm(initial=initial) - - # if the form has been sent - if request.method == "POST": - form = URLSubmissionForm(request.POST) - - # if the form is valid - if form.is_valid(): - # the url is cleaned - cd = form.cleaned_data - url = cd.get("url") - - url = Extractor.clean_url(url) - - # we check if the url is known - existing = Event.objects.filter(uuids__contains=[url]) - # if it's unknown - if len(existing) == 0: - event = None - # we import it - logger.warning('on url2event') - u2e = URL2Events(ChromiumHeadlessDownloader(), single_event=True) - events_structure = u2e.process( - url, published=request.user.is_authenticated - ) - if ( - events_structure is not None - and "events" in events_structure - and len(events_structure["events"]) > 0 - ): - event = Event.from_structure( - events_structure["events"][0], - events_structure["header"]["url"], - ) - - # add a category if the user selected one - if event.category is None or event.category == Category.get_default_category(): - if cd.get("category") is not None: - event.category = cd.get("category") - - # TODO: use celery to import the other events - - if event is not None: - event.save() - form = EventForm( - instance=event, - is_authenticated=request.user.is_authenticated, - ) - messages.success( - request, - _( - "The event has been successfully extracted, and you can now modify it if necessary." - ), - ) - return render( - request, - "agenda_culturel/event_form.html", - context={"form": form, "from_import": True}, - ) - else: - form = EventForm( - initial={"reference_urls": [url]}, - is_authenticated=request.user.is_authenticated, - ) - messages.error( - request, - _( - "Unable to extract an event from the proposed URL. Please use the form below to submit the event." - ), - ) - return render( - request, - "agenda_culturel/import.html", - context={"form": form, "form_event": form_event}, - ) + if self.is_authenticated or len(published) > 1: + self.event = published[0] if len(published) > 1 else self.existing[0] else: - published = [ - e for e in existing if e.status == Event.STATUS.PUBLISHED - ] - drafts = [e for e in existing if e.status == Event.STATUS.DRAFT] - trash = [e for e in existing if e.status == Event.STATUS.TRASH] + self.event = None - if request.user.is_authenticated or len(published) > 1: - event = published[0] if len(published) > 1 else existing[0] + def exists(self): + return self.url is not None + + def is_new(self): + return self.exists() and self.existing is None + + def is_event_visible(self): + if not self.is_new(): + return False + return self.event is not None + + def get_event(self): + if self.event is None: + return None + else: + return self.event + + def get_link(self): + e = self.get_event() + if e is None: + return "" + else: + return '' + escape(e.title) + '' + + def to_list(self): + if self.is_new(): + return (self.url, self.cat) + + +def import_from_urls(request): + URLSubmissionFormSet = formset_factory(URLSubmissionForm, extra=10, min_num=1) + + if request.method == "POST": + formset = URLSubmissionFormSet(request.POST, request.FILES) + if formset.is_valid(): + # evaluate all the forms + ucat = [URLEventEvaluation(form, request.user.is_authenticated) for form in formset.forms] + + # for each not new, add a message + for uc in ucat: + if uc.exists() and not uc.is_new(): + if uc.is_event_visible(): messages.info( request, - _( - "This URL has already been submitted, and you can find the event below." - ), + _('{} has not been submitted since it''s already known: {}.').format(uc.url).format(uc.get_link()) ) - return HttpResponseRedirect(event.get_absolute_url()) else: - if len(drafts) > 0: - messages.info( - request, - _( - "This URL has already been submitted and is awaiting moderation." - ), - ) - elif len(trash) > 0: - messages.info( - request, - _( - "This URL has already been submitted, but has not been selected for publication by the moderation team." - ), - ) + messages.info( + request, + _('{} has not been submitted since it''s already known and currently into moderation process.').format(uc.url) + ) - return render( - request, - "agenda_culturel/import.html", - context={"form": form, "form_event": form_event}, - ) + # keep only new ones + ucat = [uc.to_list() for uc in ucat if uc.is_new()] + + # finally process them or go back to home page + if len(ucat) > 0: + logger.warning(ucat) + messages.info( + request, + _('Integrating {} url(s) into our import process.').format(len(ucat)) + ) + import_events_from_urls.delay(ucat) + return HttpResponseRedirect(reverse("thank_you")) + else: + return HttpResponseRedirect(reverse("home")) + + else: + formset = URLSubmissionFormSet() + + return render(request, "agenda_culturel/import_set.html", context={"formset": formset}) + + +def import_from_url(request): + + form = URLSubmissionForm() + + initial = { + "start_day": date.today() + timedelta(days=1), + "start_time": "20:00", + "end_time": "22:00", + } + + form_event = EventForm(initial=initial) + + # if the form has been sent + if request.method == "POST": + form = URLSubmissionForm(request.POST) + + # if the form is valid + if form.is_valid(): + uc = URLEventEvaluation(form, request.user.is_authenticated) + + if uc.exists() and not uc.is_new(): + if uc.is_event_visible(): + messages.info( + request, + _('{} has not been submitted since it''s already known: {}.').format(uc.url).format(uc.get_link()) + ) + return HttpResponseRedirect(uc.get_event().get_absolute_url()) + else: + messages.info( + request, + _('{} has not been submitted since it''s already known and currently into moderation process.').format(uc.url) + ) + return HttpResponseRedirect(reverse("home")) + + else: + messages.info( + request, + _('Integrating {} into our import process.').format(uc.url) + ) + import_events_from_urls.delay([uc.to_list()]) + return HttpResponseRedirect(reverse("thank_you")) + + + return render( + request, + "agenda_culturel/import.html", + context={"form": form, "form_event": form_event}, + ) def export_event_ical(request, year, month, day, pk):