<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ediaz &#124; iamedu &#187; Debug</title>
	<atom:link href="http://ediaz.me/tag/debug/feed/" rel="self" type="application/rss+xml" />
	<link>http://ediaz.me</link>
	<description>Technology, Music, Development, Science</description>
	<lastBuildDate>Thu, 03 Jun 2010 23:28:33 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Create Content from Debug Shell</title>
		<link>http://ediaz.me/2009/12/create-content-from-cms-shell/</link>
		<comments>http://ediaz.me/2009/12/create-content-from-cms-shell/#comments</comments>
		<pubDate>Fri, 18 Dec 2009 17:29:22 +0000</pubDate>
		<dc:creator>iamedu</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Debug]]></category>
		<category><![CDATA[Plone]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://ediaz.me/?p=20</guid>
		<description><![CDATA[Maybe you knew this, but I just found out and I had to write it… otherwise I’ll forget it.
First start a plone instance in debug mode:



$ bin/instance debug


Starting debugger (the name &#8220;app&#8221; is bound to the top-level Zope object)



Now you have your python shell to play!
First of all you need a user, so let’s try [...]]]></description>
			<content:encoded><![CDATA[<p>Maybe you knew this, but I just found out and I had to write it… otherwise I’ll forget it.</p>
<p>First start a plone instance in <strong>debug</strong> mode:</p>
<div>
<ol>
<li>
<div>$ bin/instance <strong>debug</strong></div>
</li>
<li>
<div>Starting debugger <span>(</span>the name <span>&#8220;app&#8221;</span> is bound to the top-level Zope object<span>)</span></div>
</li>
</ol>
</div>
<p>Now you have your python <strong>shell</strong> to play!<br />
First of all you need a user, so let’s try the admin user:</p>
<div>
<ol>
<li>
<div><span>from</span> AccessControl.<span>SecurityManagement</span> <span>import</span> newSecurityManager</div>
</li>
<li>
<div><span>user</span> = app.<span>acl_users</span>.<span>authenticate</span><span>(</span><span>&#8220;admin&#8221;</span>, <span>&#8220;admin&#8221;</span>, <span>None</span><span>)</span></div>
</li>
<li>
<div>newSecurityManager<span>(</span><span>None</span>, <span>user</span><span>)</span></div>
</li>
</ol>
</div>
<p>As you probably guessed the first “admin” is the username, and the second one the password.<br />
OK, now we have enough permissions to create our content let’s move on, imagine you have a<br />
plone site called “development” and a folder called “test” in it.</p>
<div>
<ol>
<li>
<div>container = app.<span>development</span>.<span>test</span></div>
</li>
<li>
<div><span>id</span> = container.<span>invokeFactory</span><span>(</span>type_name=<span>&#8220;News Item&#8221;</span>, <span>id</span>=<span>‘new-news’</span><span>)</span></div>
</li>
<li>
<div>obj = container<span>[</span><span>id</span><span>]</span></div>
</li>
<li>
<div>obj.<span>setTitle</span><span>(</span><span>‘This is my dumb test’</span><span>)</span></div>
</li>
<li>
<div><span>import</span> transaction</div>
</li>
<li>
<div>transaction.<span>commit</span><span>(</span><span>)</span></div>
</li>
<li>
<div>app._p_jar.<span>sync</span><span>(</span><span>)</span></div>
</li>
</ol>
</div>
<p>Now you can go into your plone site, and you’ll have the new news, if you can’t see them try going to:</p>
<p>http://localhost:8080/development/test/new-news</p>
<p>Remember changing the url according to your own.</p>
<p>Hope this helps someone</p>
]]></content:encoded>
			<wfw:commentRss>http://ediaz.me/2009/12/create-content-from-cms-shell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
