From 864542fdca488e9173503afb45adfb765a53fc2e Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Fri, 21 Mar 2014 10:38:05 +0100 Subject: [PATCH 01/13] fix django-cms plugins loading, remove sys.path tampering --- portail_citoyen/__init__.py | 7 ------- portail_citoyen/admin.py | 2 +- portail_citoyen/apps/auquotidien_plugin/cms_plugins.py | 4 ++-- portail_citoyen/apps/auquotidien_plugin/models.py | 2 +- portail_citoyen/dashboard.py | 4 ++-- portail_citoyen/settings.py | 10 +++++----- 6 files changed, 11 insertions(+), 18 deletions(-) diff --git a/portail_citoyen/__init__.py b/portail_citoyen/__init__.py index 7a1d20e..11d27f8 100644 --- a/portail_citoyen/__init__.py +++ b/portail_citoyen/__init__.py @@ -1,8 +1 @@ -import os.path -import sys - __version__ = '0.1' - -apps_dir = os.path.join(os.path.dirname(__file__), 'apps') -if apps_dir not in sys.path: - sys.path.append(apps_dir) diff --git a/portail_citoyen/admin.py b/portail_citoyen/admin.py index a8ccbad..b3a3530 100644 --- a/portail_citoyen/admin.py +++ b/portail_citoyen/admin.py @@ -186,7 +186,7 @@ if 'wcsinst.wcsinst' in settings.INSTALLED_APPS: c += 1 sleep_length *= 2 if done and 'auquotidien_plugin' in settings.INSTALLED_APPS: - from auquotidien_plugin.models import AuQuotidienAPI + from .apps.auquotidien_plugin.models import AuQuotidienAPI defaults = { 'name': instance.title, 'orig': request.META['HTTP_HOST'], diff --git a/portail_citoyen/apps/auquotidien_plugin/cms_plugins.py b/portail_citoyen/apps/auquotidien_plugin/cms_plugins.py index 9231501..8a03baa 100644 --- a/portail_citoyen/apps/auquotidien_plugin/cms_plugins.py +++ b/portail_citoyen/apps/auquotidien_plugin/cms_plugins.py @@ -7,8 +7,8 @@ from django.utils.translation import ugettext_lazy as _ from cms.plugin_pool import plugin_pool -from data_source_plugin.cms_plugins import DataSourcePlugin, Data -from data_source_plugin.models import DataSource +from ..data_source_plugin.cms_plugins import DataSourcePlugin, Data +from ..data_source_plugin.models import DataSource from .models import ( AuQuotidienActiveFormsPlugin as AuQuotidienActiveFormsPluginModel, diff --git a/portail_citoyen/apps/auquotidien_plugin/models.py b/portail_citoyen/apps/auquotidien_plugin/models.py index b4bf2ff..d5079f6 100644 --- a/portail_citoyen/apps/auquotidien_plugin/models.py +++ b/portail_citoyen/apps/auquotidien_plugin/models.py @@ -5,7 +5,7 @@ from django.db import models from cms.models import CMSPlugin -from data_source_plugin.models import DataSource +from ..data_source_plugin.models import DataSource __all__ = [ 'AuQuotidienAPI', 'AuQuotidienActiveFormsPlugin' ] diff --git a/portail_citoyen/dashboard.py b/portail_citoyen/dashboard.py index 4279bd2..05640f6 100644 --- a/portail_citoyen/dashboard.py +++ b/portail_citoyen/dashboard.py @@ -30,8 +30,8 @@ class CustomIndexDashboard(Dashboard): _('Contents'), models=( 'cms.models.pagemodel.Page', - 'data_source_plugin.models.DataSource', - 'feed_plugin.models.Feed', + 'portail_citoyen.apps.data_source_plugin.models.DataSource', + 'portail_citoyen.apps.feed_plugin.models.Feed', ), )) diff --git a/portail_citoyen/settings.py b/portail_citoyen/settings.py index 3b946d4..dfd3907 100644 --- a/portail_citoyen/settings.py +++ b/portail_citoyen/settings.py @@ -141,11 +141,11 @@ INSTALLED_APPS = ( 'cms.plugins.video', 'cmsplugin_text_wrapper', 'cms_ajax_text_plugin', - 'feed_plugin', - 'data_source_plugin', - 'a2_service_list_plugin', - 'federation_plugin', - 'auquotidien_plugin', + 'portail_citoyen.apps.feed_plugin', + 'portail_citoyen.apps.data_source_plugin', + 'portail_citoyen.apps.a2_service_list_plugin', + 'portail_citoyen.apps.federation_plugin', + 'portail_citoyen.apps.auquotidien_plugin', 'sekizai', 'portail_citoyen', ) From aa79048b6bc01526a9bd4ddb13996e6bc2afdc43 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Fri, 21 Mar 2014 12:33:02 +0100 Subject: [PATCH 02/13] urls: do not use i18npatterns for cms pages --- portail_citoyen/urls.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/portail_citoyen/urls.py b/portail_citoyen/urls.py index 0a3183c..41ec068 100644 --- a/portail_citoyen/urls.py +++ b/portail_citoyen/urls.py @@ -1,5 +1,4 @@ from django.conf.urls import patterns, include, url -from django.conf.urls.i18n import i18n_patterns from django.contrib import admin from django.contrib.staticfiles.urls import staticfiles_urlpatterns from django.conf import settings @@ -50,7 +49,7 @@ if 'cms_ajax_text_plugin' in settings.INSTALLED_APPS: -urlpatterns += i18n_patterns('', +urlpatterns += patterns('', url(r'^', include('cms.urls')), ) From e727271967e6d15efa9ea7d2c2b5a1795501f34e Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Fri, 21 Mar 2014 15:26:09 +0100 Subject: [PATCH 03/13] force version 2.5.0 of django-cms --- requirements.txt | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 5572b63..4a449eb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ --allow-all-external --allow-unverified django-admin-tools -f https://repos.entrouvert.org/django-cms.git/ -django-cms +django-cms>=2.5.0,<3.0 -f https://repos.entrouvert.org/python-entrouvert.git/ python-entrouvert requests>=1.0.0 diff --git a/setup.py b/setup.py index 1100260..9f7596b 100755 --- a/setup.py +++ b/setup.py @@ -120,7 +120,7 @@ setup(name="portail_citoyen", 'django>=1.5.1,<1.6', 'authentic2>2.0.2', 'cmsplugin-text-wrapper>=0.5', - 'django-cms>2.4.1,<2.4.2', + 'django-cms>=2.5,<3.0', 'python-entrouvert', 'south>=0.8.4', 'django-cms-ajax-text-plugin', From a42cc026868cd82ae4a75ee4db31cd43ccafe43b Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Fri, 21 Mar 2014 17:49:24 +0100 Subject: [PATCH 04/13] cms_plugins: rename hook get_object to get_form_instance as it interacts with ModelAdmin existing method --- portail_citoyen/cms_plugins.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/portail_citoyen/cms_plugins.py b/portail_citoyen/cms_plugins.py index 114ed33..f009706 100644 --- a/portail_citoyen/cms_plugins.py +++ b/portail_citoyen/cms_plugins.py @@ -8,7 +8,7 @@ from cms.plugin_pool import plugin_pool from cms.models.pluginmodel import CMSPlugin -from . import models, utils, app_settings +from . import utils, app_settings class FormPluginBase(CMSPluginBase): @@ -31,9 +31,10 @@ class FormPluginBase(CMSPluginBase): form_class = self.get_form_class(request, context, instance, placeholder) if issubclass(form_class, ModelForm): - if not hasattr(self, 'get_object'): - raise ImproperlyConfigured('Your plugin class is missing a get_object method but use a ModelForm') - kwargs['instance'] = context['object'] = self.get_object(request, context, instance, placeholder) + if not hasattr(self, 'get_form_instance'): + raise ImproperlyConfigured('Your plugin class is missing a get_form_instance method but use a ModelForm') + kwargs['instance'] = context['object'] = \ + self.get_form_instance(request, context, instance, placeholder) if utils.callable_has_arg(form_class.__init__, 'plugin_instance'): kwargs['plugin_instance'] = instance if utils.callable_has_arg(form_class.__init__, 'request'): @@ -66,7 +67,7 @@ class ProfileFormPlugin(FormPluginBase): module = importlib.import_module(module_path) return getattr(module, class_name) - def get_object(self, request, context, instance, placeholder): + def get_form_instance(self, request, context, instance, placeholder): return request.user plugin_pool.register_plugin(ProfileFormPlugin) From cc374f2467db140e491c0b36e408188e5d56b3ca Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Fri, 21 Mar 2014 17:50:31 +0100 Subject: [PATCH 05/13] settings: adapt to module reorganization in authentic2 --- portail_citoyen/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/portail_citoyen/settings.py b/portail_citoyen/settings.py index dfd3907..6a1fd46 100644 --- a/portail_citoyen/settings.py +++ b/portail_citoyen/settings.py @@ -218,7 +218,7 @@ USE_DISCO_SERVICE = 'USE_DISCO_SERVICE' in os.environ ########################### # Only RSA private keys are currently supported -AUTH_FRONTENDS = ( 'authentic2.auth2_auth.backend.LoginPasswordBackend',) +AUTH_FRONTENDS = ( 'authentic2.auth_frontends.LoginPasswordBackend',) # expiration in seconds of authentication events. From 62af1a1ec7abfe25def72df6d9872736c378b786 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Fri, 21 Mar 2014 17:51:04 +0100 Subject: [PATCH 06/13] settings: adopt new layout for defining STATICFILES_DIRS and TEMPLATE_DIRS --- portail_citoyen/settings.py | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/portail_citoyen/settings.py b/portail_citoyen/settings.py index 6a1fd46..83d3342 100644 --- a/portail_citoyen/settings.py +++ b/portail_citoyen/settings.py @@ -10,7 +10,8 @@ DEBUG_PROPAGATE_EXCEPTIONS = 'DEBUG_PROPAGATE_EXCEPTIONS' in os.environ USE_DEBUG_TOOLBAR = 'USE_DEBUG_TOOLBAR' in os.environ TEMPLATE_DEBUG = DEBUG -PROJECT_PATH = os.path.join(os.path.dirname(__file__)) +BASE_DIR = os.path.dirname(__file__) +PROJECT_PATH = os.path.join(BASE_DIR, '..') PROJECT_NAME = 'portail-citoyen' ADMINS = () @@ -26,7 +27,7 @@ MANAGERS = ADMINS DATABASES = { 'default': { 'ENGINE': os.environ.get('DATABASE_ENGINE', 'django.db.backends.sqlite3'), - 'NAME': os.environ.get('DATABASE_NAME', os.path.join(PROJECT_PATH, '..', PROJECT_NAME + '.db')), + 'NAME': os.environ.get('DATABASE_NAME', os.path.join(PROJECT_PATH, PROJECT_NAME + '.db')), 'USER': os.environ.get('DATABASE_USER', ''), 'PASSWORD': os.environ.get('DATABASE_PASSWORD', ''), 'HOST': os.environ.get('DATABASE_HOST', ''), @@ -57,9 +58,6 @@ MEDIA_URL = os.environ.get('MEDIA_URL', '/media/') PASSERELLE_URL = os.environ.get('PASSERELLE_URL', '') PASSERELLE_APIKEY = os.environ.get('PASSERELLE_APIKEY', '') -if 'STATICFILES_DIRS' in os.environ: - STATICFILES_DIRS = os.environ['STATICFILES_DIRS'].split(':') - TEMPLATE_LOADERS = ( 'django.template.loaders.filesystem.Loader', 'django.template.loaders.app_directories.Loader', @@ -99,13 +97,23 @@ PORTAIL_CITOYEN_FAVICON_URL = '' ROOT_URLCONF = 'portail_citoyen.urls' -TEMPLATE_DIRS = [os.path.join(PROJECT_PATH, 'templates')] -if os.environ.get('TEMPLATE_DIRS'): - TEMPLATE_DIRS = os.environ['TEMPLATE_DIRS'].split(':') + TEMPLATE_DIRS -else: - TEMPLATE_DIRS = ['/var/lib/%s/templates' % PROJECT_NAME] + TEMPLATE_DIRS +VAR_DIR = os.path.join('/var/lib/', PROJECT_NAME) -TEMPLATE_DIRS = tuple(TEMPLATE_DIRS) +TEMPLATE_DIRS = ( + os.path.join(VAR_DIR, 'templates'), + os.path.join(BASE_DIR, 'templates'), +) + +STATICFILES_DIRS = ( + os.path.join(VAR_DIR, 'extra-static'), + os.path.join(BASE_DIR, 'static'), +) + +if os.environ.get('TEMPLATE_DIRS'): + TEMPLATE_DIRS = tuple(os.environ['TEMPLATE_DIRS'].split(':')) + TEMPLATE_DIRS + +if os.environ.get('STATICFILES_DIRS'): + STATICFILES_DIRS = tuple(os.environ['STATICFILES_DIRS'].split(':')) + STATICFILES_DIRS INSTALLED_APPS = ( 'admin_tools', From eb68b66e636e0ba7ebc886d4bc1b8c255e6a97ef Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Fri, 21 Mar 2014 18:03:03 +0100 Subject: [PATCH 07/13] profile_form_plugin.html: show username in a read-only field --- .../templates/portail_citoyen/profile_form_plugin.html | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/portail_citoyen/templates/portail_citoyen/profile_form_plugin.html b/portail_citoyen/templates/portail_citoyen/profile_form_plugin.html index 20a6d95..72c909b 100644 --- a/portail_citoyen/templates/portail_citoyen/profile_form_plugin.html +++ b/portail_citoyen/templates/portail_citoyen/profile_form_plugin.html @@ -1,6 +1,10 @@ {% load i18n %}
+
+ +

{{ user.username }}

+

{{ user.email }}

From 5c9c3c7724199ba8bc2fb4522ef8e3005490dcff Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Mon, 24 Mar 2014 11:45:10 +0100 Subject: [PATCH 08/13] auquotidien_plugin: remove javascript hiding of locality titles in category template fixes #4543 --- .../static/auquotidien_plugin/js/categories.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/portail_citoyen/apps/auquotidien_plugin/static/auquotidien_plugin/js/categories.js b/portail_citoyen/apps/auquotidien_plugin/static/auquotidien_plugin/js/categories.js index e6f2da8..c0c4343 100644 --- a/portail_citoyen/apps/auquotidien_plugin/static/auquotidien_plugin/js/categories.js +++ b/portail_citoyen/apps/auquotidien_plugin/static/auquotidien_plugin/js/categories.js @@ -10,8 +10,6 @@ $(document).ready(function () { } $plugin.data('initialized', 1); - $titles.hide(); - if ($categories.length > 1) { if ($empty) { $categories.hide(); From b3959251eb5e25c824246364bc9bf0693485696d Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Mon, 24 Mar 2014 16:38:07 +0100 Subject: [PATCH 09/13] urls: fix application path for msp --- portail_citoyen/urls.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/portail_citoyen/urls.py b/portail_citoyen/urls.py index 41ec068..549f00f 100644 --- a/portail_citoyen/urls.py +++ b/portail_citoyen/urls.py @@ -37,7 +37,7 @@ if settings.DEBUG: {'document_root': settings.MEDIA_ROOT, 'show_indexes': True}), ) -if 'msp' in settings.INSTALLED_APPS: +if 'portail_citoyen.apps.msp' in settings.INSTALLED_APPS: urlpatterns += patterns('', url('^msp/', include('portail_citoyen.apps.msp.urls')), ) From 0f18a3509d107a0945d06c233963d80314776726 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Mon, 24 Mar 2014 16:47:01 +0100 Subject: [PATCH 10/13] msp: fix app path in urls.py --- portail_citoyen/apps/msp/urls.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/portail_citoyen/apps/msp/urls.py b/portail_citoyen/apps/msp/urls.py index b6eac8f..1557d78 100644 --- a/portail_citoyen/apps/msp/urls.py +++ b/portail_citoyen/apps/msp/urls.py @@ -1,6 +1,6 @@ from django.conf.urls import patterns, url -urlpatterns = patterns('msp.views', +urlpatterns = patterns('portail_citoyen.apps.msp.views', url(r'^login/$', 'login', name='msp-login'), url(r'^link/$', 'link', name='msp-link'), url(r'^login-or-link/$', 'login_or_link', name='msp-login-or-link'), From a728411f08c85ce4f289a72e152b2b87d7c4070c Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Tue, 25 Mar 2014 11:15:11 +0100 Subject: [PATCH 11/13] settings: put VersionMiddleware at beginning of middleware class list --- portail_citoyen/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/portail_citoyen/settings.py b/portail_citoyen/settings.py index 83d3342..bb9c401 100644 --- a/portail_citoyen/settings.py +++ b/portail_citoyen/settings.py @@ -77,6 +77,7 @@ TEMPLATE_CONTEXT_PROCESSORS = ( ) MIDDLEWARE_CLASSES = ( + 'entrouvert.djommon.middleware.VersionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.http.ConditionalGetMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', @@ -90,7 +91,6 @@ MIDDLEWARE_CLASSES = ( 'cms.middleware.page.CurrentPageMiddleware', 'cms.middleware.user.CurrentUserMiddleware', 'cms.middleware.toolbar.ToolbarMiddleware', - 'entrouvert.djommon.middleware.VersionMiddleware', ) PORTAIL_CITOYEN_FAVICON_URL = '' From e1d05a4871775395a662638081bfd4cef953557a Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Tue, 25 Mar 2014 14:34:56 +0100 Subject: [PATCH 12/13] admin: as authentic also register the custom user model, unregister it first --- portail_citoyen/admin.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/portail_citoyen/admin.py b/portail_citoyen/admin.py index b3a3530..0aabfd0 100644 --- a/portail_citoyen/admin.py +++ b/portail_citoyen/admin.py @@ -60,6 +60,8 @@ if settings.AUTH_USER_MODEL == 'portail_citoyen.Citoyen': return self.fieldsets + if models.Citoyen in admin.site._registry: + admin.site.unregister(models.Citoyen) admin.site.register(models.Citoyen, CitoyenAdmin) from django.contrib.auth.admin import GroupAdmin From dacc8691dcc081d8f4dbbba4d4b78df39ad66eb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Schneider?= Date: Wed, 26 Mar 2014 11:15:38 +0100 Subject: [PATCH 13/13] settings: add sentry support --- portail_citoyen/settings.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/portail_citoyen/settings.py b/portail_citoyen/settings.py index bb9c401..b41c296 100644 --- a/portail_citoyen/settings.py +++ b/portail_citoyen/settings.py @@ -386,6 +386,9 @@ LOGGING = { } SOUTH_TESTS_MIGRATE = False +# Raven DSN +RAVEN_CONFIG_DSN = os.environ.get('RAVEN_CONFIG_DSN') + # Admin tools ADMIN_TOOLS_INDEX_DASHBOARD = 'portail_citoyen.dashboard.CustomIndexDashboard' ADMIN_TOOLS_APP_INDEX_DASHBOARD = 'portail_citoyen.dashboard.CustomAppIndexDashboard' @@ -476,3 +479,23 @@ if IDP_OPENID: if IDP_CAS: INSTALLED_APPS += ('authentic2.idp.idp_cas',) +if RAVEN_CONFIG_DSN: + RAVEN_CONFIG = { + 'dsn': RAVEN_CONFIG_DSN, + } + INSTALLED_APPS += ('raven.contrib.django.raven_compat', ) + LOGGING['handlers']['sentry'] = { + 'level': 'ERROR', + 'class': 'raven.contrib.django.raven_compat.handlers.SentryHandler', + } + LOGGING['loggers']['raven'] = { + 'level': 'DEBUG', + 'handlers': ['console'], + 'propagate': False, + } + LOGGING['loggers']['sentry.errors'] = { + 'level': 'DEBUG', + 'handlers': ['console'], + 'propagate': False, + } + LOGGING['loggers']['']['handlers'].append('sentry')