| 1 | <?xml version="1.0" encoding="utf-8" ?> |
|---|
| 2 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
|---|
| 3 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
|---|
| 4 | <head> |
|---|
| 5 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
|---|
| 6 | <meta name="generator" content="Docutils 0.5: http://docutils.sourceforge.net/" /> |
|---|
| 7 | <title></title> |
|---|
| 8 | <link rel="stylesheet" href="./default.css" type="text/css" /> |
|---|
| 9 | </head> |
|---|
| 10 | <body> |
|---|
| 11 | <div class="document"> |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | <div class="section" id="adding-portlets-to-educommons"> |
|---|
| 15 | <h1>Adding Portlets To eduCommons</h1> |
|---|
| 16 | <p>A portlet is a user-interface component that can be "plugged-in" to the architecture of Plone, the framework upon which eduCommons is based. There are several portlets that are natively available when you install eduCommons: the Course Info portlet that appears in the right navigation is an example, the Course Builder portlet is another. This tutorial will explain how portlets can be added and removed and how you can create your own portlet from scratch.</p> |
|---|
| 17 | <ul class="simple"> |
|---|
| 18 | <li><a class="reference internal" href="#adding-and-removing-existing-portlets">Adding and Removing Existing Portlets</a></li> |
|---|
| 19 | <li><a class="reference internal" href="#creating-your-own-portlet">Creating Your Own Portlet</a>.</li> |
|---|
| 20 | <li><a class="reference internal" href="#customizing-portlets">Customizing Portlets</a>.</li> |
|---|
| 21 | <li><a class="reference internal" href="#oerrecommender-portlet">OerRecommender Portlet</a>.</li> |
|---|
| 22 | <li><a class="reference internal" href="#coursebuilder-portlet">CourseBuilder Portlet</a>.</li> |
|---|
| 23 | <li><a class="reference internal" href="#courseinfo-portlet">CourseInfo Portlet</a>.</li> |
|---|
| 24 | <li><a class="reference internal" href="#additional-resources">Additional Resources</a>.</li> |
|---|
| 25 | </ul> |
|---|
| 26 | </div> |
|---|
| 27 | <div class="section" id="id1"> |
|---|
| 28 | <span id="adding-and-removing-existing-portlets"></span><h1>Adding and Removing Existing Portlets</h1> |
|---|
| 29 | <p>If a portlet already exists that you either want to remove or add, follow these steps.</p> |
|---|
| 30 | <ul class="simple"> |
|---|
| 31 | <li>navigate to the site as an administrator.</li> |
|---|
| 32 | <li>click on the <em>manage portlets</em> link.</li> |
|---|
| 33 | </ul> |
|---|
| 34 | <p>The <em>manage portlets</em> page allows you to add and remove portlets.</p> |
|---|
| 35 | <ul class="simple"> |
|---|
| 36 | <li>To add a portlet click on the <em>Add portlet...</em> drop down menu and select the portlet to add.</li> |
|---|
| 37 | <li>To delete a portlet click on the small red <em>x</em> next to the portlet to remove.</li> |
|---|
| 38 | </ul> |
|---|
| 39 | <p>You can also change the order that the portlets appear by using the small blue arrows next to the porlets.</p> |
|---|
| 40 | </div> |
|---|
| 41 | <div class="section" id="id2"> |
|---|
| 42 | <span id="creating-your-own-portlet"></span><h1>Creating Your Own Portlet</h1> |
|---|
| 43 | <p>One of the simplest ways to create a portlet is to use the ZopeSkel tool to create a skeleton product that you can then modify for your own purposes. The Plone site has an <a class="reference external" href="http://plone.org/documentation/how-to/use-paster/">excellent article describing how to install and use the ZopeSkel tool</a>. Once you have ZopeSkel installed you can create a new portlet package using the plone3_portlet template.</p> |
|---|
| 44 | <pre class="literal-block"> |
|---|
| 45 | paster create -t plone3_portlet |
|---|
| 46 | </pre> |
|---|
| 47 | <p>Enter the information, as prompted, for the portlet you are creating. To select the defaults, just press enter.</p> |
|---|
| 48 | <pre class="literal-block"> |
|---|
| 49 | Enter project name: SamplePortletProject |
|---|
| 50 | Variables: |
|---|
| 51 | egg: SamplePortletProject |
|---|
| 52 | package: sampleportletproject |
|---|
| 53 | project: SamplePortletProject |
|---|
| 54 | Enter namespace_package (Namespace package (like plone)) ['collective']: sample_portlet_project |
|---|
| 55 | Enter namespace_package2 (Nested namespace package (like app)) ['portlet']: |
|---|
| 56 | Enter package (The package contained namespace package (like example)) ['example']: |
|---|
| 57 | Enter zope2product (Are you creating a Zope 2 Product?) [True]: |
|---|
| 58 | Enter version (Version) ['0.1']: |
|---|
| 59 | Enter description (One-line description of the package) ['']: This is a sample portlet product |
|---|
| 60 | Enter long_description (Multi-line description (in reST)) ['']: |
|---|
| 61 | Enter author (Author name) ['Plone Foundation']: |
|---|
| 62 | Enter author_email (Author email) ['plone-developers@lists.sourceforge.net']: |
|---|
| 63 | Enter keywords (Space-separated keywords/tags) ['']: |
|---|
| 64 | Enter url (URL of homepage) ['http://plone.org']: |
|---|
| 65 | Enter license_name (License name) ['GPL']: |
|---|
| 66 | Enter zip_safe (True/False: if the package can be distributed as a .zip file) [False]: |
|---|
| 67 | Enter portlet_name (Portlet name (human readable)) ['Example portlet']: Sample Portlet |
|---|
| 68 | Enter portlet_type_name (Portlet type name (should not contain spaces)) ['ExamplePortlet']: SamplePortlet |
|---|
| 69 | </pre> |
|---|
| 70 | <p>A portlet package will be created in the folder where you ran the script. Follow the directions in the Plone article to install the new portlet package using easy_install. Another option is to tell the paster script to create a Plone 2 product and then copy this product into the Products directory of your plone instance (the Plone 2 product is buried down a few levels in the package). In either case, after you restart your Plone instance and navigate to the <em>Add-on Products</em> page of your Plone site you will see the new product listed. After installing the product into your Plone site you will be able to manage it as you do the other portlets in your site.</p> |
|---|
| 71 | </div> |
|---|
| 72 | <div class="section" id="id3"> |
|---|
| 73 | <span id="customizing-portlets"></span><h1>Customizing Portlets</h1> |
|---|
| 74 | <p>If you look at the code, generated in the last section, you will see that this new product is relatively simple. It contains a configure.zcml file, a template file, a python file, a profile folder, and a tests folder. Often the only places that will need to be changed to customize the portlet will be the template file and the renderer within the python file. Here are some examples of portlets that do just that:</p> |
|---|
| 75 | <div class="section" id="id4"> |
|---|
| 76 | <span id="oerrecommender-portlet"></span><h2>OerRecommender Portlet</h2> |
|---|
| 77 | <p>This is the <a class="reference external" href="http://cosl.usu.edu/svndev/eduCommons3/tags/3.1.0-final/portlet/oerrecommender.pt">oerrecommender.pt</a> template file for the oerrecommender. The file consists of a script tag that retrieves a series of recommendations from oerrecommender.org.</p> |
|---|
| 78 | <pre class="literal-block"> |
|---|
| 79 | <div id="recommendations"> |
|---|
| 80 | <script language="JavaScript" |
|---|
| 81 | tal:define="url here/absolute_url" |
|---|
| 82 | tal:attributes="src string:http://www.oerrecommender.org/recommendations.pjs?educommons=true&u=${url}&title=true;" |
|---|
| 83 | type="text/javascript"> |
|---|
| 84 | </script> |
|---|
| 85 | </div> |
|---|
| 86 | </pre> |
|---|
| 87 | <p>Here is the renderer for the <a class="reference external" href="http://cosl.usu.edu/svndev/eduCommons3/tags/3.1.0-final/portlet/oerrecommenderportlet.py">oerrecommenderportlet.py</a> file.</p> |
|---|
| 88 | <pre class="literal-block"> |
|---|
| 89 | class Renderer(base.Renderer): |
|---|
| 90 | """ Render the OER Portlet """ |
|---|
| 91 | render = ViewPageTemplateFile('oerrecommender.pt') |
|---|
| 92 | |
|---|
| 93 | def __init__(self, context, request, view, manager, data): |
|---|
| 94 | super(Renderer, self).__init__(context, request, view, manager, data) |
|---|
| 95 | self.props = self.context.portal_properties.educommons_properties |
|---|
| 96 | |
|---|
| 97 | @property |
|---|
| 98 | def available(self): |
|---|
| 99 | return self.props.oerrecommender_enabled |
|---|
| 100 | </pre> |
|---|
| 101 | <p>You'll notice that the renderer is where we define which page template to use when rendering the template. This file also contains a property that allows the portlet to be conditionally displayed based on whether the oerrecommender is enabled.</p> |
|---|
| 102 | </div> |
|---|
| 103 | <div class="section" id="id5"> |
|---|
| 104 | <span id="coursebuilder-portlet"></span><h2>CourseBuilder Portlet</h2> |
|---|
| 105 | <p>The Course Builder tool allows users to quickly create a course with its associated files and departments. In this <a class="reference external" href="http://cosl.usu.edu/svndev/eduCommons3/tags/3.1.0-final/portlet/coursebuilder.pt">coursebuilder.pt</a> template file you can see the portlet displaying a link to the Course Builder form (the '@@' symbol signifies that the resource is a view).</p> |
|---|
| 106 | <pre class="literal-block"> |
|---|
| 107 | <dl class="portlet portletCourseBuilder" |
|---|
| 108 | i18n:domain="eduCommons"> |
|---|
| 109 | |
|---|
| 110 | <dt class="portletHeader" |
|---|
| 111 | i18n:translate="box_course_builder"> |
|---|
| 112 | Course Builder |
|---|
| 113 | </dt> |
|---|
| 114 | |
|---|
| 115 | <dd class="portletItem even"> |
|---|
| 116 | <a href="" |
|---|
| 117 | i18n:translate="text_build_course" |
|---|
| 118 | tal:attributes="href string:${here/portal_url}/@@coursebuilderform">Build a Course</a> |
|---|
| 119 | </dd> |
|---|
| 120 | |
|---|
| 121 | </dl> |
|---|
| 122 | </pre> |
|---|
| 123 | </div> |
|---|
| 124 | <div class="section" id="courseinfo-portlet"> |
|---|
| 125 | <span id="courseinfo-example"></span><h2>CourseInfo Portlet</h2> |
|---|
| 126 | <p>The CourseInfo portlet displays course statistics for the objects within each course. Methods are defined with the python file that are then used with the template file. For example, the renderer for the portlet in the <a class="reference external" href="http://cosl.usu.edu/svndev/eduCommons3/tags/3.1.0-final/portlet/courseinfoportlet.py">courseinfoportlet.py</a> file contains several methods</p> |
|---|
| 127 | <pre class="literal-block"> |
|---|
| 128 | ... |
|---|
| 129 | def statePercent(self, state=''): |
|---|
| 130 | """ return the percent value for a given state """ |
|---|
| 131 | |
|---|
| 132 | if 0 == self.total: |
|---|
| 133 | return '0%' |
|---|
| 134 | else: |
|---|
| 135 | width = float(self.stateCounts[state])/float(self.total) * 100.0 |
|---|
| 136 | return '%d%%' %int(width) |
|---|
| 137 | ... |
|---|
| 138 | </pre> |
|---|
| 139 | <p>that are then used in the <a class="reference external" href="http://cosl.usu.edu/svndev/eduCommons3/tags/3.1.0-final/portlet/courseinfo.pt">courseinfo.pt</a> template file.</p> |
|---|
| 140 | <pre class="literal-block"> |
|---|
| 141 | ... |
|---|
| 142 | <img alt="barchart" class="statecolumnimage" |
|---|
| 143 | tal:attributes="width python:view.statePercent(item); |
|---|
| 144 | src string:bargraphic.gif" /> |
|---|
| 145 | ... |
|---|
| 146 | </pre> |
|---|
| 147 | </div> |
|---|
| 148 | </div> |
|---|
| 149 | <div class="section" id="id6"> |
|---|
| 150 | <span id="additional-resources"></span><h1>Additional Resources</h1> |
|---|
| 151 | <p>There are some great resources to help you in customizing existing portlets and for adding functionality to portlets that you've created using the ZopeSkel product.</p> |
|---|
| 152 | <p>If you would like to do some quick and dirty customization through-the-web you'll probably want to <a class="reference external" href="http://plone.org/documentation/tutorial/customization-for-developers/tutorial-all-pages">use the portal_view_customizations tool</a> in the ZMI. It's similar to portal_skins but for view, viewlets, and portlets.</p> |
|---|
| 153 | <p>Martin Aspeli has a whole tutorial on customizing a plone site which includes a section on <a class="reference external" href="http://plone.org/documentation/tutorial/customization-for-developers/portlet-renderers">customizing portlet renderers</a>.</p> |
|---|
| 154 | <p>The Plone site also has a tutorial that shows how to <a class="reference external" href="http://plone.org/documentation/how-to/override-the-portlets-in-plone-3.0/?searchterm=add%20new%20portlet">override existing portlets</a>.</p> |
|---|
| 155 | </div> |
|---|
| 156 | </div> |
|---|
| 157 | <div class="footer"> |
|---|
| 158 | <hr class="footer" /> |
|---|
| 159 | <a class="reference external" href="PORTLETS.txt">View document source</a>. |
|---|
| 160 | Generated on: 2009-08-09 07:41 UTC. |
|---|
| 161 | Generated by <a class="reference external" href="http://docutils.sourceforge.net/">Docutils</a> from <a class="reference external" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> source. |
|---|
| 162 | |
|---|
| 163 | </div> |
|---|
| 164 | </body> |
|---|
| 165 | </html> |
|---|