From 74f213e1d59e3dacc62d97610f19af6c43fa4f00 Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Tue, 13 Feb 2018 02:37:03 +0100 Subject: [PATCH 01/28] Set default value for validation_slug --- .../migrations/0007_auto_20180213_0128.py | 21 +++++++++++++++++++ membership/models.py | 12 +++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 membership/migrations/0007_auto_20180213_0128.py diff --git a/membership/migrations/0007_auto_20180213_0128.py b/membership/migrations/0007_auto_20180213_0128.py new file mode 100644 index 00000000..0dd7b54a --- /dev/null +++ b/membership/migrations/0007_auto_20180213_0128.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.4 on 2018-02-13 01:28 +from __future__ import unicode_literals + +from django.db import migrations, models +import membership.models + + +class Migration(migrations.Migration): + + dependencies = [ + ('membership', '0006_auto_20160526_0445'), + ] + + operations = [ + migrations.AlterField( + model_name='customuser', + name='validation_slug', + field=models.CharField(db_index=True, default=membership.models.get_validation_slug, max_length=50, unique=True), + ), + ] diff --git a/membership/models.py b/membership/models.py index 73804008..559b0276 100644 --- a/membership/models.py +++ b/membership/models.py @@ -59,6 +59,10 @@ class MyUserManager(BaseUserManager): return user +def get_validation_slug(): + return make_password(None) + + class CustomUser(AbstractBaseUser, PermissionsMixin): VALIDATED_CHOICES = ((0, 'Not validated'), (1, 'Validated')) site = models.ForeignKey(Site, default=1) @@ -66,8 +70,12 @@ class CustomUser(AbstractBaseUser, PermissionsMixin): email = models.EmailField(unique=True) validated = models.IntegerField(choices=VALIDATED_CHOICES, default=0) - validation_slug = models.CharField(db_index=True, unique=True, - max_length=50) + # By default, we initialize the validation_slug with appropriate value + # This is required for User(page) admin + validation_slug = models.CharField( + db_index=True, unique=True, max_length=50, + default=get_validation_slug + ) is_admin = models.BooleanField( _('staff status'), default=False, From 7f5866b777cbdfe06b9097f8eda457c99d608fba Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Tue, 13 Feb 2018 02:38:23 +0100 Subject: [PATCH 02/28] Move djangocms_admin_style above django.contrib.auth in the INSTALLED_APPS --- dynamicweb/settings/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dynamicweb/settings/base.py b/dynamicweb/settings/base.py index 47534585..3c810aa2 100644 --- a/dynamicweb/settings/base.py +++ b/dynamicweb/settings/base.py @@ -76,6 +76,7 @@ SECRET_KEY = env('DJANGO_SECRET_KEY') INSTALLED_APPS = ( # 1st migrate 'membership', + 'djangocms_admin_style', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', @@ -124,7 +125,6 @@ INSTALLED_APPS = ( # 'djangocms_teaser', 'djangocms_page_meta', 'djangocms_text_ckeditor', - 'djangocms_admin_style', 'cmsplugin_filer_file', 'cmsplugin_filer_folder', 'cmsplugin_filer_link', From 6a9232851a46a4243c228d2835942016ef4093e1 Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Tue, 13 Feb 2018 02:40:29 +0100 Subject: [PATCH 03/28] Set CMS_PERMISSION True for per page access control --- dynamicweb/settings/base.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dynamicweb/settings/base.py b/dynamicweb/settings/base.py index 3c810aa2..8684ede0 100644 --- a/dynamicweb/settings/base.py +++ b/dynamicweb/settings/base.py @@ -328,6 +328,8 @@ CMS_PLACEHOLDER_CONF = { }, } +CMS_PERMISSION=True + CACHES = { 'default': { 'BACKEND': 'django.core.cache.backends.memcached.PyLibMCCache', From 5e68fec29ecf1ea641ca5bb419c10beefe0faedf Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Tue, 13 Feb 2018 02:42:40 +0100 Subject: [PATCH 04/28] Add is_staff setter method for CustomUser --- membership/models.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/membership/models.py b/membership/models.py index 559b0276..b3cbcd91 100644 --- a/membership/models.py +++ b/membership/models.py @@ -179,6 +179,10 @@ class CustomUser(AbstractBaseUser, PermissionsMixin): # Simplest possible answer: All admins are staff return self.is_admin + @is_staff.setter + def is_staff(self, value): + self._is_staff = value + class StripeCustomer(models.Model): user = models.OneToOneField(CustomUser) From 16add66ed8001ec284ebc779e24852d3761442f1 Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Tue, 13 Feb 2018 03:01:50 +0100 Subject: [PATCH 05/28] Improve CustomUserAdmin This is required for managing djangoCMS Users (page) and also CustomUser via admin site. --- membership/admin.py | 95 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 85 insertions(+), 10 deletions(-) diff --git a/membership/admin.py b/membership/admin.py index f69ccbef..1e8d2ba8 100644 --- a/membership/admin.py +++ b/membership/admin.py @@ -1,20 +1,95 @@ +from django import forms from django.contrib import admin +from django.contrib.auth.admin import UserAdmin as BaseUserAdmin +from django.contrib.auth.forms import ReadOnlyPasswordHashField + from .models import CustomUser, StripeCustomer -from django.contrib.auth.hashers import make_password -class CustomUserAdmin(admin.ModelAdmin): - fields = ('password', 'user_permissions', 'email', 'is_admin') +# Refer https://docs.djangoproject.com/en/2.0/topics/auth/customizing/ +# for understanding custom auth user model - def save_model(self, request, obj, form, change): - password = form.cleaned_data.get('password') - if not change: - obj.validation_slug = make_password(None) +class UserCreationForm(forms.ModelForm): + """A form for creating new users. Includes all the required + fields, plus a repeated password.""" + password1 = forms.CharField(label='Password', widget=forms.PasswordInput) + password2 = forms.CharField(label='Password confirmation', + widget=forms.PasswordInput) - obj.set_password(password) - obj.save() - return obj + class Meta: + model = CustomUser + fields = ('email', 'user_permissions', 'email', 'is_admin') + + def clean_password2(self): + # Check that the two password entries match + password1 = self.cleaned_data.get("password1") + password2 = self.cleaned_data.get("password2") + if password1 and password2 and password1 != password2: + raise forms.ValidationError("Passwords don't match") + return password2 + + def save(self, commit=True): + # Save the provided password in hashed format + user = super().save(commit=False) + user.set_password(self.cleaned_data["password1"]) + if commit: + user.save() + return user + + +class UserChangeForm(forms.ModelForm): + """A form for updating users. Includes all the fields on + the user, but replaces the password field with admin's + password hash display field. + """ + password = ReadOnlyPasswordHashField( + label="Password", + help_text=( + "Raw passwords are not stored, so there is no way to see " + "this user's password, but you can change the password " + "using this form.") + ) + + class Meta: + model = CustomUser + fields = ('email', 'password', 'is_admin') + + def clean_password(self): + # Regardless of what the user provides, return the initial value. + # This is done here, rather than on the field, because the + # field does not have access to the initial value + return self.initial["password"] + + +class CustomUserAdmin(BaseUserAdmin): + # The forms to add and change user instances + form = UserChangeForm + add_form = UserCreationForm + + # The fields to be used in displaying the User model. + # These override the definitions on the base UserAdmin + # that reference specific fields on auth.User. + list_display = ( + 'email', 'is_admin', 'is_superuser' + ) + list_filter = () + fieldsets = ( + (None, {'fields': ('email', 'password')}), + ('Permissions', {'fields': ('is_admin', 'user_permissions', + 'groups')}), + ) + # add_fieldsets is not a standard ModelAdmin attribute. UserAdmin + # overrides get_fieldsets to use this attribute when creating a user. + add_fieldsets = ( + (None, { + 'classes': ('wide',), + 'fields': ('email', 'password1', 'password2')} + ), + ) + search_fields = ('email',) + ordering = ('email',) + filter_horizontal = () admin.site.register(CustomUser, CustomUserAdmin) From abf316da9e2d6f85107b87237781443bbfa1eb77 Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Tue, 13 Feb 2018 03:33:27 +0100 Subject: [PATCH 06/28] Add Change password functinality while editing a user via admin site --- membership/admin.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/membership/admin.py b/membership/admin.py index 1e8d2ba8..a4265e5e 100644 --- a/membership/admin.py +++ b/membership/admin.py @@ -75,7 +75,15 @@ class CustomUserAdmin(BaseUserAdmin): ) list_filter = () fieldsets = ( - (None, {'fields': ('email', 'password')}), + (None, {'fields': ('email',)}), + ('Change Password', + {'fields': ('password',), + 'description': "Raw passwords are not stored, so there is no way to " + "see this user's password, but you can change the " + "password using this " + "form." + } + ), ('Permissions', {'fields': ('is_admin', 'user_permissions', 'groups')}), ) From f62b33191920c9e7e9ed098fe4e5684600ffa94c Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Thu, 15 Feb 2018 10:55:41 +0100 Subject: [PATCH 07/28] Add multisite requirements --- requirements.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/requirements.txt b/requirements.txt index 7a325357..3ecb0f91 100644 --- a/requirements.txt +++ b/requirements.txt @@ -34,6 +34,7 @@ django-meta==1.2 django-meta-mixin==0.3.0 django-model-utils==2.5 django-mptt==0.8.4 +django-multisite==1.2.5 django-parler==1.6.3 django-phonenumber-field==1.1.0 django-polymorphic==0.9.2 @@ -97,3 +98,4 @@ billiard==3.5.0.3 amqp==2.2.1 vine==1.1.4 cdist==4.7.0 +https://github.com/nephila/djangocms-multisite/archive/master.zip From a30e8a6adfe6236670110586ed550ad4da0c335d Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Thu, 15 Feb 2018 10:58:06 +0100 Subject: [PATCH 08/28] Configure multisite SITE_ID --- dynamicweb/settings/base.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dynamicweb/settings/base.py b/dynamicweb/settings/base.py index 8684ede0..4c904891 100644 --- a/dynamicweb/settings/base.py +++ b/dynamicweb/settings/base.py @@ -54,7 +54,8 @@ PROJECT_DIR = os.path.abspath( # load .env file dotenv.read_dotenv("{0}/.env".format(PROJECT_DIR)) -SITE_ID = 1 +from multisite import SiteID +SITE_ID = SiteID(default=1) APP_ROOT_ENDPOINT = "/" APPEND_SLASH = True From cb5dd8a5924609d6ab3487db985ed455e698f725 Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Thu, 15 Feb 2018 11:58:44 +0100 Subject: [PATCH 09/28] REmove aldryn_newsblog for the moment --- dynamicweb/settings/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dynamicweb/settings/base.py b/dynamicweb/settings/base.py index 4c904891..c8a1b7b4 100644 --- a/dynamicweb/settings/base.py +++ b/dynamicweb/settings/base.py @@ -105,7 +105,7 @@ INSTALLED_APPS = ( 'aldryn_boilerplates', 'aldryn_categories', 'aldryn_common', - 'aldryn_newsblog', + #'aldryn_newsblog', 'aldryn_people', 'aldryn_reversion', 'aldryn_translation_tools', From bea1f40b1b6c613ec9d6291353872adf87c204cf Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Thu, 15 Feb 2018 17:37:51 +0100 Subject: [PATCH 10/28] Add multisite dependent apps and corresponding settings --- dynamicweb/settings/base.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/dynamicweb/settings/base.py b/dynamicweb/settings/base.py index c8a1b7b4..a267daee 100644 --- a/dynamicweb/settings/base.py +++ b/dynamicweb/settings/base.py @@ -85,6 +85,8 @@ INSTALLED_APPS = ( 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.sites', + 'multisite', + 'djangocms_multisite', 'easy_thumbnails', 'utils', 'stored_messages', @@ -164,6 +166,8 @@ MIDDLEWARE_CLASSES = ( 'cms.middleware.page.CurrentPageMiddleware', 'cms.middleware.toolbar.ToolbarMiddleware', 'cms.middleware.language.LanguageCookieMiddleware', + 'multisite.middleware.DynamicSiteMiddleware', + 'djangocms_multisite.middleware.CMSMultiSiteMiddleware', ) CSRF_FAILURE_VIEW = 'hosting.views.forbidden_view' @@ -510,6 +514,16 @@ STRIPE_API_PRIVATE_KEY_TEST = env('STRIPE_API_PRIVATE_KEY_TEST') ANONYMOUS_USER_NAME = 'anonymous@ungleich.ch' GUARDIAN_GET_INIT_ANONYMOUS_USER = 'membership.models.get_anonymous_user_instance' +MULTISITE_CMS_URLS = { + 'www.example.com:8000': 'dynamicweb.urls1', + 'www.example2.com:8000': 'dynamicweb.urls2', +} +MULTISITE_CMS_ALIASES = { + 'www.example.com': ('alias1.example.com', 'alias2.example.com',), + 'www.example2.com': ('alias1.example2.com', 'alias2.example2.com',), +} +MULTISITE_CMS_FALLBACK = 'www.example.com' + ############################################# # configurations for opennebula-integration # ############################################# From d7d831a831fd10b6c70f96bcb22b24a3d05dadb4 Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Thu, 15 Feb 2018 17:57:54 +0100 Subject: [PATCH 11/28] Comment out debug_toolbar for DEBUG version --- dynamicweb/settings/local.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dynamicweb/settings/local.py b/dynamicweb/settings/local.py index 1b03f3fe..4ea3dc7e 100644 --- a/dynamicweb/settings/local.py +++ b/dynamicweb/settings/local.py @@ -19,5 +19,6 @@ MIDDLEWARE_CLASSES += ("debug_toolbar.middleware.DebugToolbarMiddleware",) INSTALLED_APPS += ( 'django_extensions', - 'debug_toolbar' + # debug_toolbar seems to conflict with multisite (and djangocms_multisite) + # 'debug_toolbar' ) From df35fd1f3549502d486efc2f2fca940a86e52ae5 Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Thu, 15 Feb 2018 17:58:30 +0100 Subject: [PATCH 12/28] Add urls for example1 and example2 --- dynamicweb/urls1.py | 72 +++++++++++++++++++++++++++++++++++++++++++++ dynamicweb/urls2.py | 72 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 144 insertions(+) create mode 100644 dynamicweb/urls1.py create mode 100644 dynamicweb/urls2.py diff --git a/dynamicweb/urls1.py b/dynamicweb/urls1.py new file mode 100644 index 00000000..98a363f4 --- /dev/null +++ b/dynamicweb/urls1.py @@ -0,0 +1,72 @@ +from django.conf.urls import include, url +from django.contrib import admin +from django.conf.urls.i18n import i18n_patterns +from django.conf.urls.static import static +from django.views import i18n, static as static_view + +from django.conf import settings +from hosting.views import ( + RailsHostingView, DjangoHostingView, NodeJSHostingView +) +from membership import urls as membership_urls +from ungleich_page.views import LandingView +from django.views.generic import RedirectView +from django.core.urlresolvers import reverse_lazy +import debug_toolbar + +# urlpatterns = [ +# url(r'^index.html$', LandingView.as_view()), +# url(r'^open_api/', include('opennebula_api.urls', +# namespace='opennebula_api')), +# url(r'^railshosting/', RailsHostingView.as_view(), +# name="rails.hosting"), +# url(r'^nodehosting/', NodeJSHostingView.as_view(), +# name="node.hosting"), +# url(r'^djangohosting/', DjangoHostingView.as_view(), +# name="django.hosting"), +# url(r'^nosystemd/', include('nosystemd.urls', namespace="nosystemd")), +# url(r'^taggit_autosuggest/', include('taggit_autosuggest.urls')), +# url(r'^jsi18n/(?P\S+?)/$', +# i18n.javascript_catalog), +# ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) + +# urlpatterns += i18n_patterns( +# url(r'^hosting/', include('hosting.urls', namespace="hosting")), +# ) + +# note the django CMS URLs included via i18n_patterns +urlpatterns = i18n_patterns( + # url(r'^$', LandingView.as_view()), + url(r'^admin/', include(admin.site.urls)), + # url(r'^datacenterlight/', + # include('datacenterlight.urls', namespace="datacenterlight")), + # url(r'^hosting/', RedirectView.as_view( + # url=reverse_lazy('hosting:login')), name='redirect_hosting_login'), + # url(r'^alplora/', include('alplora.urls', namespace="alplora")), + # url(r'^membership/', include(membership_urls)), + # url(r'^digitalglarus/', include('digitalglarus.urls', + # namespace="digitalglarus")), + # url(r'^blog/', include('ungleich.urls', namespace='ungleich')), + # url(r'^', + # include('ungleich_page.urls', + # namespace='ungleich_page'), + # name='ungleich_page'), + # url(r'^cms/blog/', + # include('ungleich.urls', namespace='ungleich')), + # url( + # r'^blog/(?P\d{4})/(?P\d{1,2})/(?P\d{1,2})/(?P\w[-\w]*)/$', + # RedirectView.as_view(pattern_name='ungleich:post-detail')), + # url(r'^blog/|cms/$', RedirectView.as_view( + # url=reverse_lazy('ungleich:post-list')), name='blog_list_view'), + url(r'^example1/', include('cms.urls')), +) + +urlpatterns += [ + url(r'^media/(?P.*)$', + static_view.serve, { + 'document_root': settings.MEDIA_ROOT, + }), +] + +# if settings.DEBUG: +# urlpatterns += [url(r'^__debug__/', include(debug_toolbar.urls))] diff --git a/dynamicweb/urls2.py b/dynamicweb/urls2.py new file mode 100644 index 00000000..8329f50b --- /dev/null +++ b/dynamicweb/urls2.py @@ -0,0 +1,72 @@ +from django.conf.urls import include, url +from django.contrib import admin +from django.conf.urls.i18n import i18n_patterns +from django.conf.urls.static import static +from django.views import i18n, static as static_view + +from django.conf import settings +from hosting.views import ( + RailsHostingView, DjangoHostingView, NodeJSHostingView +) +from membership import urls as membership_urls +from ungleich_page.views import LandingView +from django.views.generic import RedirectView +from django.core.urlresolvers import reverse_lazy +import debug_toolbar + +urlpatterns = [ + url(r'^index.html$', LandingView.as_view()), + url(r'^open_api/', include('opennebula_api.urls', + namespace='opennebula_api')), + url(r'^railshosting/', RailsHostingView.as_view(), + name="rails.hosting"), + url(r'^nodehosting/', NodeJSHostingView.as_view(), + name="node.hosting"), + url(r'^djangohosting/', DjangoHostingView.as_view(), + name="django.hosting"), + url(r'^nosystemd/', include('nosystemd.urls', namespace="nosystemd")), + url(r'^taggit_autosuggest/', include('taggit_autosuggest.urls')), + url(r'^jsi18n/(?P\S+?)/$', + i18n.javascript_catalog), +] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) + +urlpatterns += i18n_patterns( + url(r'^hosting/', include('hosting.urls', namespace="hosting")), +) + +# note the django CMS URLs included via i18n_patterns +urlpatterns += i18n_patterns( + url(r'^$', LandingView.as_view()), + url(r'^admin/', include(admin.site.urls)), + url(r'^datacenterlight/', + include('datacenterlight.urls', namespace="datacenterlight")), + url(r'^hosting/', RedirectView.as_view( + url=reverse_lazy('hosting:login')), name='redirect_hosting_login'), + url(r'^alplora/', include('alplora.urls', namespace="alplora")), + url(r'^membership/', include(membership_urls)), + url(r'^digitalglarus/', include('digitalglarus.urls', + namespace="digitalglarus")), + # url(r'^blog/', include('ungleich.urls', namespace='ungleich')), + url(r'^', + include('ungleich_page.urls', + namespace='ungleich_page'), + name='ungleich_page'), + # url(r'^cms/blog/', + # include('ungleich.urls', namespace='ungleich')), + # url( + # r'^blog/(?P\d{4})/(?P\d{1,2})/(?P\d{1,2})/(?P\w[-\w]*)/$', + # RedirectView.as_view(pattern_name='ungleich:post-detail')), + # url(r'^blog/|cms/$', RedirectView.as_view( + # url=reverse_lazy('ungleich:post-list')), name='blog_list_view'), + url(r'^example2/', include('cms.urls')), +) + +urlpatterns += [ + url(r'^media/(?P.*)$', + static_view.serve, { + 'document_root': settings.MEDIA_ROOT, + }), +] + +if settings.DEBUG: + urlpatterns += [url(r'^__debug__/', include(debug_toolbar.urls))] From c1c8b38cf291e9b3e55bfd3520ac8b0c49680687 Mon Sep 17 00:00:00 2001 From: PCoder Date: Sat, 17 Feb 2018 11:30:36 +0100 Subject: [PATCH 13/28] Update multisite cms urls, aliases and fallback urls --- dynamicweb/settings/base.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/dynamicweb/settings/base.py b/dynamicweb/settings/base.py index a267daee..aca3e05d 100644 --- a/dynamicweb/settings/base.py +++ b/dynamicweb/settings/base.py @@ -515,14 +515,12 @@ ANONYMOUS_USER_NAME = 'anonymous@ungleich.ch' GUARDIAN_GET_INIT_ANONYMOUS_USER = 'membership.models.get_anonymous_user_instance' MULTISITE_CMS_URLS = { - 'www.example.com:8000': 'dynamicweb.urls1', - 'www.example2.com:8000': 'dynamicweb.urls2', + 'blog-dev2.ungleich.ch': 'dynamicweb.urls', + 'nuglarus-dev2.ungleich.ch': 'dynamicweb.urls_multi', } MULTISITE_CMS_ALIASES = { - 'www.example.com': ('alias1.example.com', 'alias2.example.com',), - 'www.example2.com': ('alias1.example2.com', 'alias2.example2.com',), } -MULTISITE_CMS_FALLBACK = 'www.example.com' +MULTISITE_CMS_FALLBACK = 'blog-dev2.ungleich.ch' ############################################# # configurations for opennebula-integration # From bca2956e0676b2edde0dbed205519ec3e888996b Mon Sep 17 00:00:00 2001 From: PCoder Date: Sat, 17 Feb 2018 11:33:28 +0100 Subject: [PATCH 14/28] Rename urls1.py to urls_multi.py --- dynamicweb/{urls1.py => urls_multi.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename dynamicweb/{urls1.py => urls_multi.py} (100%) diff --git a/dynamicweb/urls1.py b/dynamicweb/urls_multi.py similarity index 100% rename from dynamicweb/urls1.py rename to dynamicweb/urls_multi.py From be3aeb45e7c338a24f107aaf18503c7b3e5b89cb Mon Sep 17 00:00:00 2001 From: PCoder Date: Sat, 17 Feb 2018 11:33:48 +0100 Subject: [PATCH 15/28] Remove urls2.py --- dynamicweb/urls2.py | 72 --------------------------------------------- 1 file changed, 72 deletions(-) delete mode 100644 dynamicweb/urls2.py diff --git a/dynamicweb/urls2.py b/dynamicweb/urls2.py deleted file mode 100644 index 8329f50b..00000000 --- a/dynamicweb/urls2.py +++ /dev/null @@ -1,72 +0,0 @@ -from django.conf.urls import include, url -from django.contrib import admin -from django.conf.urls.i18n import i18n_patterns -from django.conf.urls.static import static -from django.views import i18n, static as static_view - -from django.conf import settings -from hosting.views import ( - RailsHostingView, DjangoHostingView, NodeJSHostingView -) -from membership import urls as membership_urls -from ungleich_page.views import LandingView -from django.views.generic import RedirectView -from django.core.urlresolvers import reverse_lazy -import debug_toolbar - -urlpatterns = [ - url(r'^index.html$', LandingView.as_view()), - url(r'^open_api/', include('opennebula_api.urls', - namespace='opennebula_api')), - url(r'^railshosting/', RailsHostingView.as_view(), - name="rails.hosting"), - url(r'^nodehosting/', NodeJSHostingView.as_view(), - name="node.hosting"), - url(r'^djangohosting/', DjangoHostingView.as_view(), - name="django.hosting"), - url(r'^nosystemd/', include('nosystemd.urls', namespace="nosystemd")), - url(r'^taggit_autosuggest/', include('taggit_autosuggest.urls')), - url(r'^jsi18n/(?P\S+?)/$', - i18n.javascript_catalog), -] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) - -urlpatterns += i18n_patterns( - url(r'^hosting/', include('hosting.urls', namespace="hosting")), -) - -# note the django CMS URLs included via i18n_patterns -urlpatterns += i18n_patterns( - url(r'^$', LandingView.as_view()), - url(r'^admin/', include(admin.site.urls)), - url(r'^datacenterlight/', - include('datacenterlight.urls', namespace="datacenterlight")), - url(r'^hosting/', RedirectView.as_view( - url=reverse_lazy('hosting:login')), name='redirect_hosting_login'), - url(r'^alplora/', include('alplora.urls', namespace="alplora")), - url(r'^membership/', include(membership_urls)), - url(r'^digitalglarus/', include('digitalglarus.urls', - namespace="digitalglarus")), - # url(r'^blog/', include('ungleich.urls', namespace='ungleich')), - url(r'^', - include('ungleich_page.urls', - namespace='ungleich_page'), - name='ungleich_page'), - # url(r'^cms/blog/', - # include('ungleich.urls', namespace='ungleich')), - # url( - # r'^blog/(?P\d{4})/(?P\d{1,2})/(?P\d{1,2})/(?P\w[-\w]*)/$', - # RedirectView.as_view(pattern_name='ungleich:post-detail')), - # url(r'^blog/|cms/$', RedirectView.as_view( - # url=reverse_lazy('ungleich:post-list')), name='blog_list_view'), - url(r'^example2/', include('cms.urls')), -) - -urlpatterns += [ - url(r'^media/(?P.*)$', - static_view.serve, { - 'document_root': settings.MEDIA_ROOT, - }), -] - -if settings.DEBUG: - urlpatterns += [url(r'^__debug__/', include(debug_toolbar.urls))] From 4c5ff149f728a2c5dbb51b18a6a0e525fd482a5d Mon Sep 17 00:00:00 2001 From: PCoder Date: Sat, 17 Feb 2018 16:52:54 +0100 Subject: [PATCH 16/28] Some multisite parameters --- dynamicweb/settings/base.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/dynamicweb/settings/base.py b/dynamicweb/settings/base.py index aca3e05d..50b762ce 100644 --- a/dynamicweb/settings/base.py +++ b/dynamicweb/settings/base.py @@ -515,12 +515,18 @@ ANONYMOUS_USER_NAME = 'anonymous@ungleich.ch' GUARDIAN_GET_INIT_ANONYMOUS_USER = 'membership.models.get_anonymous_user_instance' MULTISITE_CMS_URLS = { + 'dynamicweb-development2.ungleich.ch': 'dynamicweb.urls', 'blog-dev2.ungleich.ch': 'dynamicweb.urls', 'nuglarus-dev2.ungleich.ch': 'dynamicweb.urls_multi', } MULTISITE_CMS_ALIASES = { } MULTISITE_CMS_FALLBACK = 'blog-dev2.ungleich.ch' +MULTISITE_FALLBACK = 'django.views.generic.base.RedirectView' + +MULTISITE_FALLBACK_KWARGS = {'url': 'https://datacenterlight.ch/', + 'permanent': False} + ############################################# # configurations for opennebula-integration # From aa63515ff5950652f5fc0fdfd4994ac0f8f913cd Mon Sep 17 00:00:00 2001 From: PCoder Date: Sat, 17 Feb 2018 16:54:11 +0100 Subject: [PATCH 17/28] Change url for multi domains --- dynamicweb/urls_multi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dynamicweb/urls_multi.py b/dynamicweb/urls_multi.py index 98a363f4..9ec725f9 100644 --- a/dynamicweb/urls_multi.py +++ b/dynamicweb/urls_multi.py @@ -58,7 +58,7 @@ urlpatterns = i18n_patterns( # RedirectView.as_view(pattern_name='ungleich:post-detail')), # url(r'^blog/|cms/$', RedirectView.as_view( # url=reverse_lazy('ungleich:post-list')), name='blog_list_view'), - url(r'^example1/', include('cms.urls')), + url(r'^multi/', include('cms.urls')), ) urlpatterns += [ From d5a0224476a8d43e8c92673dc7fbbf3e48b1bddf Mon Sep 17 00:00:00 2001 From: PCoder Date: Sat, 17 Feb 2018 17:01:07 +0100 Subject: [PATCH 18/28] Set FILER_ENABLE_PERMISSIONS to True --- dynamicweb/settings/base.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dynamicweb/settings/base.py b/dynamicweb/settings/base.py index 50b762ce..9ceb909c 100644 --- a/dynamicweb/settings/base.py +++ b/dynamicweb/settings/base.py @@ -527,6 +527,8 @@ MULTISITE_FALLBACK = 'django.views.generic.base.RedirectView' MULTISITE_FALLBACK_KWARGS = {'url': 'https://datacenterlight.ch/', 'permanent': False} +FILER_ENABLE_PERMISSIONS = True + ############################################# # configurations for opennebula-integration # From c1d98603e6da828a3b0ae7c722a6163acca24d5f Mon Sep 17 00:00:00 2001 From: PCoder Date: Tue, 20 Feb 2018 06:25:02 +0100 Subject: [PATCH 19/28] Obtain value for MULTISITE_CMS_URLS from env --- dynamicweb/settings/base.py | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/dynamicweb/settings/base.py b/dynamicweb/settings/base.py index 9ceb909c..328b7fa6 100644 --- a/dynamicweb/settings/base.py +++ b/dynamicweb/settings/base.py @@ -514,18 +514,29 @@ STRIPE_API_PRIVATE_KEY_TEST = env('STRIPE_API_PRIVATE_KEY_TEST') ANONYMOUS_USER_NAME = 'anonymous@ungleich.ch' GUARDIAN_GET_INIT_ANONYMOUS_USER = 'membership.models.get_anonymous_user_instance' -MULTISITE_CMS_URLS = { - 'dynamicweb-development2.ungleich.ch': 'dynamicweb.urls', - 'blog-dev2.ungleich.ch': 'dynamicweb.urls', - 'nuglarus-dev2.ungleich.ch': 'dynamicweb.urls_multi', -} +UNGLEICH_SITE_CONFIGS = env('UNGLEICH_SITE_CONFIGS') + +MULTISITE_CMS_URLS = {} +if UNGLEICH_SITE_CONFIGS == "": + raise Exception("Please define UNGLEICH_SITE_CONFIGS in your .env") +else: + ungleich_site_config_list = UNGLEICH_SITE_CONFIGS.split(";") + for ungliech_site_config in ungleich_site_config_list: + ungliech_site_params = ungliech_site_config.split(":") + if len(ungliech_site_params) <= 1: + raise Exception("Incomplete UNGLEICH_SITE_CONFIGS") + else: + MULTISITE_CMS_URLS[ungliech_site_params[0]] = ungliech_site_params[1] + MULTISITE_CMS_ALIASES = { } -MULTISITE_CMS_FALLBACK = 'blog-dev2.ungleich.ch' +MULTISITE_CMS_FALLBACK = env('MULTISITE_CMS_FALLBACK') +if MULTISITE_CMS_FALLBACK == '': + MULTISITE_CMS_FALLBACK = 'datacenterlight.ch' MULTISITE_FALLBACK = 'django.views.generic.base.RedirectView' - -MULTISITE_FALLBACK_KWARGS = {'url': 'https://datacenterlight.ch/', - 'permanent': False} +MULTISITE_FALLBACK_KWARGS = { + 'url': 'https://{}/'.format(MULTISITE_CMS_FALLBACK), 'permanent': False +} FILER_ENABLE_PERMISSIONS = True From cc4f0dc32d4796f64a882a901948a73a97b5b108 Mon Sep 17 00:00:00 2001 From: PCoder Date: Tue, 20 Feb 2018 06:53:29 +0100 Subject: [PATCH 20/28] Cleanup unused code from urls_multi --- dynamicweb/urls_multi.py | 63 +++------------------------------------- 1 file changed, 4 insertions(+), 59 deletions(-) diff --git a/dynamicweb/urls_multi.py b/dynamicweb/urls_multi.py index 9ec725f9..74ce1fab 100644 --- a/dynamicweb/urls_multi.py +++ b/dynamicweb/urls_multi.py @@ -1,63 +1,11 @@ -from django.conf.urls import include, url -from django.contrib import admin -from django.conf.urls.i18n import i18n_patterns -from django.conf.urls.static import static -from django.views import i18n, static as static_view - from django.conf import settings -from hosting.views import ( - RailsHostingView, DjangoHostingView, NodeJSHostingView -) -from membership import urls as membership_urls -from ungleich_page.views import LandingView -from django.views.generic import RedirectView -from django.core.urlresolvers import reverse_lazy -import debug_toolbar +from django.conf.urls import include, url +from django.conf.urls.i18n import i18n_patterns +from django.contrib import admin +from django.views import static as static_view -# urlpatterns = [ -# url(r'^index.html$', LandingView.as_view()), -# url(r'^open_api/', include('opennebula_api.urls', -# namespace='opennebula_api')), -# url(r'^railshosting/', RailsHostingView.as_view(), -# name="rails.hosting"), -# url(r'^nodehosting/', NodeJSHostingView.as_view(), -# name="node.hosting"), -# url(r'^djangohosting/', DjangoHostingView.as_view(), -# name="django.hosting"), -# url(r'^nosystemd/', include('nosystemd.urls', namespace="nosystemd")), -# url(r'^taggit_autosuggest/', include('taggit_autosuggest.urls')), -# url(r'^jsi18n/(?P\S+?)/$', -# i18n.javascript_catalog), -# ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) - -# urlpatterns += i18n_patterns( -# url(r'^hosting/', include('hosting.urls', namespace="hosting")), -# ) - -# note the django CMS URLs included via i18n_patterns urlpatterns = i18n_patterns( - # url(r'^$', LandingView.as_view()), url(r'^admin/', include(admin.site.urls)), - # url(r'^datacenterlight/', - # include('datacenterlight.urls', namespace="datacenterlight")), - # url(r'^hosting/', RedirectView.as_view( - # url=reverse_lazy('hosting:login')), name='redirect_hosting_login'), - # url(r'^alplora/', include('alplora.urls', namespace="alplora")), - # url(r'^membership/', include(membership_urls)), - # url(r'^digitalglarus/', include('digitalglarus.urls', - # namespace="digitalglarus")), - # url(r'^blog/', include('ungleich.urls', namespace='ungleich')), - # url(r'^', - # include('ungleich_page.urls', - # namespace='ungleich_page'), - # name='ungleich_page'), - # url(r'^cms/blog/', - # include('ungleich.urls', namespace='ungleich')), - # url( - # r'^blog/(?P\d{4})/(?P\d{1,2})/(?P\d{1,2})/(?P\w[-\w]*)/$', - # RedirectView.as_view(pattern_name='ungleich:post-detail')), - # url(r'^blog/|cms/$', RedirectView.as_view( - # url=reverse_lazy('ungleich:post-list')), name='blog_list_view'), url(r'^multi/', include('cms.urls')), ) @@ -67,6 +15,3 @@ urlpatterns += [ 'document_root': settings.MEDIA_ROOT, }), ] - -# if settings.DEBUG: -# urlpatterns += [url(r'^__debug__/', include(debug_toolbar.urls))] From de4d1bc7c81e6dacbac519ca55b53e89582e8974 Mon Sep 17 00:00:00 2001 From: PCoder Date: Tue, 20 Feb 2018 06:55:09 +0100 Subject: [PATCH 21/28] Change the multisite url prefix multi to ncms --- dynamicweb/urls_multi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dynamicweb/urls_multi.py b/dynamicweb/urls_multi.py index 74ce1fab..09bbb8dc 100644 --- a/dynamicweb/urls_multi.py +++ b/dynamicweb/urls_multi.py @@ -6,7 +6,7 @@ from django.views import static as static_view urlpatterns = i18n_patterns( url(r'^admin/', include(admin.site.urls)), - url(r'^multi/', include('cms.urls')), + url(r'^ncms/', include('cms.urls')), ) urlpatterns += [ From 593c83aeeee12c9e6511ceb0de760b815fd7af30 Mon Sep 17 00:00:00 2001 From: PCoder Date: Tue, 20 Feb 2018 06:58:08 +0100 Subject: [PATCH 22/28] Autoformat membership/admin.py --- membership/admin.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/membership/admin.py b/membership/admin.py index a4265e5e..3aefa780 100644 --- a/membership/admin.py +++ b/membership/admin.py @@ -82,8 +82,8 @@ class CustomUserAdmin(BaseUserAdmin): "see this user's password, but you can change the " "password using this " "form." - } - ), + } + ), ('Permissions', {'fields': ('is_admin', 'user_permissions', 'groups')}), ) From 05e49b04bb1bce167a028c16f432a91359b31af8 Mon Sep 17 00:00:00 2001 From: PCoder Date: Tue, 20 Feb 2018 07:05:56 +0100 Subject: [PATCH 23/28] Revert back aldryn_newsblog app --- dynamicweb/settings/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dynamicweb/settings/base.py b/dynamicweb/settings/base.py index 328b7fa6..141796c0 100644 --- a/dynamicweb/settings/base.py +++ b/dynamicweb/settings/base.py @@ -107,7 +107,7 @@ INSTALLED_APPS = ( 'aldryn_boilerplates', 'aldryn_categories', 'aldryn_common', - #'aldryn_newsblog', + 'aldryn_newsblog', 'aldryn_people', 'aldryn_reversion', 'aldryn_translation_tools', From cb102fe62248a8d68db2f65400323aa707f1c0e4 Mon Sep 17 00:00:00 2001 From: PCoder Date: Tue, 20 Feb 2018 07:20:01 +0100 Subject: [PATCH 24/28] Use ungleich's fork of djangocms-multisite --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 3ecb0f91..43ba31cb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -98,4 +98,4 @@ billiard==3.5.0.3 amqp==2.2.1 vine==1.1.4 cdist==4.7.0 -https://github.com/nephila/djangocms-multisite/archive/master.zip +git+https://github.com/ungleich/djangocms-multisite.git#egg=djangocms_multisite From 7f6a66bc16f172486e6a6652e28297142b7abf09 Mon Sep 17 00:00:00 2001 From: PCoder Date: Tue, 20 Feb 2018 08:25:43 +0100 Subject: [PATCH 25/28] Update django-multisite version --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 43ba31cb..85a41841 100644 --- a/requirements.txt +++ b/requirements.txt @@ -34,7 +34,7 @@ django-meta==1.2 django-meta-mixin==0.3.0 django-model-utils==2.5 django-mptt==0.8.4 -django-multisite==1.2.5 +django-multisite==1.4.1 django-parler==1.6.3 django-phonenumber-field==1.1.0 django-polymorphic==0.9.2 From 575835aa05f3ab6de4c871de539351e6a3498018 Mon Sep 17 00:00:00 2001 From: PCoder Date: Tue, 20 Feb 2018 08:48:19 +0100 Subject: [PATCH 26/28] Load multisite urls using json --- dynamicweb/settings/base.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/dynamicweb/settings/base.py b/dynamicweb/settings/base.py index 141796c0..78d2db44 100644 --- a/dynamicweb/settings/base.py +++ b/dynamicweb/settings/base.py @@ -5,6 +5,7 @@ Copyright 2015 ungleich. # -*- coding: utf-8 -*- # Build paths inside the project like this: os.path.join(BASE_DIR, ...) import os +import json from django.utils.translation import ugettext_lazy as _ @@ -520,13 +521,14 @@ MULTISITE_CMS_URLS = {} if UNGLEICH_SITE_CONFIGS == "": raise Exception("Please define UNGLEICH_SITE_CONFIGS in your .env") else: - ungleich_site_config_list = UNGLEICH_SITE_CONFIGS.split(";") - for ungliech_site_config in ungleich_site_config_list: - ungliech_site_params = ungliech_site_config.split(":") - if len(ungliech_site_params) <= 1: - raise Exception("Incomplete UNGLEICH_SITE_CONFIGS") - else: - MULTISITE_CMS_URLS[ungliech_site_params[0]] = ungliech_site_params[1] + try: + configs_dict=json.loads(UNGLEICH_SITE_CONFIGS) + except ValueError as verr: + raise Exception("UNGLEICH_SITE_CONFIGS is not a valid JSON") + else: + MULTISITE_CMS_URLS = { + k:v['MULTISITE_CMS_URL'] for (k,v) in configs_dict.items() + } MULTISITE_CMS_ALIASES = { } From fcd11c93c28af0c5f941a6d15e9c3ca5799753e0 Mon Sep 17 00:00:00 2001 From: PCoder Date: Tue, 20 Feb 2018 09:23:24 +0100 Subject: [PATCH 27/28] Add UNGLEICH_SITE_CONFIGS env variable to travis.yml --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c306c1f9..6a3cca25 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ python: # - "3.6" env: - - DJANGO_SECRET_KEY=0 OPENNEBULA_USERNAME='test' OPENNEBULA_PASSWORD='test' OPENNEBULA_PROTOCOL='http' OPENNEBULA_DOMAIN='test_domain' OPENNEBULA_PORT='2633' OPENNEBULA_ENDPOINT='/RPC2' DCL_TEXT='Data Center Light' CELERY_MAX_RETRIES=0 + - DJANGO_SECRET_KEY=0 OPENNEBULA_USERNAME='test' OPENNEBULA_PASSWORD='test' OPENNEBULA_PROTOCOL='http' OPENNEBULA_DOMAIN='test_domain' OPENNEBULA_PORT='2633' OPENNEBULA_ENDPOINT='/RPC2' DCL_TEXT='Data Center Light' CELERY_MAX_RETRIES=0 UNGLEICH_SITE_CONFIGS='{"localhost":{"MULTISITE_CMS_URL":"dynamicweb.urls"}}' # install dependencies install: "pip install -r requirements.txt" script: From 4035ffcfd4d407a9d3b39f8c61bac316b6b10ced Mon Sep 17 00:00:00 2001 From: PCoder Date: Thu, 22 Feb 2018 07:07:26 +0100 Subject: [PATCH 28/28] Log the error also --- dynamicweb/settings/base.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dynamicweb/settings/base.py b/dynamicweb/settings/base.py index 78d2db44..b3bb0d20 100644 --- a/dynamicweb/settings/base.py +++ b/dynamicweb/settings/base.py @@ -524,7 +524,9 @@ else: try: configs_dict=json.loads(UNGLEICH_SITE_CONFIGS) except ValueError as verr: - raise Exception("UNGLEICH_SITE_CONFIGS is not a valid JSON") + raise Exception("UNGLEICH_SITE_CONFIGS is not a valid JSON: {}".format( + str(verr) + )) else: MULTISITE_CMS_URLS = { k:v['MULTISITE_CMS_URL'] for (k,v) in configs_dict.items()