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