Create page structure one time for all languages - django-cms

I'm testing the Django CMS and I'm looking for a way to create the pages one time for all languages. Currently I have to create a new page for each languages and the content/plugin/structure is not shared between the different languages.
Is there a way to achieve this?
Thanks in advance

The built-in management command ./manage.py cms copy lang copies the entire page tree from one language to another. The page tree stays unchanged and the plugin trees are transferred. That is fine if you want to bootstrap a new language for the entire site.
If you want to copy the plugin trees for only one page, you can use the language menu from the toolbar: Language -> Copy all plugins if you are viewing the target language. This is fine, if you only have one page.
If you want to bootstrap a language for a page tree, i.e. a page and all its children, then you either have a lot of clicking to do, or use this short management command I created based on the original DjangoCMS ./manage.py cms copy long command. It allows to specify a page to copy either by its id or by its name in the source language (attention: it has to be unique).
Copy this snippet into any of your application's command folder: my_app/management/commands/. Once you've copied the file you'll have a new Django management command available: ./manage.py copylang. Usage examples:
./manage.py copylang --from-lang=en --to-lang=nl --tree="Home"
./manage.py copylang --from-lang=en --to-lang=nl --tree_id=36 --force
The page id needed for the --tree_id option can be easily inferred from the page admin by hovering over the page's preview icon. The page id is part of the link: .../page/page_id/lang/preview/...
If you leave out the --treeand the --tree_id options the command will revert to DjangoCMS's original cms copy lang behaviour.

The management command provided by #Fabian is quite useful.
I updated the command code here to reflect the changes in django-cms API:
# pages = [head] + list(head.children.drafts())
pages = [head] + list(head.get_child_pages().drafts())
Tested against django-cms 3.5.3 and 3.7.4.
All credits go to #Fabian.

Related

Plone setuphandler- In a setuphandler, how can I programatically add/create a folderish content type at root of Plonesite?

I have have made a folderish content type called supplier_folder, which displays a list of suppliers that can be added under it, and their information. I can add it through the navigation bar, but I would like to add it programatically during setup.
I have been following the tutorial on custom installer code (http://docs.plone.org/develop/addons/components/genericsetup.html#custom-installer-code-setuphandlers-py) and have looked at creating objects programatically (http://docs.plone.org/develop/plone/content/creating.html).
Unfortunately, the second article says I need to have a folder created. How can I get around this and add the supplier_folder object at the Plone Site outside of a folder?
IIRC, only users with role Manager or Site Administrator can add content to the root of the site; you can overcome this limitation in two ways:
by using the _constructInstance method as it bypasses the permissions when creating an item
by switching roles inside your code with plone.api.env.adopt_roles
I personally prefer the second one.
you can see an example of a pretty complex setuphandlers.py in interlegis.portalmodelo.policy package.
When you create a new Plone site, it's also creating some default content types.
Look at how Plone do: https://github.com/plone/Products.CMFPlone/blob/1471828ee97a8dd84396bad4a3286be514819869/Products/CMFPlone/setuphandlers.py#L119
There are a couple of ways to achieve this. The buildin mechanism is to use GenericSetup in combination with "structure" folder as described here: http://koansys.com/tech/create-plone-initial-content-with-generic-setup
In short you need the following:
Create a folder "structure" in your Generic Setup profile (in general, under profiles/default)
Create a .objects file with the following content: "suppliers,supplier_folder"
in "structure" create a folder "suppliers" with a .properties file and content:
[DEFAULT]
title = Suppliers
description = Some usefull description text
As far as I remember this is ok for simple structures likes your. If you have complex structures with folders and sub-folders and want more specific control you probably need to write python code. I made some stuff here: https://github.com/collective/zettwerk.setup/blob/master/zettwerk/setup/structure.py
But zettwerk.setup is not yet released, but you should be able to integrate the structure.py right into your project. Than you can the handle_structure method into your setuphandlers.py and passing a structure dict like this:
handle_structure(portal, [{'id': 'suppliers', 'portal_type': 'supplier_folder'}])
The advantage of this method is, that you can also control metadata like workflow state, default page setting, portlets, local roles and some others.

Sharepoint MasterPages/Templates customization

I am pretty new to Sharepoint.
I need to customize some Sharepoint Masterpages (the background color, the font type and a few other css requeriments).
Considering I have available the following files: v4.master, default.master and two more pages which are content pages of default.master, plus the COREv4.css file.
I know I should create a copy of one of those master pages (I am not sure which tho) and customize it changing the CSS linked to it). The following questions come in regards of this:
1) The custom CSS file should be a modified copy of the COREv4.CSS or just another CSS file with the desired styles?
2) How do I create/link the customized CSS file for the modified page via Site Settings?. How/Where should I save the new file?.
3) As for the copy of v4.master, How do I load it to "replace" the original one for the site?.
4) The system is built upon Sharepoint 2010. That ensures that the page to have the modified CSS would be a v4.master copy only?.
Thank you for the insight as always.
**Update**
Hi,
I managed to solve the problem getting a general idea with the pdf manual provided, your suggestions and some extra steps I will describe briefly:
1) To place my custom css file I put it in the folder: C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\3082\STYLES
2) I opened the site to be customized with Sharepoint Designer 2010.
3) I clicked on the option Main Pages/Master Pages, and selected the page to be v4.master page, copied and pasted it. Then I renamed it right clicking on it, selecting "Rename" and typed the new name, after doing that I right clicked one more and selected "Set page as main default page".
4) To edit the contents of the page I right clicked once more and selected the option "Edit content in advanced mode", right before the head tag ended I copied and pasted:
<SharePoint:CssRegistration name="customname.css" runat="server" After="core4.css"/>
Note that "customname.css" is my css file. Then I clicked on the floppy disk icon on the upper left side of the screen to save.
5) After doing that I used Chrome HTML/CSS Analyzer, inspecting the original (and now copied) master page to browse on the zones that needed customization in order to identify the class names/ids/element types that managed the styles to be changed. Once identified I only added to them the properties that required change, EG:
//Webparts Alternate Highlighted Rows
div#ctl00_MSO_ContentDiv table.ms-viewlsts tbody
tr.ms-alternatingstrong{ background-color:#F7FAF4 }
table.ms-listviewtable.ms-basictable tbody
tr.ms-alternatingstrong.ms-itmhover{ background-color:#F7FAF4 }
I mostly did this by myself by trial and error with Chrome Analyzer but I also helped the task using the Chart found here (http://sharepointexperience.com/csschart/csschart.html), tho at some point going thru it turned a bit tricky and I decided to do it by myself as I mentioned. In the process I repeatedly added more styles to the custom file and then overwrote it on the server location to refresh the page/pages to see how it was looking, this till the end of the process.
Thanks for your help, I hope this serves as a guide for anyone that needs it. If you have questions let me know.
You can create a new master page from the scratch or modify the existing one.
Please have a look at this link it may help you to get answers of your questions
http://www.rdacorp.com/wp-content/uploads/ASP-NET-Master-Pages-and-SharePoint.pdf
It's not advised to modify files of SharePoint.
Better to create new master page file, specify all CSS and script you want inside and install this with feature.
What version of SharePoint do you have? SharePoint 2010 Server or Foundation? Cause with server version you can brand your master page in a cool way:
see this link
Microsoft has a good introductory article on how you can/should do this.
http://office.microsoft.com/en-us/sharepoint-designer-help/customize-a-master-page-to-brand-your-site-HA102449505.aspx

How to make sure changes to a Wordpress plugin won't be lost on plugin update?

I'm pretty sure I've read somewhere that you can actually move the main plugin *.php file to somewhere else (I assume under your theme directory) to have it safe in case you made changes to it and your plugin updates. I tried Google but I can't find anything. Google page with good results will suffice.
I've just experienced a situation where my 2 plugins which had its layout changed and accommodated my needs and I want to make sure it doesn't happen again. Apart from having the main file in another location, is there a way to move along any CSS and JS files as well?
In Concrete5 CMS there is a nice way of doing this, by creating a new folder inside a block of an addon (may be regarded as a WP plugin), inside of which you can create copies of main file, any CSS and JS files and then you can simply edit them and choose that template for a page location you are using that block in.
I assume there is no such thing in Wordpress but how close can I get?
UPDATE: I found where I applied that advice on creating a new instance of the file then moving it to the theme directory.
The plugin in question was HL-Twitter. These are the plugin files:
admin.php
archive.php
functions.php
hl_twitter.php
hl_twitter_archive.php
hl_twitter_widget.php
import.php
widget.php
Now, this is the top contents (commented out) of the hl_twitter_widget.php:
Widget Theme for HL Twitter
To change this theme, copy hl_twitter_widget.php
to your current theme folder, do not edit this
file directly.
Available Properties:
$before_widget
$after_widget
$before_title
$after_title
$widget_title
$show_avatars
$show_powered_by
$num_tweets: how many tweets to show
$tweets: array of $tweet
$tweet: object representing a tweet
$tweet->twitter_tweet_id
$tweet->tweet
$tweet->lat
$tweet->lon
$tweet->created
$tweet->reply_tweet_id
$tweet->reply_screen_name
$tweet->source
$tweet->screen_name
$tweet->name
$tweet->avatar
$user: represents the Twitter user (ONLY SET IF SHOWING A SINGLE USERS TWEETS!)
$user->twitter_user_id
$user->screen_name
$user->name
$user->num_friends
$user->num_followers
$user->num_tweets
$user->registered
$user->url
$user->description
$user->location
$user->avatar
So I was wrong about copying the main file (in this case hl_twitter.php), but still - this enabled me to edit the file outside the plugin directory and the system somehow checks for its existence and picks it up if exists.
If this behavior something that is natively supported by Wordpress or it has been integrated in the plugin itself?
With themes, Wordpress has a concept of "child themes" which allows exactly that: to keep changes separate from main theme, in case it changes.
I haven't yet found a way to do this with plugins.
I'm using a few tactics myself:
I bump plugin version to a very high number like 99.9. This way Wordpress won't ever update the plugin.
Store my plugins in version control (i use git, but it doesnt matter), this allows you to update the plugin, run the 'diff' tool and see what changes happend. If you don't like you just revert like it would be a bad code you've written. But this approach requires a bit of skill.
Are you talking about running parts of a modified 3rd party plugin, and an updated version, at the same time?
That's not going to be possible. There is no magical method of "preserve my changes and transfer them into the new version automatically". The way to go here is doing a diff between the edited version and the update, and integrating the changes in the actual source files.
The bottom line is, if you manually edit a third party plugin, you're in for manual review (and possibly rework) once an update takes place. That's why it's usually not a good idea to extensively modify third party plugins.
Well in fact, yes! There is some kind of way.
You have to remove the to be modificated plugin's original actions/filters and then add your altereted actions/filters.
If the desired plugin is even coded in OOP you can just inherit the whole class and rewrite the wanted functions (oh sorry: "methods". we're talking about OOP ;) ). Instantiate your inherited class and rest as above.
Maybe there are better ways! I already search for a method so that the original class won't even get loaded but our altered one instead but I'm no John Carmack.

Pasted folder invisible to Plone but not to Zope

I am getting a very weird problem when attempted to cut-and-paste folders from one place to another in our intranet Plone site. The paste operation returned the error "Nothing in the clipboard". However it had gone and removed the folder from where it had originally been, and it looks as though it hasn't been inserted yet into the new location. Showing the Content view of the folder in which the paste happened does not show the pasted folder. However, through the ZMI interface I can see that the paste has happened. Clearly something threw an error before the pasted content was moved successfully, and it is left in a weird state.
For example the site search can find the content in the new pasted location, and the bread-crumbs show that those content pages are beneath the folder which is otherwise invisible to Plone.
Is it possible - maybe through the ZMI - to get this folder to be visible in the Plone world?
That is a weird bug. The quick solution to get the folder to display in Plone is to go to the ZMI, then visit portal_catalog, then locate (in one of the tabs) the button to rebuild the catalog. This ought to regenerate the catalog indexes (which may have failed to be updated when you did the cut/paste, through no fault of your own) and thus all the views (folder listings, etc) in Plone will display the new index (the views use the catalog to know what to display).
The same problem as I copied a folder from one language folder to an other the pasted object was only visible in ZMI
As fRiSi said the problem was the language category in Categorization tab > Language
Because I had many subobjects inside a folder I run the script below to change the language categorization recursively
Based on Convert LinguaPlone sub-language back to language for all content?
path = '/'.join(context.getPhysicalPath())
for brain in context.portal_catalog(path={'query': path, 'depth': 1000}, Language="it"):
obj = brain.getObject()
obj.setLanguage('en')
obj.reindexObject(idxs=['Language'])
print brain.getURL()
return printed

How do I add version control to uploaded files / images using Plone 4.1?

I want to activate version control facility for uploaded files using Plone 4.1. E.g.Whenever an image is edited using Products.ImageEditor in Plone, I want the entry to appear in the history for the image.
First thing to activate version control for images is to:
1) go to site setup
2) click Types
3) Select Image from the drop down
4) select Automatic versioning
Even with that, I don't think versioning will not automatically be performed for ImageEditor changes. ImageEditor just sets the field value for the image and does not emit any object modified events which I assume is required for plone's versioning to kick in.
FWIW, I'm the author of Products.ImageEditor. You can submit a ticket for the issue if you'd like: https://github.com/collective/Products.ImageEditor/issues

Resources