From 2c2b9d4306a25285f6908b49e46d257fb446bbc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Tue, 31 May 2022 18:51:07 +0200 Subject: [PATCH] remove urls/views (#64910) --- combo_plugin_gnm/__init__.py | 36 --------- combo_plugin_gnm/urls.py | 27 ------- combo_plugin_gnm/views.py | 147 ----------------------------------- 3 files changed, 210 deletions(-) delete mode 100644 combo_plugin_gnm/urls.py delete mode 100644 combo_plugin_gnm/views.py diff --git a/combo_plugin_gnm/__init__.py b/combo_plugin_gnm/__init__.py index 039e26c..e69de29 100644 --- a/combo_plugin_gnm/__init__.py +++ b/combo_plugin_gnm/__init__.py @@ -1,36 +0,0 @@ -# combo-plugin-gnm - Combo GNM plugin -# 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 . - -import django.apps -from django.utils.translation import ugettext_lazy as _ - - -class Plugin(object): - def get_apps(self): - return [__name__] - - -class AppConfig(django.apps.AppConfig): - name = __name__ - verbose_name = _('GNM Extension') - - def get_before_urls(self): - from . import urls - - return urls.urlpatterns - - -default_app_config = __name__ + '.AppConfig' diff --git a/combo_plugin_gnm/urls.py b/combo_plugin_gnm/urls.py deleted file mode 100644 index 8ab1230..0000000 --- a/combo_plugin_gnm/urls.py +++ /dev/null @@ -1,27 +0,0 @@ -# -*- coding: utf-8 -*- -# combo-plugin-gnm - Combo GNM plugin -# 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 . - -from django.conf.urls import url - -from . import views - -urlpatterns = [ - url(r'^gnm/plusone/$', views.plusone, name='gnm-plus-one'), - url(r'^gnm/share/$', views.share, name='gnm-share'), - url(r'^gnm/stats/$', views.stats, name='gnm-stats'), - url(r'^gnm/cartads/unsubscribe/$', views.cartads_unsubscribe, name='gnm-cartads-unsubscribe'), -] diff --git a/combo_plugin_gnm/views.py b/combo_plugin_gnm/views.py deleted file mode 100644 index b31c3ac..0000000 --- a/combo_plugin_gnm/views.py +++ /dev/null @@ -1,147 +0,0 @@ -# -*- coding: utf-8 -*- -# combo-plugin-gnm - Combo GNM plugin -# 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 . - -from django.conf import settings -from django.contrib import messages -from django.contrib.auth import get_user_model -from django.core.mail import EmailMultiAlternatives -from django.http import HttpResponseRedirect, JsonResponse -from django.template import RequestContext -from django.template.loader import render_to_string - -from combo.apps.dashboard.models import Tile -from combo.data.models import ConfigJsonCell -from combo.utils import requests, get_templated_url - - -def plusone(request, *args, **kwargs): - # add reference to a jsondatastore with slug "plus1" - reference = request.GET.get('ref') - if reference: - context = RequestContext(request, {'request': request}) - passerelle_url = '[passerelle_url]jsondatastore/plus1/data/create' - if request.user and request.user.is_authenticated: - passerelle_url += '?name_id=[user_nameid]' - passerelle_url = get_templated_url(passerelle_url, context) - headers = {'content-type': 'application/json'} - requests.post( - passerelle_url, - remote_service='auto', - without_user=True, - headers={'Accept': 'application/json'}, - json={'reference': reference}, - timeout=2, - ) - - messages.info(request, u'Merci, votre confirmation nous est utile.') - if request.user and request.user.is_authenticated: - return HttpResponseRedirect('/') - else: - return HttpResponseRedirect('/services/') - - -def share(request, *args, **kwargs): - subject_template = 'gnm/share_email_subject.txt' - text_body_template = 'gnm/share_email_body.txt' - html_body_template = 'gnm/share_email_body.html' - - ctx = {} - ctx['request'] = request - ctx['name'] = request.POST['name'] - ctx['url'] = request.build_absolute_uri(request.POST['url']) - subject = render_to_string([subject_template], ctx, request=request).strip() - text_body = render_to_string([text_body_template], ctx, request=request) - html_body = render_to_string([html_body_template], ctx, request=request) - message = EmailMultiAlternatives(subject, text_body, to=[request.POST['email']]) - message.attach_alternative(html_body, 'text/html') - message.send() - - url = request.POST.get('url') - return HttpResponseRedirect(url) - - -def stats(request, *args, **kwargs): - data = {} - User = get_user_model() - data['users'] = {} - data['users']['count'] = User.objects.all().count() - data['tiles'] = {} - tiles_by_user = {} - manual_tiles_by_user = {} - - # preload - cells = {} - for cell in ConfigJsonCell.objects.filter(placeholder__in=['_dashboard', '_suggested_tile']): - cells[cell.id] = cell - - for tile in Tile.objects.filter(dashboard__isnull=False): - cell = cells[tile.cell_pk] # no db access - - if cell.key not in settings.JSON_CELL_TYPES: - continue - - if tile.user_id not in tiles_by_user: - tiles_by_user[tile.user_id] = [] - tiles_by_user[tile.user_id].append(cell.key) - - if cell.key not in data['tiles']: - data['tiles'][cell.key] = { - 'name': settings.JSON_CELL_TYPES[cell.key]['name'], - 'count': 0, - 'manual': 0, - } - - data['tiles'][cell.key]['count'] += 1 - - if cell.placeholder != '_suggested_tile': - data['tiles'][cell.key]['manual'] += 1 - if tile.user_id not in manual_tiles_by_user: - manual_tiles_by_user[tile.user_id] = [] - manual_tiles_by_user[tile.user_id].append(cell.key) - - data['users']['have-tiles'] = len(tiles_by_user.keys()) - data['users']['have-more-than-suggested-tiles'] = len(manual_tiles_by_user.keys()) - data['users']['have-no-tiles'] = data['users']['count'] - data['users']['have-tiles'] - dashboard_lengths = [len(x) for x in tiles_by_user.values()] - if dashboard_lengths: - dashboard_lengths.sort() - data['users']['max-tiles'] = max(dashboard_lengths) - data['users']['median-tiles'] = dashboard_lengths[len(dashboard_lengths) // 2] - - return JsonResponse(data) - - -def cartads_unsubscribe(request, *args, **kwargs): - cell = ConfigJsonCell.objects.filter(key='cartads-dossiers').first() - if cell: - next_url = cell.page.get_online_url() - else: - next_url = '/' - numero_dossier = request.GET.get('numero_dossier') - if numero_dossier: - context = RequestContext(request, {'request': request}) - context.update(cell.get_cell_extra_context(context)) - action_url = get_templated_url( - settings.JSON_CELL_TYPES['cartads-dossiers']['actions']['unsubscribe']['url'], context - ) - action_url += '&dossier_number=' + numero_dossier - response = requests.get(action_url, remote_service='auto', without_user=True) - if response.ok: - messages.info(request, u'Le dossier a été retiré de votre suivi.') - return HttpResponseRedirect(next_url) - messages.error(request, u"Le dossier n'a pas pu être retiré de votre suivi.") - return HttpResponseRedirect(next_url)