GSoC 2018 Ideas: Improve plonecli and bobtemplates.plone

<configure
    xmlns="http://namespaces.zope.org/zope"
    xmlns:browser="http://namespaces.zope.org/browser"
    xmlns:plone="http://namespaces.plone.org/plone"
    i18n_domain="ploneconf.site">

  <!-- Set overrides folder for Just-a-Bunch-Of-Templates product-->
  <include package="z3c.jbot" file="meta.zcml" />
  <browser:jbot
      directory="overrides"
      layer="ploneconf.site.interfaces.IPloneconfSiteLayer"
      />

  <!-- Publish static files -->
  <plone:static
      name="ploneconf.site"
      type="plone"
      directory="static"
      />

  <browser:resourceDirectory
      name="talklist"
      directory="talklist"
      />
  
  <browser:page
     name="training"
     for="*"
     template="templates/training.pt"
     permission="zope2.View"
     />
  
  <browser:page
      name="training"
      for="*"
      layer="ploneconf.site.interfaces.IPloneconfSiteLayer"
      class=".views.DemoView"
      template="templates/training.pt"
      permission="zope2.View"
      />

  <browser:page
      name="talkview"
      for="ploneconf.site.interfaces.ITalk"
      layer="ploneconf.site.interfaces.IPloneconfSiteLayer"
      class=".views.TalkView"
      template="templates/talkview.pt"
      permission="zope2.View"
      />

  <browser:page
      name="talklistview"
      for="*"
      layer="ploneconf.site.interfaces.IPloneconfSiteLayer"
      class=".views.TalkListView"
      template="templates/talklistview.pt"
      permission="zope2.View"
      />

  <browser:viewlet
      name="social"
      for="ploneconf.site.behaviors.social.ISocial"
      manager="plone.app.layout.viewlets.interfaces.IBelowContentTitle"
      class=".viewlets.SocialViewlet"
      layer="ploneconf.site.interfaces.IPloneconfSiteLayer"
      template="templates/social_viewlet.pt"
      permission="zope2.View"
      />

  <browser:page
      name="frontpageview"
      for="*"
      layer="ploneconf.site.interfaces.IPloneconfSiteLayer"
      class=".frontpage.FrontpageView"
      template="templates/frontpage.pt"
      permission="zope2.View"
      />

  <browser:viewlet
      name="sponsorsviewlet"
      manager="plone.app.layout.viewlets.interfaces.IPortalFooter"
      for="*"
      layer="..interfaces.IPloneconfSiteLayer"
      class=".viewlets.SponsorsViewlet"
      template="templates/sponsors_viewlet.pt"
      permission="zope2.View"
      />

  <browser:page
      name="ploneconf-controlpanel"
      for="Products.CMFPlone.interfaces.IPloneSiteRoot"
      class=".controlpanel.PloneconfControlPanelView"
      permission="cmf.ManagePortal"
      />

</configure>

You have two browser pages with same name training. I don't know if that is causing the error, but it possibly could.

Yeah I did notice that!

Your first regitration should work on every context, the second only if the browser layer "IPloneconfSiteLayer" is active.
For info to BrowserLayer see here:
https://training.plone.org/5/mastering-plone/dexterity_2.html?highlight=layer#add-a-browserlayer

Hello, I have added a template for creating a simple view to my fork of the bobtemplates.plone. The link to the commit is here.

I have a couple of questions:

  1. How would you suggest we get feedback on the templates we write? Should we make a documentation of how the template works and the files that it creates or should we submit a pull request to the main repo or something else?

  2. How do we test the templates that we write? I'm aware of using the mrbob command to generate the directory structure from the templates, but how do we use the new templates within the Plone environment? I'm assuming that running the command mrbob bobtemplates.plone:views would search for bobtemplates.plone in the buidlout-cache/ or lib/ (for virtualenv), so how do we make it use our version of bobtemplates.plone?

  3. (This one's not really a question :stuck_out_tongue:)
    I made the template by referring to the template for content_type. I found that many snippets of the code from content_type.py can be reused for making any new subtemplate, so I've added those as functions in the file base.py and have used these functions in view.py (the file containing logic for pre-render and post-render hooks). I haven't changed the contents of content_type.py to use these functions though. Feedback on this would also be appreciated :smile:

I have also added a template to create viewlets in my fork.

The gist explaining the working of the template for view creation can be found here

@meshde I'll add some more docs for developing the templates.
The test you can run with tox. Just install tox with pip or pipenv and run it in the bobtemplates.plone repository folder.
to see which tox environment are exiting, use:

tox -l

To run just one environment, use:

tox -e <envname>

For exiting test look into skeleton-tests/ and package-tests/ folders.

I suggest tests that create a new package and try to run the buildout of it from all supported versions in bobtemplates.plone.

Example: create a new package for Plone 4.3.x, and then trying to run the buildout to see if there's a dependency problem.

Thats what the tests are doing: https://github.com/plone/bobtemplates.plone/blob/master/tox.ini

I'm trying to create a new view here. I'm not able to render a certain template. I'm following the below given steps. I'd be glad if anyone could help me out as I would like to explore more as to how these views and viewlets work.

  1. I've created a new add-on by using the command mrbob mrbob:plonetheme.tango
  2. I've created a views.py file with the following code in it
    from zope.interface import Interface from Products.Five.browser import BrowserView from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
    class MyView(BrowserView):
    index = ViewPageTemplateFile("myview.pt")
    3.Then I've added a template myview.pt in /plonetheme/tango/browser/templates/myview.pt
    4.I've registered the template in browser/configure.zcml.
    Here is the code:
    `

<plone:static
name="plonetheme.tango"
type="plone"
directory="static"
/>

<browser:page
      for="*"
      name="test"
      permission="zope2.Public"
      class=".views.MyView"
      />
` Here is the HTML for myview.pt: `
<metal:block fill-slot="content-core">
        XXX - this text comes below title and description
</metal:block>
` When I go to this site,

https://localhost/Plone/@@myview
It says that the page does not exist.
Don't know where I'm going wrong. I would appreciate it if you could help me out.

You named your view test in the zcml declaration. So you should be able to open it with http://localhost/Plone/@@test.

I’ve visited this link as well https://localhost/Plone/@@test
The site says that it does not exist even now.

Am I going wrong somewhere while I am creating the view?

These are not what I have in mind. Please correct me if I'm wrong: you're testing if the template correctly creates a package, and the idea is to test if an already created package from template is succesfull when running bin/buildout. So, the idea is to create the package:

./bin/mrbob bobtemplates.plone:addon -O src/collective.foo                                                                                                                      [14:18:08]

Welcome to mr.bob interactive mode. Before we generate directory structure, some questions need to be answered.

Answer with a question mark to display help.
Values in square brackets at the end of the questions show the default value if there is no answer.


--> Author's name: author

--> Author's email: author@author.com

--> Author's GitHub username: author

--> Package description [An add-on for Plone]: author

--> Plone version [5.0.8]: 4.3.15


Generated file structure at /tmp/src/collective.foo

And then run bin/buildout to be sure that buildout is working.

Yes! Thank you for the steps on doing it! The buildout runs perfectly fine I've created the add-on structure and I have put some sample code into the buildout. It works perfectly fine now.

The new test structure is a bit confusing to read. You can see that those tests are run: https://travis-ci.org/plone/bobtemplates.plone/jobs/346936640#L1686

The definition for the tests is available here: https://github.com/plone/bobtemplates.plone/blob/master/skeleton-tests/test_addon.py#L71-L109

The problem is that for code analysis, the status code return is disabled in the add-on template: https://github.com/plone/bobtemplates.plone/blob/master/bobtemplates/plone/addon/buildout.cfg.bob#L36. That's why errors on that part are not recognized.

1 Like

Actually, https://github.com/plone/bobtemplates.plone/blob/master/skeleton-tests/test_addon.py#L71-L109 is not that hard to read. You can see the commands being run. Thanks for the explanation @tmassman.

@mrsaicharan1if you lok at this docs:
https://github.com/plone/bobtemplates.plone/blob/master/docs/vocabulary.rst

you can see that for the sub templates you want to create always an addon package to start.
So first step create the addon package and then inside this package use sub templates.
The view and viewlets sub templates you are working on, should work the same way.
But before you start creating the sub template, add all pieces manually and bring them to work.
If you check the traing docs and the Plone docs, you can find a lot of examples how Browser Views and Viewlets are working.

@MrTango Thank you very much for clarifying my doubt! In addition to that, I've also created some templates for views and viewlets which I have requested for review on the bobtemplates repo. I would be glad if you could check it out!