Mike,
I got this code to work for the first example on http://developer.plone.org/members/member_basics.html#getting-the-logged-in-member
I used your example code and came up with this for the configure.zcml
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser"
i18n_domain="example.MyAddOn">
<include package="plone.app.contentmenu" />
<!-- -*- extra stuff goes here -*- -->
<browser:page
for="*"
name="test_user_view"
class=".common.TestUserView"
permission="zope2.View"
/>
<browser:page
for="*"
name="test_user_view2"
class=".mycommon.TestUserView2"
permission="zope2.View"
/>
</configure>
This is the code I came up with for mycommon.py
from Products.Five import BrowserView
from Products.CMFCore.utils import getToolByName
import logging
logger=logging.getLogger("MyLogger: ")
from zope.component import getMultiAdapter
class TestUserView2:
def __call__(self):
"""Testing views"""
logger.info("TestUserView2: __call__: ")
portal_state = getMultiAdapter((self.context, self.request), name="plone_portal_state")
if portal_state.anonymous():
# Return target URL for the site anonymous visitors
logger.info("TestUserView2: __call__: self.context.portal_url(): %s" % str(self.context.portal_url.getPortalObject()))
else:
# Return edit URL for the site members
logger.info("TestUserView2: __call__: self.context.absolute_url(): %s" % str(self.context.absolute_url()))
I tested this from the /events folder off of the root
When I place /@@test_user_view2 in the url while logged in, it displays this in the console:
2013-07-14 01:20:59 INFO MyLogger: TestUserView2: __call__:
2013-07-14 01:20:59 INFO MyLogger: TestUserView2: __call__: self.context.absolute_url(): http://localhost:8080/PloneTest/events
When I do the same thing with the anonymous view, it displays this in the console:
2013-07-14 01:18:29 INFO MyLogger: TestUserView2: __call__:
2013-07-14 01:18:29 INFO MyLogger: TestUserView2: __call__: self.context.portal_url(): <PloneSite at PloneTest>
I tried to get the actual root url to show up, but couldn't get anything to work. I have used context.getURL0() in the theme product in the past, but it would not work here.
I could not get the code in the original else clause, product.absolute_url() to work so I replaced it with self.context.absolute_url()
Actually, I couldn't find any examples of product.absolute_url() in the Plone code on my site, my Plone documentation, which includes most of the Plone books, or any google search. Seems odd that they would use something so uncommon. Is that code, product.absolute_url(), correct or am I missing something?
This is the error I got with product.absolute_url() in the if clause:
2013-07-13 22:28:15 INFO Zope Ready to handle requests
2013-07-13 22:29:08 INFO MyLogger: TestUserView2: __call__:
2013-07-13 22:29:08 ERROR Zope.SiteErrorLog 1373768948.090.486417813512 http://localhost:8080/PloneTest/@@test_user_view2
Traceback (innermost last):
Module ZPublisher.Publish, line 126, in publish
Module ZPublisher.mapply, line 77, in mapply
Module ZPublisher.Publish, line 46, in call_object
Module example.MyAddOn.browser.mycommon, line 18, in __call__
NameError: global name 'product' is not defined
I ran into a similar problem with the anonymous view and the code self.product.getHomepageLink() in the if clause:
It generates this error:
2013-07-13 22:23:14 INFO MyLogger: TestUserView2: __call__:
2013-07-13 22:23:14 ERROR Zope.SiteErrorLog 1373768594.460.832128119821 http://127.0.0.1:8080/PloneTest/@@test_user_view2
Traceback (innermost last):
Module ZPublisher.Publish, line 126, in publish
Module ZPublisher.mapply, line 77, in mapply
Module ZPublisher.Publish, line 46, in call_object
Module example.MyAddOn.browser.mycommon, line 15, in __call__
AttributeError: 'TestUserView2' object has no attribute 'product'
Is self.product.getHomepageLink() valid code or am I not understanding something?
I appreciate your help with this.
Joe Bigler
-----Original Message-----
From: Mike Cullerton [mailto:***@bakednotfried.com]
Sent: Saturday, July 13, 2013 9:41 AM
To: Joe Bigler
Cc: plone-***@lists.sourceforge.net
Subject: Re: [Plone-docs] Zope View Tutorial
Hey Joe,
You don't ask a specific question. Did you try something and get an error?
I suggest starting your view without restricting the views/interfaces, and worrying about that when you have all the other logic working.
Here's what it takes to get the example you referenced at http://developer.plone.org/members/member_basics.html#list-users-within-all-groups running.
First you tell Plone about your entry point. In the browser directory, in configure.zcml, add
<browser:page
for="*"
name="test_user_view"
class=".common.TestUserView"
permission="zope2.View"
/>
This says when someone goes to the url test_user_view, run the code in the class common.TestUserView.
To create the class, create a file called common.py in the browser directory, and in common.py, add
from Products.Five import BrowserView
from Products.CMFCore.utils import getToolByName import logging
logger=logging.getLogger("MyLogger: ")
class TestUserView:
def __call__(self):
"""Testing views"""
logger.info("TestUserView: __call__: ")
acl_users = getToolByName(self.context, 'acl_users')
groups_tool = getToolByName(self.context, 'portal_groups')
groups = acl_users.source_groups.getGroupIds()
for group_id in groups:
group = groups_tool.getGroupById(group_id)
if group is None:
continue
logger.info("TestUserView: __call__: group: %s" % str(group))
members = group.getGroupMembers()
member_emails = [m.getProperty('email') for m in members]
logger.info("TestUserView: __call__: member_emails: %s" % str(member_emails))
Notice that I added some logging to their example.
You can access that code at http:blahblahblah/yourplonesite/test_user_view
Hope this helps,
Mike
Post by Joe BiglerMike,
- email blast to all editors in the site
- generate a report with names and email addresses for all editors
- generate a list of all groups with their editors listed.
I have tried to build a view for this, but not sure how to proceed. I
worked through the developer.plone.org "Hello World" tutorial at
https://developer.plone.org/reference_manuals/active/helloworld/index.
html
I installed the product on my test site and got it to work for the tutorial. I have also looked at the Professional Plone 4 Development book, and posted the question in the Nabble forum. I understand the basic idea of a view, but determining the interface, the class, and the python code to get the examples on http://developer.plone.org/members/member_basics.html#list-users-within-all-groups to work is something I just don't see yet. I understand Zope browser views are an important part on Plone 4 and I need to understand how to use them, but I am frankly stuck. I don't want to have to ask someone to build every one of these I need. I need to get the principals down so I can build them on my own. Any suggestions?
I have been working with Plone since 2006. We made the jump from Plone 2.5.3 to Plone 4.1 last year. I only know Python from what little I have used it in Plone. I am working on that. I don't have any experience with an object oriented programming language. I have been programming web pages since 1998, mostly with ColdFusion and database applications since the 1990's with Visual Basic and SQL Server. I am the web administrator for the College of Education at Penn State University. You can see our site at http://www.ed.psu.edu.
I am hoping that if I can understand views to add a tutorial to the http://developer.plone.org/members/member_basics.html#list-users-within-all-groups page. I know of several administrators that would like to be able to do what I am doing, but have a similar background and are stuck as well.
Any thoughts or suggestions would be appreciated.
Joseph E. Bigler
Web Administrator
Carrara Education Technology Center
814-865-1560
233B Chambers Building
University Park, PA 16802
-----Original Message-----
Sent: Thursday, July 11, 2013 10:43 AM
To: Joe Bigler
Subject: Re: [Plone-docs] Zope View Tutorial
Hey Joe,
I don't know which tutorial you are referring to, but the Hello World tutorial has a secion of views.
https://developer.plone.org/reference_manuals/active/helloworld/index.
html
If that's not what you are interested in, you can find all the
tutorials listed at https://developer.plone.org/
Mike
Post by Joe BiglerI am looking for the zope view tutorial referenced in the Plone
Developer Manual Documentation. It is listed on page 77, section 1.2
Programming Plone in the latest version I have, April 03, 2013.
When I click on the link, it redirects me to
http://developer.plone.org/moved_content.html. This tells me the
documentation has been moved to another location, but it doesn't list
where it is. I tried checking the links on that page, but I could not find it.
The link it originally went to is
http://plone.org/documentation/tutorial/borg/zope-3-views.
I have tried multiple searches, but cannot find it. Can anyone help
with this or point me to a good zope view tutorial?
--
http://plone.293351.n2.nabble.com/Zope-View-Tutorial-tp7566584.html
Sent from the Documentation Team mailing list archive at Nabble.com.
---------------------------------------------------------------------
-
-------- See everything from the browser to the database with
AppDynamics Get end-to-end visibility with application monitoring
from AppDynamics Isolate bottlenecks and diagnose root cause in seconds.
Start your free trial of AppDynamics Pro today!
http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.
c lktrk _______________________________________________
Plone-docs mailing list
https://lists.sourceforge.net/lists/listinfo/plone-docs