misc: move AppConfig subclasses from init to apps.py (#75442)

This commit is contained in:
Valentin Deniaud 2023-03-16 11:22:11 +01:00
parent 03e3927681
commit b0d1617c22
32 changed files with 711 additions and 685 deletions

View File

@ -1,32 +0,0 @@
# combo - content management system
# Copyright (C) 2017-2018 Entr'ouvert
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import django.apps
from django.urls import reverse
from django.utils.translation import gettext_lazy as _
class AppConfig(django.apps.AppConfig):
name = 'combo.apps.assets'
verbose_name = _('Assets')
def get_before_urls(self):
from . import urls
return urls.urlpatterns
def get_extra_manager_actions(self):
return [{'href': reverse('combo-manager-assets'), 'text': _('Assets')}]

32
combo/apps/assets/apps.py Normal file
View File

@ -0,0 +1,32 @@
# combo - content management system
# Copyright (C) 2017-2018 Entr'ouvert
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import django.apps
from django.urls import reverse
from django.utils.translation import gettext_lazy as _
class AppConfig(django.apps.AppConfig):
name = 'combo.apps.assets'
verbose_name = _('Assets')
def get_before_urls(self):
from . import urls
return urls.urlpatterns
def get_extra_manager_actions(self):
return [{'href': reverse('combo-manager-assets'), 'text': _('Assets')}]

View File

@ -1,28 +0,0 @@
# combo - content management system
# Copyright (C) 2017 Entr'ouvert
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import django.apps
from django.utils.translation import gettext_lazy as _
class AppConfig(django.apps.AppConfig):
name = 'combo.apps.calendar'
verbose_name = _('Calendar')
def get_before_urls(self):
from . import urls
return urls.urlpatterns

View File

@ -0,0 +1,28 @@
# combo - content management system
# Copyright (C) 2017 Entr'ouvert
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import django.apps
from django.utils.translation import gettext_lazy as _
class AppConfig(django.apps.AppConfig):
name = 'combo.apps.calendar'
verbose_name = _('Calendar')
def get_before_urls(self):
from . import urls
return urls.urlpatterns

View File

@ -1,36 +0,0 @@
# combo - content management system
# Copyright (C) 2014-2017 Entr'ouvert
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
import django.apps
from django.utils.timezone import now, timedelta
from django.utils.translation import gettext_lazy as _
class AppConfig(django.apps.AppConfig):
name = 'combo.apps.dashboard'
verbose_name = _('Dashboard')
def get_before_urls(self):
from . import urls
return urls.urlpatterns
def hourly(self):
self.clean_autotiles()
def clean_autotiles(self):
from combo.data.models import ConfigJsonCell
ConfigJsonCell.objects.filter(
placeholder='_auto_tile', last_update_timestamp__lte=now() - timedelta(days=2)
).delete()

View File

@ -0,0 +1,36 @@
# combo - content management system
# Copyright (C) 2014-2017 Entr'ouvert
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
import django.apps
from django.utils.timezone import now, timedelta
from django.utils.translation import gettext_lazy as _
class AppConfig(django.apps.AppConfig):
name = 'combo.apps.dashboard'
verbose_name = _('Dashboard')
def get_before_urls(self):
from . import urls
return urls.urlpatterns
def hourly(self):
self.clean_autotiles()
def clean_autotiles(self):
from combo.data.models import ConfigJsonCell
ConfigJsonCell.objects.filter(
placeholder='_auto_tile', last_update_timestamp__lte=now() - timedelta(days=2)
).delete()

View File

@ -1,36 +0,0 @@
# combo - content management system
# Copyright (C) 2015 Entr'ouvert
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import django.apps
from django.utils.translation import gettext_lazy as _
class AppConfig(django.apps.AppConfig):
name = 'combo.apps.dataviz'
verbose_name = _('Data Visualisation')
def get_before_urls(self):
from . import urls
return urls.urlpatterns
def hourly(self):
from .models import ChartNgCell
from .utils import update_available_statistics
update_available_statistics()
for cell in ChartNgCell.objects.all():
cell.check_validity()

View File

@ -0,0 +1,36 @@
# combo - content management system
# Copyright (C) 2015 Entr'ouvert
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import django.apps
from django.utils.translation import gettext_lazy as _
class AppConfig(django.apps.AppConfig):
name = 'combo.apps.dataviz'
verbose_name = _('Data Visualisation')
def get_before_urls(self):
from . import urls
return urls.urlpatterns
def hourly(self):
from .models import ChartNgCell
from .utils import update_available_statistics
update_available_statistics()
for cell in ChartNgCell.objects.all():
cell.check_validity()

View File

@ -1,23 +0,0 @@
# combo - content management system
# Copyright (C) 2021 Entr'ouvert
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import django.apps
from django.utils.translation import gettext_lazy as _
class AppConfig(django.apps.AppConfig):
name = 'combo.apps.family'
verbose_name = _('Family')

23
combo/apps/family/apps.py Normal file
View File

@ -0,0 +1,23 @@
# combo - content management system
# Copyright (C) 2021 Entr'ouvert
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import django.apps
from django.utils.translation import gettext_lazy as _
class AppConfig(django.apps.AppConfig):
name = 'combo.apps.family'
verbose_name = _('Family')

View File

@ -1,23 +0,0 @@
# combo - content management system
# Copyright (C) 2016 Entr'ouvert
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import django.apps
from django.utils.translation import gettext_lazy as _
class AppConfig(django.apps.AppConfig):
name = 'combo.apps.fargo'
verbose_name = _('Portfolio')

23
combo/apps/fargo/apps.py Normal file
View File

@ -0,0 +1,23 @@
# combo - content management system
# Copyright (C) 2016 Entr'ouvert
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import django.apps
from django.utils.translation import gettext_lazy as _
class AppConfig(django.apps.AppConfig):
name = 'combo.apps.fargo'
verbose_name = _('Portfolio')

View File

@ -1,28 +0,0 @@
# combo - content management system
# Copyright (C) 2015 Entr'ouvert
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import django.apps
from django.utils.translation import gettext_lazy as _
class AppConfig(django.apps.AppConfig):
name = 'combo.apps.gallery'
verbose_name = _('Gallery')
def get_before_urls(self):
from . import urls
return urls.urlpatterns

View File

@ -0,0 +1,28 @@
# combo - content management system
# Copyright (C) 2015 Entr'ouvert
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import django.apps
from django.utils.translation import gettext_lazy as _
class AppConfig(django.apps.AppConfig):
name = 'combo.apps.gallery'
verbose_name = _('Gallery')
def get_before_urls(self):
from . import urls
return urls.urlpatterns

View File

@ -1,23 +0,0 @@
# combo - content management system
# Copyright (C) 2020 Entr'ouvert
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import django.apps
from django.utils.translation import gettext_lazy as _
class AppConfig(django.apps.AppConfig):
name = 'combo.apps.kb'
verbose_name = _('Knowledge Base')

23
combo/apps/kb/apps.py Normal file
View File

@ -0,0 +1,23 @@
# combo - content management system
# Copyright (C) 2020 Entr'ouvert
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import django.apps
from django.utils.translation import gettext_lazy as _
class AppConfig(django.apps.AppConfig):
name = 'combo.apps.kb'
verbose_name = _('Knowledge Base')

View File

@ -1,102 +0,0 @@
# lingo - basket and payment system
# Copyright (C) 2015 Entr'ouvert
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import datetime
import logging
import django.apps
import eopayment
from django.db import transaction
from django.db.models.signals import post_migrate
from django.urls import reverse
from django.utils import timezone
from django.utils.translation import gettext_lazy as _
class AppConfig(django.apps.AppConfig):
name = 'combo.apps.lingo'
verbose_name = _('Payment')
def ready(self):
post_migrate.connect(self.post_migrate_handler, sender=self)
def post_migrate_handler(self, **kwargs):
from .models import PaymentBackend
with transaction.atomic():
for payment_backend in PaymentBackend.objects.all():
service_options = payment_backend.service_options
transaction_options = {}
for parameter in payment_backend.eopayment.get_parameters(scope='transaction'):
name = parameter['name']
if name in service_options:
transaction_options[name] = service_options.pop(name)
if not transaction_options:
continue
payment_backend.save()
for regie in payment_backend.regie_set.all():
# merge old values in new transactions options
regie.transaction_options = dict(transaction_options, **regie.transaction_options)
regie.save()
def get_before_urls(self):
from . import urls
return urls.urlpatterns
def get_extra_manager_actions(self):
return [{'href': reverse('lingo-manager-homepage'), 'text': _('Online Payment')}]
def hourly(self):
self.update_transactions()
self.notify_payments()
def update_transactions(self):
from .models import EXPIRED, Transaction
logger = logging.getLogger(__name__)
now = timezone.now()
to_expire = Transaction.objects.filter(
start_date__lt=now - datetime.timedelta(hours=1), end_date__isnull=True
)
for transaction in to_expire:
logger.info('transaction %r is expired', transaction.order_id)
transaction.status = EXPIRED
transaction.save()
to_retry = Transaction.objects.filter(
status__in=(eopayment.PAID, eopayment.ACCEPTED),
to_be_paid_remote_items__isnull=False,
start_date__gt=now - datetime.timedelta(days=4),
)
for transaction in to_retry:
transaction.retry_notify_remote_items_of_payments()
def notify_payments(self):
from combo.apps.lingo.models import BasketItem
logger = logging.getLogger(__name__)
now = timezone.now()
for item in BasketItem.objects.filter(
notification_date__isnull=True,
cancellation_date__isnull=True,
payment_date__lt=now - datetime.timedelta(minutes=5),
payment_date__gt=now - datetime.timedelta(minutes=300),
):
try:
item.notify_payment()
except Exception:
logger.exception('error in async notification for basket item %s', item.id)

102
combo/apps/lingo/apps.py Normal file
View File

@ -0,0 +1,102 @@
# lingo - basket and payment system
# Copyright (C) 2015 Entr'ouvert
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import datetime
import logging
import django.apps
import eopayment
from django.db import transaction
from django.db.models.signals import post_migrate
from django.urls import reverse
from django.utils import timezone
from django.utils.translation import gettext_lazy as _
class AppConfig(django.apps.AppConfig):
name = 'combo.apps.lingo'
verbose_name = _('Payment')
def ready(self):
post_migrate.connect(self.post_migrate_handler, sender=self)
def post_migrate_handler(self, **kwargs):
from .models import PaymentBackend
with transaction.atomic():
for payment_backend in PaymentBackend.objects.all():
service_options = payment_backend.service_options
transaction_options = {}
for parameter in payment_backend.eopayment.get_parameters(scope='transaction'):
name = parameter['name']
if name in service_options:
transaction_options[name] = service_options.pop(name)
if not transaction_options:
continue
payment_backend.save()
for regie in payment_backend.regie_set.all():
# merge old values in new transactions options
regie.transaction_options = dict(transaction_options, **regie.transaction_options)
regie.save()
def get_before_urls(self):
from . import urls
return urls.urlpatterns
def get_extra_manager_actions(self):
return [{'href': reverse('lingo-manager-homepage'), 'text': _('Online Payment')}]
def hourly(self):
self.update_transactions()
self.notify_payments()
def update_transactions(self):
from .models import EXPIRED, Transaction
logger = logging.getLogger(__name__)
now = timezone.now()
to_expire = Transaction.objects.filter(
start_date__lt=now - datetime.timedelta(hours=1), end_date__isnull=True
)
for transaction in to_expire:
logger.info('transaction %r is expired', transaction.order_id)
transaction.status = EXPIRED
transaction.save()
to_retry = Transaction.objects.filter(
status__in=(eopayment.PAID, eopayment.ACCEPTED),
to_be_paid_remote_items__isnull=False,
start_date__gt=now - datetime.timedelta(days=4),
)
for transaction in to_retry:
transaction.retry_notify_remote_items_of_payments()
def notify_payments(self):
from combo.apps.lingo.models import BasketItem
logger = logging.getLogger(__name__)
now = timezone.now()
for item in BasketItem.objects.filter(
notification_date__isnull=True,
cancellation_date__isnull=True,
payment_date__lt=now - datetime.timedelta(minutes=5),
payment_date__gt=now - datetime.timedelta(minutes=300),
):
try:
item.notify_payment()
except Exception:
logger.exception('error in async notification for basket item %s', item.id)

View File

@ -1,32 +0,0 @@
# combo - content management system
# Copyright (C) 2017 Entr'ouvert
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import django.apps
from django.urls import reverse
from django.utils.translation import gettext_lazy as _
class AppConfig(django.apps.AppConfig):
name = 'combo.apps.maps'
verbose_name = _('Maps')
def get_before_urls(self):
from . import urls
return urls.urlpatterns
def get_extra_manager_actions(self):
return [{'href': reverse('maps-manager-homepage'), 'text': _('Maps')}]

32
combo/apps/maps/apps.py Normal file
View File

@ -0,0 +1,32 @@
# combo - content management system
# Copyright (C) 2017 Entr'ouvert
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import django.apps
from django.urls import reverse
from django.utils.translation import gettext_lazy as _
class AppConfig(django.apps.AppConfig):
name = 'combo.apps.maps'
verbose_name = _('Maps')
def get_before_urls(self):
from . import urls
return urls.urlpatterns
def get_extra_manager_actions(self):
return [{'href': reverse('maps-manager-homepage'), 'text': _('Maps')}]

View File

@ -1,28 +0,0 @@
# combo - content management system
# Copyright (C) 2016 Entr'ouvert
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import django.apps
from django.utils.translation import gettext_lazy as _
class AppConfig(django.apps.AppConfig):
name = 'combo.apps.notifications'
verbose_name = _('Notification')
def get_before_urls(self):
from . import urls
return urls.urlpatterns

View File

@ -0,0 +1,28 @@
# combo - content management system
# Copyright (C) 2016 Entr'ouvert
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import django.apps
from django.utils.translation import gettext_lazy as _
class AppConfig(django.apps.AppConfig):
name = 'combo.apps.notifications'
verbose_name = _('Notification')
def get_before_urls(self):
from . import urls
return urls.urlpatterns

View File

@ -1,26 +0,0 @@
# combo - content management system
# Copyright (C) 2015 Entr'ouvert
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import django.apps
class AppConfig(django.apps.AppConfig):
name = 'combo.apps.publik'
def get_before_urls(self):
from . import urls
return urls.urlpatterns

26
combo/apps/publik/apps.py Normal file
View File

@ -0,0 +1,26 @@
# combo - content management system
# Copyright (C) 2015 Entr'ouvert
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import django.apps
class AppConfig(django.apps.AppConfig):
name = 'combo.apps.publik'
def get_before_urls(self):
from . import urls
return urls.urlpatterns

View File

@ -1,38 +0,0 @@
# combo - content management system
# Copyright (C) 2015-2018 Entr'ouvert
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import django.apps
from django.urls import reverse
from django.utils.translation import gettext_lazy as _
class AppConfig(django.apps.AppConfig):
name = 'combo.apps.pwa'
def ready(self):
from . import signals # noqa pylint: disable=unused-import
def get_before_urls(self):
from . import urls
return urls.urlpatterns
def get_extra_manager_actions(self):
from django.conf import settings
if settings.TEMPLATE_VARS.get('pwa_display') == 'standalone':
return [{'href': reverse('pwa-manager-homepage'), 'text': _('Mobile Application (PWA)')}]
return []

38
combo/apps/pwa/apps.py Normal file
View File

@ -0,0 +1,38 @@
# combo - content management system
# Copyright (C) 2015-2018 Entr'ouvert
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import django.apps
from django.urls import reverse
from django.utils.translation import gettext_lazy as _
class AppConfig(django.apps.AppConfig):
name = 'combo.apps.pwa'
def ready(self):
from . import signals # noqa pylint: disable=unused-import
def get_before_urls(self):
from . import urls
return urls.urlpatterns
def get_extra_manager_actions(self):
from django.conf import settings
if settings.TEMPLATE_VARS.get('pwa_display') == 'standalone':
return [{'href': reverse('pwa-manager-homepage'), 'text': _('Mobile Application (PWA)')}]
return []

View File

@ -1,50 +0,0 @@
# combo - content management system
# Copyright (C) 2014-2017 Entr'ouvert
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import django.apps
from django.urls import reverse
from django.utils.translation import gettext_lazy as _
from .engines import engines
class AppConfig(django.apps.AppConfig):
name = 'combo.apps.search'
verbose_name = _('Search')
def get_before_urls(self):
from . import urls
return urls.urlpatterns
def hourly(self):
from .utils import index_site
index_site()
def ready(self):
# register built-in search engine for page contents
engines.register(self.get_search_engines)
def get_search_engines(self):
from .utils import search_site
return {
'_text': {
'function': search_site,
'label': _('Page Contents'),
}
}

50
combo/apps/search/apps.py Normal file
View File

@ -0,0 +1,50 @@
# combo - content management system
# Copyright (C) 2014-2017 Entr'ouvert
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import django.apps
from django.urls import reverse
from django.utils.translation import gettext_lazy as _
from .engines import engines
class AppConfig(django.apps.AppConfig):
name = 'combo.apps.search'
verbose_name = _('Search')
def get_before_urls(self):
from . import urls
return urls.urlpatterns
def hourly(self):
from .utils import index_site
index_site()
def ready(self):
# register built-in search engine for page contents
engines.register(self.get_search_engines)
def get_search_engines(self):
from .utils import search_site
return {
'_text': {
'function': search_site,
'label': _('Page Contents'),
}
}

View File

@ -1,137 +0,0 @@
# combo - content management system
# Copyright (C) 2016 Entr'ouvert
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import hashlib
import django.apps
from django.conf import settings
from django.urls import reverse
from django.utils.encoding import force_bytes
from django.utils.translation import gettext_lazy as _
from django.utils.translation import pgettext_lazy
class AppConfig(django.apps.AppConfig):
name = 'combo.apps.wcs'
verbose_name = _('Forms')
def ready(self):
from combo.apps.search import engines
engines.register(self.get_search_engines)
def get_search_engines(self):
from .utils import get_wcs_services
wcs_services = get_wcs_services()
if not wcs_services:
return
engines = self.get_portal_agent_search_engines(wcs_services)
engines.update(self.get_card_search_engines(wcs_services))
return engines
def get_card_search_engines(self, wcs_services):
from combo.data.models import Page
from .utils import get_matching_pages_from_card_slug, get_wcs_json
pages_with_sub_slug = Page.objects.exclude(sub_slug='')
if not pages_with_sub_slug:
return {}
engines = {}
for key, service in wcs_services.items():
card_models = get_wcs_json(service, 'api/cards/@list')
for card in card_models.get('data') or []:
matching_pages = get_matching_pages_from_card_slug(card['id'])
if not matching_pages:
continue
card_page = matching_pages[0]
card_page_base_url = card_page.get_online_url()
label = card['text']
if len(wcs_services.keys()) > 1:
label = '%s (%s)' % (label, service['title'])
engines['cards:%s:%s' % (hashlib.md5(force_bytes(key)).hexdigest()[:8], card['id'])] = {
'url': (
service['url'] + 'api/cards/' + card['id'] + '/list/'
'{% if search_service.selected_custom_view %}{{ search_service.selected_custom_view }}{% endif %}'
'?{% if not search_service.without_user %}NameID={{ user_nameid }}&{% endif %}'
'q=%(q)s'
),
'custom_views': card.get('custom_views') or [],
'label': label,
'signature': True,
'hit_url_template': '%s{{ id }}/' % card_page_base_url,
'hit_label_template': '{% firstof digest text %}',
}
return engines
def get_portal_agent_search_engines(self, wcs_services):
if not settings.TEMPLATE_VARS.get('is_portal_agent'):
return {}
engines = {
'tracking-code': {
'url': reverse('wcs-tracking-code-search') + '?q=%(q)s',
'label': _('Tracking Code'),
}
}
for key, service in wcs_services.items():
label = pgettext_lazy('user-forms', 'Forms')
if len(wcs_services.keys()) > 1:
label = pgettext_lazy('user-forms', 'Forms (%s)') % service['title']
engines['formdata:%s' % hashlib.md5(force_bytes(key)).hexdigest()[:8]] = {
'url': service['url']
+ 'api/forms/?NameID={{user_nameid}}&status=all&ignore-roles=on&include-anonymised=off&q=%(q)s',
'label': label,
'signature': True,
'hit_url_template': '{% if readable %}{{ form_url_backoffice }}{% endif %}',
'hit_label_template': '{{ title }}',
'hit_description_template': '{{ form_digest|default:"" }}',
}
return engines
def get_before_urls(self):
from . import urls
return urls.urlpatterns
def hourly(self):
from combo.data.library import get_cell_classes
from combo.data.models import CellBase
cell_classes = [c for c in self.get_models() if c in get_cell_classes()]
for cell in CellBase.get_cells(cell_filter=lambda x: x in cell_classes, page__snapshot__isnull=True):
if hasattr(cell, 'check_validity'):
cell.check_validity()
self.update_db_cache()
def update_db_cache(self):
from combo.data.models import CellBase
from .models import WcsCardCell, WcsCategoryCell, WcsFormCell, WcsFormsOfCategoryCell
models_to_update = [
WcsFormCell,
WcsCategoryCell,
WcsFormsOfCategoryCell,
WcsCardCell,
]
for cell in CellBase.get_cells(cell_filter=lambda x: x in models_to_update):
cell.save()

137
combo/apps/wcs/apps.py Normal file
View File

@ -0,0 +1,137 @@
# combo - content management system
# Copyright (C) 2016 Entr'ouvert
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import hashlib
import django.apps
from django.conf import settings
from django.urls import reverse
from django.utils.encoding import force_bytes
from django.utils.translation import gettext_lazy as _
from django.utils.translation import pgettext_lazy
class AppConfig(django.apps.AppConfig):
name = 'combo.apps.wcs'
verbose_name = _('Forms')
def ready(self):
from combo.apps.search.engines import engines
engines.register(self.get_search_engines)
def get_search_engines(self):
from .utils import get_wcs_services
wcs_services = get_wcs_services()
if not wcs_services:
return
engines = self.get_portal_agent_search_engines(wcs_services)
engines.update(self.get_card_search_engines(wcs_services))
return engines
def get_card_search_engines(self, wcs_services):
from combo.data.models import Page
from .utils import get_matching_pages_from_card_slug, get_wcs_json
pages_with_sub_slug = Page.objects.exclude(sub_slug='')
if not pages_with_sub_slug:
return {}
engines = {}
for key, service in wcs_services.items():
card_models = get_wcs_json(service, 'api/cards/@list')
for card in card_models.get('data') or []:
matching_pages = get_matching_pages_from_card_slug(card['id'])
if not matching_pages:
continue
card_page = matching_pages[0]
card_page_base_url = card_page.get_online_url()
label = card['text']
if len(wcs_services.keys()) > 1:
label = '%s (%s)' % (label, service['title'])
engines['cards:%s:%s' % (hashlib.md5(force_bytes(key)).hexdigest()[:8], card['id'])] = {
'url': (
service['url'] + 'api/cards/' + card['id'] + '/list/'
'{% if search_service.selected_custom_view %}{{ search_service.selected_custom_view }}{% endif %}'
'?{% if not search_service.without_user %}NameID={{ user_nameid }}&{% endif %}'
'q=%(q)s'
),
'custom_views': card.get('custom_views') or [],
'label': label,
'signature': True,
'hit_url_template': '%s{{ id }}/' % card_page_base_url,
'hit_label_template': '{% firstof digest text %}',
}
return engines
def get_portal_agent_search_engines(self, wcs_services):
if not settings.TEMPLATE_VARS.get('is_portal_agent'):
return {}
engines = {
'tracking-code': {
'url': reverse('wcs-tracking-code-search') + '?q=%(q)s',
'label': _('Tracking Code'),
}
}
for key, service in wcs_services.items():
label = pgettext_lazy('user-forms', 'Forms')
if len(wcs_services.keys()) > 1:
label = pgettext_lazy('user-forms', 'Forms (%s)') % service['title']
engines['formdata:%s' % hashlib.md5(force_bytes(key)).hexdigest()[:8]] = {
'url': service['url']
+ 'api/forms/?NameID={{user_nameid}}&status=all&ignore-roles=on&include-anonymised=off&q=%(q)s',
'label': label,
'signature': True,
'hit_url_template': '{% if readable %}{{ form_url_backoffice }}{% endif %}',
'hit_label_template': '{{ title }}',
'hit_description_template': '{{ form_digest|default:"" }}',
}
return engines
def get_before_urls(self):
from . import urls
return urls.urlpatterns
def hourly(self):
from combo.data.library import get_cell_classes
from combo.data.models import CellBase
cell_classes = [c for c in self.get_models() if c in get_cell_classes()]
for cell in CellBase.get_cells(cell_filter=lambda x: x in cell_classes, page__snapshot__isnull=True):
if hasattr(cell, 'check_validity'):
cell.check_validity()
self.update_db_cache()
def update_db_cache(self):
from combo.data.models import CellBase
from .models import WcsCardCell, WcsCategoryCell, WcsFormCell, WcsFormsOfCategoryCell
models_to_update = [
WcsFormCell,
WcsCategoryCell,
WcsFormsOfCategoryCell,
WcsCardCell,
]
for cell in CellBase.get_cells(cell_filter=lambda x: x in models_to_update):
cell.save()

View File

@ -16,10 +16,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import django.apps
from django.utils.translation import gettext_lazy as _
def user_get_name_id(user):
if not hasattr(user, '_name_id'):
user._name_id = None
@ -37,42 +33,3 @@ default_description_template = """{{ email|default:"" }}
{% if address %} {{ address }}{% endif %}
{% if zipcode %} {{ zipcode }}{% endif %}
{% if city %} {{ city }}{% endif %}"""
class AppConfig(django.apps.AppConfig):
name = 'combo.profile'
verbose_name = _('Profile')
def ready(self):
from combo.apps.search import engines
engines.register(self.get_search_engines)
from django.contrib.auth import get_user_model
get_user_model().add_to_class('get_name_id', user_get_name_id)
def get_search_engines(self):
from django.conf import settings
from combo.data.models import Page
user_page = Page.objects.filter(sub_slug='name_id').first()
if not user_page:
user_page = Page.objects.filter(sub_slug__contains='<name_id>').first()
if not user_page:
return
user_page_base_url = user_page.get_online_url()
# return entry using first(&only) authentic (if it exists)
for service in settings.KNOWN_SERVICES.get('authentic', {}).values():
return {
'users': {
'url': service['url'] + 'api/users/?q=%(q)s',
'label': _('Users'),
'signature': True,
'data_key': 'results',
'hit_url_template': user_page_base_url + '{{uuid}}/',
'hit_label_template': '{{first_name}} {{last_name}}',
'hit_description_template': default_description_template,
}
}

69
combo/profile/apps.py Normal file
View File

@ -0,0 +1,69 @@
# combo - content management system
# Copyright (C) 2023 Entr'ouvert
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import django.apps
from django.utils.translation import gettext_lazy as _
from . import default_description_template
def user_get_name_id(user):
if not hasattr(user, '_name_id'):
user._name_id = None
saml_identifier = user.saml_identifiers.first()
if saml_identifier:
user._name_id = saml_identifier.name_id
return user._name_id
class AppConfig(django.apps.AppConfig):
name = 'combo.profile'
verbose_name = _('Profile')
def ready(self):
from combo.apps.search.engines import engines
engines.register(self.get_search_engines)
from django.contrib.auth import get_user_model
get_user_model().add_to_class('get_name_id', user_get_name_id)
def get_search_engines(self):
from django.conf import settings
from combo.data.models import Page
user_page = Page.objects.filter(sub_slug='name_id').first()
if not user_page:
user_page = Page.objects.filter(sub_slug__contains='<name_id>').first()
if not user_page:
return
user_page_base_url = user_page.get_online_url()
# return entry using first(&only) authentic (if it exists)
for service in settings.KNOWN_SERVICES.get('authentic', {}).values():
return {
'users': {
'url': service['url'] + 'api/users/?q=%(q)s',
'label': _('Users'),
'signature': True,
'data_key': 'results',
'hit_url_template': user_page_base_url + '{{uuid}}/',
'hit_label_template': '{{first_name}} {{last_name}}',
'hit_description_template': default_description_template,
}
}