make format
This commit is contained in:
parent
b2a4df5be7
commit
4f80d00485
@ -76,11 +76,11 @@ class DayInCalendar:
|
|||||||
def _add_event_internal(self, event):
|
def _add_event_internal(self, event):
|
||||||
self.events.append(event)
|
self.events.append(event)
|
||||||
if event.category is None:
|
if event.category is None:
|
||||||
if not "" in self.events_by_category:
|
if "" not in self.events_by_category:
|
||||||
self.events_by_category[""] = []
|
self.events_by_category[""] = []
|
||||||
self.events_by_category[""].append(event)
|
self.events_by_category[""].append(event)
|
||||||
else:
|
else:
|
||||||
if not event.category.name in self.events_by_category:
|
if event.category.name not in self.events_by_category:
|
||||||
self.events_by_category[event.category.name] = []
|
self.events_by_category[event.category.name] = []
|
||||||
self.events_by_category[event.category.name].append(event)
|
self.events_by_category[event.category.name].append(event)
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ def close_import_task(taskid, success, error_message, importer):
|
|||||||
|
|
||||||
@app.task(bind=True)
|
@app.task(bind=True)
|
||||||
def import_events_from_json(self, json):
|
def import_events_from_json(self, json):
|
||||||
from agenda_culturel.models import Event, BatchImportation
|
from agenda_culturel.models import BatchImportation
|
||||||
from .db_importer import DBImporterEvents
|
from .db_importer import DBImporterEvents
|
||||||
|
|
||||||
# create a batch importation
|
# create a batch importation
|
||||||
@ -78,7 +78,6 @@ def import_events_from_json(self, json):
|
|||||||
def run_recurrent_import(self, pk):
|
def run_recurrent_import(self, pk):
|
||||||
from agenda_culturel.models import RecurrentImport, BatchImportation
|
from agenda_culturel.models import RecurrentImport, BatchImportation
|
||||||
from .db_importer import DBImporterEvents
|
from .db_importer import DBImporterEvents
|
||||||
from django.shortcuts import get_object_or_404
|
|
||||||
|
|
||||||
logger.info("Run recurrent import: {}".format(self.request.id))
|
logger.info("Run recurrent import: {}".format(self.request.id))
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
from agenda_culturel.models import Event
|
from agenda_culturel.models import Event
|
||||||
import json
|
import json
|
||||||
from datetime import datetime
|
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
@ -44,9 +43,9 @@ class DBImporterEvents:
|
|||||||
except:
|
except:
|
||||||
return (False, "JSON file is not correctly structured")
|
return (False, "JSON file is not correctly structured")
|
||||||
|
|
||||||
if not "header" in structure:
|
if "header" not in structure:
|
||||||
return (False, "JSON is not correctly structured: missing header")
|
return (False, "JSON is not correctly structured: missing header")
|
||||||
if not "events" in structure:
|
if "events" not in structure:
|
||||||
return (False, "JSON is not correctly structured: missing events")
|
return (False, "JSON is not correctly structured: missing events")
|
||||||
|
|
||||||
if "url" in structure["header"]:
|
if "url" in structure["header"]:
|
||||||
|
@ -14,12 +14,10 @@ from django.forms import (
|
|||||||
HiddenInput,
|
HiddenInput,
|
||||||
ModelChoiceField,
|
ModelChoiceField,
|
||||||
)
|
)
|
||||||
from datetime import date
|
|
||||||
from django_better_admin_arrayfield.forms.widgets import DynamicArrayWidget
|
from django_better_admin_arrayfield.forms.widgets import DynamicArrayWidget
|
||||||
|
|
||||||
from .models import (
|
from .models import (
|
||||||
Event,
|
Event,
|
||||||
BatchImportation,
|
|
||||||
RecurrentImport,
|
RecurrentImport,
|
||||||
CategorisationRule,
|
CategorisationRule,
|
||||||
ModerationAnswer,
|
ModerationAnswer,
|
||||||
@ -327,7 +325,7 @@ class MergeDuplicates(Form):
|
|||||||
|
|
||||||
def get_selected_events_id(self, key):
|
def get_selected_events_id(self, key):
|
||||||
value = self.cleaned_data.get(key)
|
value = self.cleaned_data.get(key)
|
||||||
if not key in self.fields:
|
if key not in self.fields:
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
if isinstance(value, list):
|
if isinstance(value, list):
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
from ..generic_extractors import *
|
from ..generic_extractors import *
|
||||||
import re
|
|
||||||
import json5
|
import json5
|
||||||
from datetime import timedelta
|
|
||||||
|
|
||||||
|
|
||||||
# A class dedicated to get events from La Coopérative de Mai:
|
# A class dedicated to get events from La Coopérative de Mai:
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
from ..generic_extractors import *
|
from ..generic_extractors import *
|
||||||
import re
|
import re
|
||||||
import json5
|
import json5
|
||||||
from datetime import timedelta
|
|
||||||
|
|
||||||
|
|
||||||
# A class dedicated to get events from La Coopérative de Mai:
|
# A class dedicated to get events from La Coopérative de Mai:
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
from ..generic_extractors import *
|
from ..generic_extractors import *
|
||||||
import re
|
import re
|
||||||
import json5
|
|
||||||
from datetime import timedelta
|
|
||||||
|
|
||||||
|
|
||||||
# A class dedicated to get events from La puce à l'oreille
|
# A class dedicated to get events from La puce à l'oreille
|
||||||
|
@ -1,7 +1,4 @@
|
|||||||
from ..generic_extractors import *
|
from ..generic_extractors import *
|
||||||
import re
|
|
||||||
import json5
|
|
||||||
from datetime import timedelta
|
|
||||||
|
|
||||||
|
|
||||||
# A class dedicated to get events from Le Fotomat'
|
# A class dedicated to get events from Le Fotomat'
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
from urllib.parse import urlparse, urlencode
|
from urllib.parse import urlencode
|
||||||
import urllib.request
|
import urllib.request
|
||||||
import os
|
import os
|
||||||
from selenium import webdriver
|
from selenium import webdriver
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from bs4 import BeautifulSoup
|
|
||||||
from datetime import datetime, time, date, timedelta
|
from datetime import datetime, time, date, timedelta
|
||||||
import re
|
import re
|
||||||
import unicodedata
|
import unicodedata
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
import icalendar
|
from datetime import datetime
|
||||||
import warnings
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
from datetime import datetime, date
|
|
||||||
from bs4 import BeautifulSoup, MarkupResemblesLocatorWarning
|
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
from .extractor import *
|
from .extractor import *
|
||||||
@ -182,7 +179,7 @@ class FacebookEventExtractor(Extractor):
|
|||||||
return event
|
return event
|
||||||
|
|
||||||
def build_event(self, url):
|
def build_event(self, url):
|
||||||
image = self.get_element("image")
|
self.get_element("image")
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"title": self.get_element("name"),
|
"title": self.get_element("name"),
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
import icalendar
|
import icalendar
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
from icalendar import vDatetime
|
|
||||||
import bbcode
|
import bbcode
|
||||||
|
|
||||||
from datetime import datetime, date, timedelta
|
from datetime import datetime, date, timedelta
|
||||||
from bs4 import BeautifulSoup, MarkupResemblesLocatorWarning
|
from bs4 import BeautifulSoup, MarkupResemblesLocatorWarning
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
from .extractor import *
|
from .extractor import *
|
||||||
|
|
||||||
|
@ -63,34 +63,34 @@ class TwoStepsExtractor(Extractor):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def add_event_start_day(self, url, start_day):
|
def add_event_start_day(self, url, start_day):
|
||||||
if not url in self.event_properties:
|
if url not in self.event_properties:
|
||||||
self.event_properties[url] = {}
|
self.event_properties[url] = {}
|
||||||
self.event_properties[url]["start_day"] = start_day
|
self.event_properties[url]["start_day"] = start_day
|
||||||
|
|
||||||
def add_event_start_time(self, url, start_time):
|
def add_event_start_time(self, url, start_time):
|
||||||
if not url in self.event_properties:
|
if url not in self.event_properties:
|
||||||
self.event_properties[url] = {}
|
self.event_properties[url] = {}
|
||||||
self.event_properties[url]["start_time"] = start_time
|
self.event_properties[url]["start_time"] = start_time
|
||||||
|
|
||||||
def add_event_title(self, url, title):
|
def add_event_title(self, url, title):
|
||||||
if not url in self.event_properties:
|
if url not in self.event_properties:
|
||||||
self.event_properties[url] = {}
|
self.event_properties[url] = {}
|
||||||
self.event_properties[url]["title"] = title
|
self.event_properties[url]["title"] = title
|
||||||
|
|
||||||
def add_event_tag(self, url, tag):
|
def add_event_tag(self, url, tag):
|
||||||
if not url in self.event_properties:
|
if url not in self.event_properties:
|
||||||
self.event_properties[url] = {}
|
self.event_properties[url] = {}
|
||||||
if not "tags" in self.event_properties[url]:
|
if "tags" not in self.event_properties[url]:
|
||||||
self.event_properties[url]["tags"] = []
|
self.event_properties[url]["tags"] = []
|
||||||
self.event_properties[url]["tags"].append(tag)
|
self.event_properties[url]["tags"].append(tag)
|
||||||
|
|
||||||
def add_event_category(self, url, cat):
|
def add_event_category(self, url, cat):
|
||||||
if not url in self.event_properties:
|
if url not in self.event_properties:
|
||||||
self.event_properties[url] = {}
|
self.event_properties[url] = {}
|
||||||
self.event_properties[url]["category"] = cat
|
self.event_properties[url]["category"] = cat
|
||||||
|
|
||||||
def add_event_location(self, url, loc):
|
def add_event_location(self, url, loc):
|
||||||
if not url in self.event_properties:
|
if url not in self.event_properties:
|
||||||
self.event_properties[url] = {}
|
self.event_properties[url] = {}
|
||||||
self.event_properties[url]["location"] = loc
|
self.event_properties[url]["location"] = loc
|
||||||
|
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
import os
|
|
||||||
|
|
||||||
from .downloader import *
|
from .downloader import *
|
||||||
from .extractor import *
|
from .extractor import *
|
||||||
|
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
# Create groups for several tasks
|
# Create groups for several tasks
|
||||||
|
|
||||||
from django.db import migrations
|
from django.db import migrations
|
||||||
from django.contrib.auth.management import create_permissions
|
from django.contrib.auth.models import Group
|
||||||
from django.contrib.auth.models import Group, Permission
|
|
||||||
|
|
||||||
|
|
||||||
def groups_permissions_creation(apps, schema_editor):
|
def groups_permissions_creation(apps, schema_editor):
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
from django.db import migrations
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
from django.contrib.auth.management import create_permissions
|
|
||||||
from django.contrib.auth.models import Group, Permission
|
from django.contrib.auth.models import Group, Permission
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
# Generated by Django 4.2.7 on 2024-04-03 17:24
|
# Generated by Django 4.2.7 on 2024-04-03 17:24
|
||||||
|
|
||||||
from django.db import migrations
|
from django.db import migrations
|
||||||
from django.contrib.auth.management import create_permissions
|
|
||||||
from django.contrib.auth.models import Group, Permission
|
from django.contrib.auth.models import Group, Permission
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
# Generated by Django 4.2.7 on 2024-04-17 10:12
|
# Generated by Django 4.2.7 on 2024-04-17 10:12
|
||||||
|
|
||||||
from django.db import migrations
|
from django.db import migrations
|
||||||
from django.contrib.auth.management import create_permissions
|
|
||||||
from django.contrib.auth.models import Group, Permission
|
from django.contrib.auth.models import Group, Permission
|
||||||
|
|
||||||
def update_groups_permissions(apps, schema_editor):
|
def update_groups_permissions(apps, schema_editor):
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
# Generated by Django 4.2.7 on 2024-04-27 16:29
|
# Generated by Django 4.2.7 on 2024-04-27 16:29
|
||||||
|
|
||||||
from django.db import migrations
|
from django.db import migrations
|
||||||
from django.contrib.auth.management import create_permissions
|
|
||||||
from django.contrib.auth.models import Group, Permission
|
from django.contrib.auth.models import Group, Permission
|
||||||
|
|
||||||
def update_groups_permissions(apps, schema_editor):
|
def update_groups_permissions(apps, schema_editor):
|
||||||
|
@ -930,7 +930,7 @@ class Event(models.Model):
|
|||||||
if self.uuids is None:
|
if self.uuids is None:
|
||||||
self.uuids = []
|
self.uuids = []
|
||||||
for uuid in other.uuids:
|
for uuid in other.uuids:
|
||||||
if not uuid in self.uuids:
|
if uuid not in self.uuids:
|
||||||
self.uuids.append(uuid)
|
self.uuids.append(uuid)
|
||||||
|
|
||||||
# Limitation: the given events should not be considered similar one to another...
|
# Limitation: the given events should not be considered similar one to another...
|
||||||
|
@ -2,7 +2,6 @@ from django import template
|
|||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
|
|
||||||
from agenda_culturel.models import Category
|
from agenda_culturel.models import Category
|
||||||
import statistics
|
|
||||||
import colorsys
|
import colorsys
|
||||||
from .utils_extra import *
|
from .utils_extra import *
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ from django.urls import reverse_lazy
|
|||||||
from django.template.defaultfilters import pluralize, linebreaks, urlize
|
from django.template.defaultfilters import pluralize, linebreaks, urlize
|
||||||
|
|
||||||
|
|
||||||
from agenda_culturel.models import Event, Category
|
from agenda_culturel.models import Event
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
|
|
||||||
from .utils_extra import picto_from_name
|
from .utils_extra import picto_from_name
|
||||||
@ -22,14 +22,14 @@ def in_date(event, date):
|
|||||||
|
|
||||||
@register.filter
|
@register.filter
|
||||||
def can_show_start_time(event, day=None):
|
def can_show_start_time(event, day=None):
|
||||||
if not day is None and day == event.start_day:
|
if day is not None and day == event.start_day:
|
||||||
return True
|
return True
|
||||||
return event.start_time and (not event.end_day or event.end_day == event.start_day)
|
return event.start_time and (not event.end_day or event.end_day == event.start_day)
|
||||||
|
|
||||||
|
|
||||||
@register.filter
|
@register.filter
|
||||||
def can_show_end_time(event, day=None):
|
def can_show_end_time(event, day=None):
|
||||||
if not day is None and day == event.end_day and event.start_day != event.end_day:
|
if day is not None and day == event.end_day and event.start_day != event.end_day:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -126,6 +126,7 @@ def field_to_html(field, key):
|
|||||||
else:
|
else:
|
||||||
return field
|
return field
|
||||||
|
|
||||||
|
|
||||||
@register.filter
|
@register.filter
|
||||||
def add_url_category(url, c):
|
def add_url_category(url, c):
|
||||||
if c is None:
|
if c is None:
|
||||||
@ -133,4 +134,4 @@ def add_url_category(url, c):
|
|||||||
if url == "":
|
if url == "":
|
||||||
return "category=" + str(c.pk)
|
return "category=" + str(c.pk)
|
||||||
else:
|
else:
|
||||||
return url + "&category=" + str(c.pk)
|
return url + "&category=" + str(c.pk)
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
from django import template
|
from django import template
|
||||||
from django.utils.safestring import mark_safe
|
|
||||||
|
|
||||||
from agenda_culturel.models import StaticContent
|
from agenda_culturel.models import StaticContent
|
||||||
from django.db.models import Q
|
|
||||||
|
|
||||||
register = template.Library()
|
register = template.Library()
|
||||||
|
|
||||||
|
@ -2,8 +2,7 @@ from django.conf import settings
|
|||||||
from django.conf.urls.static import static
|
from django.conf.urls.static import static
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
|
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
|
||||||
from django.urls import path, include, re_path
|
from django.urls import path, include
|
||||||
from django.contrib.auth import views as auth_views
|
|
||||||
from django.views.i18n import JavaScriptCatalog
|
from django.views.i18n import JavaScriptCatalog
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
from django.shortcuts import render, get_object_or_404
|
from django.shortcuts import render, get_object_or_404
|
||||||
from django.views.generic import ListView, DetailView, FormView
|
from django.views.generic import ListView, DetailView
|
||||||
from django.views.generic.edit import CreateView, UpdateView, DeleteView
|
from django.views.generic.edit import CreateView, UpdateView, DeleteView
|
||||||
from django.contrib.auth.mixins import (
|
from django.contrib.auth.mixins import (
|
||||||
LoginRequiredMixin,
|
LoginRequiredMixin,
|
||||||
@ -9,11 +9,9 @@ from django.contrib.auth.mixins import (
|
|||||||
from django.http import QueryDict
|
from django.http import QueryDict
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.contrib.postgres.search import SearchQuery, SearchHeadline
|
from django.contrib.postgres.search import SearchQuery, SearchHeadline
|
||||||
from django.core.exceptions import PermissionDenied
|
|
||||||
|
|
||||||
from django.http import HttpResponseRedirect, HttpResponse, HttpResponseNotFound
|
from django.http import HttpResponseRedirect
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
import urllib
|
|
||||||
from collections import Counter
|
from collections import Counter
|
||||||
|
|
||||||
from .forms import (
|
from .forms import (
|
||||||
@ -48,13 +46,11 @@ from .models import (
|
|||||||
Place,
|
Place,
|
||||||
)
|
)
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from enum import StrEnum
|
|
||||||
from datetime import date, timedelta
|
from datetime import date, timedelta
|
||||||
from django.db.models import Q, F
|
from django.db.models import Q
|
||||||
|
|
||||||
from django.urls import reverse_lazy
|
from django.urls import reverse_lazy
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django.utils.translation import activate, get_language_info
|
|
||||||
import django_filters
|
import django_filters
|
||||||
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
|
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
|
||||||
from django.contrib.auth.decorators import login_required, permission_required
|
from django.contrib.auth.decorators import login_required, permission_required
|
||||||
@ -75,7 +71,6 @@ from .celery import (
|
|||||||
run_all_recurrent_imports,
|
run_all_recurrent_imports,
|
||||||
)
|
)
|
||||||
|
|
||||||
import unicodedata
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@ -429,7 +424,7 @@ class EventModerateView(
|
|||||||
template_name = "agenda_culturel/event_moderation_form.html"
|
template_name = "agenda_culturel/event_moderation_form.html"
|
||||||
|
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
mas = ModerationAnswer.objects.all()
|
ModerationAnswer.objects.all()
|
||||||
logger.warning("ON valide la forme")
|
logger.warning("ON valide la forme")
|
||||||
|
|
||||||
for f in form.cleaned_data:
|
for f in form.cleaned_data:
|
||||||
@ -470,7 +465,7 @@ def change_status_event(request, pk, status):
|
|||||||
def import_from_url(request):
|
def import_from_url(request):
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logging.getLogger(__name__)
|
||||||
|
|
||||||
if request.method == "POST" and "title" in request.POST:
|
if request.method == "POST" and "title" in request.POST:
|
||||||
form = EventForm(request.POST, is_authenticated=request.user.is_authenticated)
|
form = EventForm(request.POST, is_authenticated=request.user.is_authenticated)
|
||||||
@ -532,7 +527,7 @@ def import_from_url(request):
|
|||||||
)
|
)
|
||||||
# TODO: use celery to import the other events
|
# TODO: use celery to import the other events
|
||||||
|
|
||||||
if event != None:
|
if event is not None:
|
||||||
form = EventForm(
|
form = EventForm(
|
||||||
instance=event,
|
instance=event,
|
||||||
is_authenticated=request.user.is_authenticated,
|
is_authenticated=request.user.is_authenticated,
|
||||||
@ -876,7 +871,7 @@ def add_import(request):
|
|||||||
form = BatchImportationForm(request.POST)
|
form = BatchImportationForm(request.POST)
|
||||||
|
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
result = import_events_from_json.delay(form.data["json"])
|
import_events_from_json.delay(form.data["json"])
|
||||||
|
|
||||||
messages.success(request, _("The import has been run successfully."))
|
messages.success(request, _("The import has been run successfully."))
|
||||||
return HttpResponseRedirect(reverse_lazy("imports"))
|
return HttpResponseRedirect(reverse_lazy("imports"))
|
||||||
@ -993,7 +988,7 @@ def run_rimport(request, pk):
|
|||||||
|
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
# run recurrent import
|
# run recurrent import
|
||||||
result = run_recurrent_import.delay(pk)
|
run_recurrent_import.delay(pk)
|
||||||
|
|
||||||
messages.success(request, _("The import has been launched."))
|
messages.success(request, _("The import has been launched."))
|
||||||
return HttpResponseRedirect(reverse_lazy("view_rimport", args=[pk]))
|
return HttpResponseRedirect(reverse_lazy("view_rimport", args=[pk]))
|
||||||
@ -1010,7 +1005,7 @@ def run_rimport(request, pk):
|
|||||||
def run_all_rimports(request):
|
def run_all_rimports(request):
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
# run recurrent import
|
# run recurrent import
|
||||||
result = run_all_recurrent_imports.delay()
|
run_all_recurrent_imports.delay()
|
||||||
|
|
||||||
messages.success(request, _("Imports has been launched."))
|
messages.success(request, _("Imports has been launched."))
|
||||||
return HttpResponseRedirect(reverse_lazy("recurrent_imports"))
|
return HttpResponseRedirect(reverse_lazy("recurrent_imports"))
|
||||||
|
@ -7,7 +7,9 @@ import sys
|
|||||||
def main():
|
def main():
|
||||||
"""Run administrative tasks."""
|
"""Run administrative tasks."""
|
||||||
APP_ENV = os.getenv("APP_ENV", "dev")
|
APP_ENV = os.getenv("APP_ENV", "dev")
|
||||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", f"agenda_culturel.settings.{APP_ENV}")
|
os.environ.setdefault(
|
||||||
|
"DJANGO_SETTINGS_MODULE", f"agenda_culturel.settings.{APP_ENV}"
|
||||||
|
)
|
||||||
try:
|
try:
|
||||||
from django.core.management import execute_from_command_line
|
from django.core.management import execute_from_command_line
|
||||||
except ImportError as exc:
|
except ImportError as exc:
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
from agenda_culturel.models import Category
|
from agenda_culturel.models import Category
|
||||||
|
|
||||||
|
|
||||||
def run():
|
def run():
|
||||||
# concert, théâtre, jeune public, danse, arts du spectacle, exposition
|
# concert, théâtre, jeune public, danse, arts du spectacle, exposition
|
||||||
# conférence, nature,
|
# conférence, nature,
|
||||||
# divers
|
# divers
|
||||||
|
|
||||||
categories = [
|
categories = [
|
||||||
@ -14,12 +15,13 @@ def run():
|
|||||||
("Exposition", "Expositions", "E"),
|
("Exposition", "Expositions", "E"),
|
||||||
("Conférence", "Conférences", "C"),
|
("Conférence", "Conférences", "C"),
|
||||||
("Nature", "Événements nature", "N"),
|
("Nature", "Événements nature", "N"),
|
||||||
("Autre", "Autres événements", "A")
|
("Autre", "Autres événements", "A"),
|
||||||
]
|
]
|
||||||
|
|
||||||
if len(Category.objects.all()) <= 1:
|
if len(Category.objects.all()) <= 1:
|
||||||
print("On créée des catégories")
|
print("On créée des catégories")
|
||||||
for c in categories:
|
for c in categories:
|
||||||
cat = Category(name=c[0], alt_name = c[1] if c[1] is not None else c[0], codename=c[2])
|
cat = Category(
|
||||||
|
name=c[0], alt_name=c[1] if c[1] is not None else c[0], codename=c[2]
|
||||||
|
)
|
||||||
cat.save()
|
cat.save()
|
||||||
|
|
||||||
|
@ -1,38 +1,39 @@
|
|||||||
from djipsum.faker import FakerModel
|
from djipsum.faker import FakerModel
|
||||||
from agenda_culturel.models import Category, Event
|
from agenda_culturel.models import Event
|
||||||
import random
|
import random
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
def run():
|
|
||||||
|
|
||||||
|
def run():
|
||||||
tags = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
|
tags = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
|
||||||
tags = [w for w in tags.replace(",", "").replace(".", "").split() if len(w) >= 3]
|
tags = [w for w in tags.replace(",", "").replace(".", "").split() if len(w) >= 3]
|
||||||
|
|
||||||
faker = FakerModel(app='agenda_culturel', model='Event')
|
faker = FakerModel(app="agenda_culturel", model="Event")
|
||||||
|
|
||||||
def random_hour():
|
def random_hour():
|
||||||
m = random.randint(0,59)
|
m = random.randint(0, 59)
|
||||||
h = random.randint(0,23)
|
h = random.randint(0, 23)
|
||||||
s = random.randint(0,59)
|
s = random.randint(0, 59)
|
||||||
return f'{h}:{m}:{s}'
|
return f"{h}:{m}:{s}"
|
||||||
|
|
||||||
for j in range(20):
|
for j in range(20):
|
||||||
sday = datetime.now() + timedelta(days=random.randint(0, 40))
|
sday = datetime.now() + timedelta(days=random.randint(0, 40))
|
||||||
fields = {
|
fields = {
|
||||||
'title': faker.fake.text(max_nb_chars=100),
|
"title": faker.fake.text(max_nb_chars=100),
|
||||||
'status': Event.STATUS.PUBLISHED,
|
"status": Event.STATUS.PUBLISHED,
|
||||||
'category': faker.fake_relations(
|
"category": faker.fake_relations(type="fk", field_name="category"),
|
||||||
type='fk',
|
"start_day": sday.date(),
|
||||||
field_name='category'
|
"location": faker.fake.text(max_nb_chars=100),
|
||||||
),
|
"description": " ".join(faker.fake.paragraphs()),
|
||||||
'start_day': sday.date(),
|
"image": faker.fake.url(),
|
||||||
'location': faker.fake.text(max_nb_chars=100),
|
"image_alt": faker.fake.text(max_nb_chars=100),
|
||||||
'description': ' '.join(faker.fake.paragraphs()),
|
"reference_urls": [
|
||||||
'image': faker.fake.url(),
|
faker.fake.url() for i in range(0, random.randint(0, 5))
|
||||||
'image_alt': faker.fake.text(max_nb_chars=100),
|
],
|
||||||
'reference_urls': [faker.fake.url() for i in range(0, random.randint(0, 5))],
|
"tags": [
|
||||||
'tags': [tags[random.randint(0, len(tags) - 1)] for i in range(0, random.randint(0, 10))]
|
tags[random.randint(0, len(tags) - 1)]
|
||||||
|
for i in range(0, random.randint(0, 10))
|
||||||
|
],
|
||||||
}
|
}
|
||||||
if random.randint(0, 1) == 1:
|
if random.randint(0, 1) == 1:
|
||||||
fields["start_time"] = random_hour()
|
fields["start_time"] = random_hour()
|
||||||
@ -42,4 +43,3 @@ def run():
|
|||||||
if random.randint(0, 1) == 1:
|
if random.randint(0, 1) == 1:
|
||||||
fields["end_time"] = random_hour()
|
fields["end_time"] = random_hour()
|
||||||
faker.create(fields)
|
faker.create(fields)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user