DjangoCMS with Aldryn Newsblog urls clash - issue adding new non-blog pages - django-cms

I am using Aldryn Newsblog and Aldryn FAQ in my DjangoCMS project. When trying to add a new page that is not a blog page, but just a normal CMS page, I get the following error:
Seems like Aldryn Newsblog rewrites the urls and sets itself as the default root.
Here's my urls.py file:
from __future__ import absolute_import, print_function, unicode_literals
from cms.sitemaps import CMSSitemap
from django.conf import settings
from django.conf.urls import * # NOQA
from django.conf.urls.i18n import i18n_patterns
from django.contrib import admin
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
admin.autodiscover()
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)), # NOQA
url(r'^sitemap\.xml$', 'django.contrib.sitemaps.views.sitemap',
{'sitemaps': {'cmspages': CMSSitemap}}),
url(r'^select2/', include('django_select2.urls')),
url(r'^', include('cms.urls')),
)
# This is only needed when using runserver.
if settings.DEBUG:
urlpatterns = patterns('',
url(r'^media/(?P<path>.*)$', 'django.views.static.serve', # NOQA
{'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),
) + staticfiles_urlpatterns() + urlpatterns # NOQA
How to I tweak it to account for Aldryn Newsblog?

I solved this by going to my Blog page -> Advanced Settings -> Application -> deselect "NewsBlog", select "------" (none).
I was then able to create a new page "Home", turned Application -> NewsBlog back on for my blog page and all works fine.

I can't comment yet, and I know this isn't proper protocol for an answer, but I simply can't avoid thanking dmk12 for this solution. After two days of searching/going insane, this was the only mention of this technique, and it's the only thing that fixed my home page loading errors. It definitely deserves more attention, because it must be happening to more than just us three Aldryn users.
P.S. I have no idea how you figured that out, but I'm really glad you did.

Related

Django3 Include path/The include urls.py not showing up the templates

I am pretty new to python Django; I am trying to figure out what exactly I am missing from the last few hours.
here is my code structure
url.py
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('signup', views.signupuser, name="signupuser"),
path ('', views.home, name='home'),
path ('socialcard', views.create_social_card, name='create_social_card'),
path ('dashboard/', include('dashboard.urls')),
]
Then I created another URL set in the dashboard app; here is the code.
From django.shortcuts import render
# Create your views here.
def dashboard(request):
home="dashboard"
return render(request, 'dashboard.html', {'home':home})
I am getting the following error,
TemplateDoesNotExist at /dashboard/
dashboard.html
I don't know what I am missing, I have added the templates folder in the app and have also added the subfolder dashboard. like this dashboard/templates/dashboard, and then there reside dashboard.html
When I add the template path as base.html, it loads up an empty page, doesn't display any error. So I don't know what exactly I am missing.
Well as all beginners do silly mistakes...I forgot to define my app in the setting.
I would advise all beginners that add the app in the setting as soon as you start an app.

moment.js change locale not working

My project is a react project.
My website is a mutilanguage website, when I change the web language. moment.locale(lang) not working.
My code is:
const startDate = moment.utc(start).locale(lang);
const endDate = moment.utc(end).locale(lang);
whatever I set lang I check the startDate.locale() always is 'en'
startDate.format('ll') result always is English.
If the project was created using create-react-app, moment locales were probably excluded by default.
This is now documented in the "Moment.js locales are missing" section of create-react-app's troubleshooting guide.
Solution: explicitly import locales in addition to 'moment':
import moment from 'moment';
import 'moment/locale/fr';
import 'moment/locale/es';
// etc. as required
According to this github issue, from 2022 on or so, it has to be imported like so:
import moment from 'moment';
import 'moment/dist/locale/de';
moment.locale('de');
if this doesn't work, try this change:
import moment from 'moment/dist/moment';
I think if you do
import 'moment/min/locales'
Instead of individual import of each locale.
In my case it resolve my problem
I found the solution here: https://stackoverflow.com/a/55334751/8318855
You should use the moment.updateLocale function

Getting the interface of a Zope 3 browser layer knowing only it's name

Having a Plone skin interface registered as follow:
<interface
interface=".interfaces.IThemeSpecific"
type="zope.publisher.interfaces.browser.IBrowserSkinType"
name="My Theme Name"
/>
What is the simplest way to get the interface (my.app.browser.interfaces.IThemeSpecific) knowing the name ("My Theme Name")?
Probably this:
>>> from zope.component import getUtility
>>> from zope.publisher.interfaces.browser import IBrowserSkinType
>>> getUtility(IBrowserSkinType, name="Old Plone 3 Custom Theme")
<InterfaceClass plonetheme.classic.browser.interfaces.IThemeSpecific>
If you have a buildout where this plone skin is installed, adding the collective.recipe.omelette to it will help you later being able to grep on all your packages for it.
So something like this will work:
grep -R --include=*.zcml 'My Theme Name' parts/omelette

Plone 4.3 - How to build a Form package using Zc3.form without Grok?

I am trying to build a form package for a Plone website. I am currently working with Plone 4.3. Before I was using Dexterity with five.grok and grok libraries. But after reading the Plone 4.3 migration and five.grok dependency section of this article: http://developer.plone.org/components/grok.html it appears that Plone developers are moving away from using grok all together.
So should I move away from using Grok and how would I go about doing so when all the current documentation is currently using Grok? Additionally I am developing from a Windows based machine.
First creating form without grok is not that hard and do not depends on your Operating System.
Creating a form is always the same. Here is how I proceed:
Some imports
from Products.Five.browser import BrowserView
from plone.autoform.form import AutoExtensibleForm
from plone.app.z3cform import layout
from zope import interface
from zope import schema
from zope import component
from z3c.form import form
from collective.my.i18n import _
Create a schema
class AddFormSchema(interface.Interface):
what = schema.Choice(
title=_(u"What"),
vocabulary="plone.app.vocabularies.UserFriendlyTypes"
)
where = schema.Choice(
title=u"Where",
vocabulary="collective.my.vocabulary.groups"
)
create a generic adapter to fill the form from anywhere
class AddFormAdapter(object):
interface.implements(AddFormSchema)
component.adapts(interface.Interface)
def __init__(self, context):
self.what = None
self.where = None
Then write the form
class AddForm(AutoExtensibleForm, form.Form):
schema = AddFormSchema
form_name = 'add_content'
Add a view
class AddButton(layout.FormWrapper):
"""Add button"""
form = AddForm
Now ZCML time this is the step you don't need when using grok:
<adapter factory=".my.AddFormAdapter"/>
<browser:page
for="*"
name="my.addbutton"
class=".my.AddButton"
template="addbutton.pt"
permission="zope2.View"
/>
Should you move from grok:
This is depending of what are you doing. For an addon I say Yes but for a project, it's up to you.
Grok is not parts of the already big Zope. So adding dependency is something that always should be done only if needed. Grok is an option so I have never used it.

Delete all portlets site-wide in Plone

What's the best (or simplest) way to delete portlets site-wide in plone 4.x?
It depends. If you have a small amount of local assigned portlets I suggest the manual way. If you have a complex assignment of local portlets you could take this way:
1- create a browser view linked to the site root
2- add this:
from Products.Five import BrowserView
from Products.CMFCore.utils import getToolByName
from zope.component import getMultiAdapter
from plone.portlets.interfaces import IPortletManager
from plone.portlets.interfaces import IPortletAssignmentMapping
from plone.portlets.interfaces import ILocalPortletAssignable
class MyView(BrowserView):
def __call__(self):
ctool = getToolByName(self.context, 'portal_catalog')
all_brains = ctool.searchResults()
for i in all_brains:
obj = i.getObject()
if not ILocalPortletAssignable.providedBy(obj):
continue
for manager_name in ('plone.leftcolumn','plone.rightcolumn'):
manager = getUtility(IPortletManager, name=manager_name)
assignment_mapping = getMultiAdapter((obj, manager),
IPortletAssignmentMapping)
for i in assignment_mapping.keys():
del assignment_mapping['assignment_mapping']
Usually retrieving all objects is not a good thing, so you should evaluate carefully the amount of contents and local portlers. That said, this way is a bit aggressive but it will do the job.
I think you made a small typo:
del assignment_mapping['assignment_mapping']
should be:
del assignment_mapping[i]

Resources