Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6867947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:22:22+00:00 2026-05-27T03:22:22+00:00

I am writing a python script to import content from another CMS into Plone

  • 0

I am writing a python script to import content from another CMS into Plone 4.1. For a number of reasons I am running it like so: bin/instance run path/to/myscript

The question I have is how to get the correct context for a folder with a hyphen in the ID/shortname. For example from the root of a plone site called mysite, I can work with a folder called “sub-folder” like so:

from Products.CMFCore.utils import getToolByName
urltool = getToolByName(app.mysite, "portal_url")
portal  = urltool.getPortalObject()
folder = getattr(portal, 'sub-folder')

But if I then want to create a folder or page within that sub-folder, the following throws an error: “AttributeError: sub”

urltool = getToolByName(app.mysite.sub-folder, "portal_url")
portal  = urltool.getPortalObject()

And performing the same on the News folder, (which has no hyphen) produces no error:

urltool = getToolByName(app.mysite.news, "portal_url")
portal  = urltool.getPortalObject()

Simply trying portal.sub-folder throws the same Error.

So what would be the python code to get the proper context of “http://localhost:8080/mysite/sub-folder” so that I can then successfully call the invokeFactory method and create a folder or page within mysite/sub-folder?

What if I needed to find the context of “http://localhost:8080/mysite/sub-folder/2nd-level” ?

The online documentation I have found seems to only account for folders named dog or news, which have no hyphen in the ID/Shortname. However, if you create these items by hand in Plone, the shortnames obviously have hyphens, and so there must be a way to get the correct folder context.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T03:22:22+00:00Added an answer on May 27, 2026 at 3:22 am

    That’s because if you use:

    app.mysite.sub-folder
    

    python thinks that you’re trying to do a difference between app.mysite.sub and folder.
    Instead you have to use this syntax:

    secondlevel = mysite['sub-folder']['2nd-level']
    

    or

    secondlevel = mysite.restrictedTraverse('/mysite/sub-folder/2nd-level')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I amm writing a little python script that will grab information from VMs of
I'm writing a Python script to process emails returned from Procmail . As suggested
I'm writing a python script to replace strings from a each text file in
I'm writing a script to import some model objects into the database my django
I'm writing a python script that uses this awkward glob syntax. import glob F
I'm writing a script in Python 3.1.2 that logs into a site and then
I'm writing a python script which I would like to be able to both
I have a python script that is constantly grabbing data from Twitter and writing
I am writing python scripts and execute them in a Makefile. The python script
I'm writing a python script that executes a csh script in Solaris 10. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.