Multiple calls to a portlet method in Renderer class - plone

I'm creating a portlet based on Base Portlet.
In the Renderer class, I've defined a method like this :
def myMethod(self):
""" """
logger.info("hou yeah")
....
In the portlet's template I call view/myMethod
In the root site, I add my portlet.
When I go to http://www.example.com/ I see hou yeah one time. Great.
When I go to http://www.example.com/folder1 I see hou yeah twice. Uh ?
When I go to http://www.example.com/folder1/folder2/folder3 I see hou yeah four time. Really ?
Etc...
Is this a normal behavior ?
Is there a way to fix that ?
Thanks.

It is a normal behaviour, I think. you've just to find which transaction was the right one. The others are deleted by zope transactions handling.

Related

Override view (from other package), fix browser layers priority

I have a other.package registering a view my_view. Then I'm trying to replace this view with a view defined in mine this.package.
<browser:page
for="other.package.interfaces.IBarClass"
name="my_view"
class="this.package.views.FooClass"
permission="zope2.View"
layer="this.package.interfaces.IThisPackageContentLayer"
/>
For some reason my_view is not overrided. I think its about layers priority maybe, but I have no idea how to fix it. Any suggestion?
If I rename the view (name="my_view_new") it is working as expected. But if the same name is used, the original one seems to have priority. How can I change this?
UPDATE:
It's about layer priority:
(Pdb) self.request.__provides__.__iro__[13]
<InterfaceClass other.package.interfaces.layer.IOriginalLayer>
(Pdb) self.request.__provides__.__iro__[14]
<InterfaceClass this.package.content.interfaces.IThisPackageContentLayer>
You can check the activated layers from HTTP request object by looking
at self.request.provides.iro. Layers are evaluated from zero
index (highest priority) the last index (lowest priority). (source)
So, the problem is how can I prioritize a layer?
The problem was fixed by fixing the layers' priority this way:
class IThisPackageContentLayer(IOriginalLayer):
as suggested here.
Another way is, to use ZCML-Overrides with the same browser layer.
That should also override the original, but the solution with sub classing the original layer is a bit nice ;).

How do I register a MediatR post processor

I would like to try the new pipeline feature in MediatR: https://github.com/jbogard/MediatR/wiki/Behaviors
I tried the following, but it does not get executed
services.AddMediatR();
services.AddTransient(typeof(IRequestPostProcessor<,>), typeof(PostHandler<,>));
What am I missing?
You need to register the behavior associated with post-processors, like this unit test shows.
Your registration code would look like:
services.AddMediatR();
services.AddTransient(typeof(IRequestPostProcessor<,>), typeof(PostHandler<,>));
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(RequestPostProcessorBehavior<,>));
That behavior will get all the post-processors you registered and execute them.
Edit
After a comment about the post-processor running twice, I had a look at the code that registers MediatR in the ASP.NET Core built-in DI container, and it turns out instances of IRequestPreProcessor<TRequest, TResponse> and IRequestPostProcessor<TRequest, TResponse> are automatically registered as you can see here. What's left to do to get them running in the pipeline is just register the associated behavior. So the necessary registration is then:
services.AddMediatR();
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(RequestPostProcessorBehavior<,>));
I encountered the same issue as Larsi in the comment above. My code looked like this
services.AddScoped<IPipelineBehavior<AddMessageRequest, MessageResponse>, RequestPostProcessorBehavior<AddMessageRequest, MessageResponse>>();
but the behaviour still executed twice. My solution was to simply not register it manually, seems like the registration is handled otherwise now.
In my case services.AddMediatR(Assembly.GetExecutingAssembly()); was enough.
Would be nice if someone could expand on why this is.

Plone - How can I check if User is on /folder_contents view action

Because I use plone.app.widgets (1.8.0) and wildcard.foldercontents (1.3.2), I have to disable pa.widgets-Javascript only for /folder_contents tab.
Multiupload does not work with pa.widgets enabled
().fileUpload is not a function
But how can I determine that?
What I've tried:
context/absolute_url
context/##plone_context_state/object_url
getViewTemplateId
and a few more
Plone 4.3.4.1
I had a similar issue with wildcard.foldercontents and collective.z3cform.widgets..both have a related js code that goes in conflict.
i check that condition like this:
self.request.steps[-1] != "folder_contents"
In folder_contents tab, last step in the request is always "folder_contents".
I don't know if it's the best solution, but it works
Sorry, just so simple
request.ACTUAL_URL
open for a better solution :-)
You could try the following code:
mt = getToolByName(self.context, 'portal_membership')
member = mt.getMemberById(username)
if member == 'Anonymous':
pass
else:
pass
And you can handle when is Anonymou or logged member.

Plone Conditional - If Content Type is Versionable

Is there a simple way to check if a content-type, or a specific object, has Versioning enabled/disabled in Plone (4.3.2)?
For context, I am making some unique conditionals around portal_actions. So instead of checking path('object/##iterate_control').checkout_allowed(), I need to first see if versioning is even enabled. Otherwise, the action in question does not display for items that have versioning disabled, because obviously it isn't checkout_allowed.
I didn't have any luck with good ole Google, and couldn't find this question anywhere here, so I hope it's not a dupe. Thanks!
I was able to get this working by creating a new script, importing getToolByName, and checking current content type against portal_repository.getVersionableContentTypes(). Then just included that script in the conditional.
I was looking for something like this that already existed, so if anyone knows of one let me know. Otherwise, I've got my own now. Thanks again!
The first thing that checkout_allowed does is check if the object in question supports versioning at all:
if not interfaces.IIterateAware.providedBy(context):
return False
(the interface being plone.app.iterate.interfaces.IIterateAware:
class IIterateAware( Interface ):
"""An object that can be used for check-in/check-out operations.
"""
The semantics Interface.providedBy(instance) are a bit unfortunate for usage in conditions or TAL scripts, because you'd need to import the interface, but there's a reversal helper:
context.portal_interface.objectImplements(context,
'plone.app.iterate.interfaces.IIterateAware')

Open direct links to AX-objects or datasets from external application

Is there a way to open a specified document, eg "production order 123" or form, eg "purchase orders" in Ax2012 from an external application directly?
In detail, I'm looking for something similiar like AXPath, but this doesn't work with versions greater then 2009.
Is there any ( maybe included ) way to achieve this?
There is! It's using AX's drilldown functionality which uses AxHLink.exe to handle dynamics:// URLs, which are passed to the Classes\SysStartupCmd function. You could also create some custom code there if you wanted to launch the AX client executable directly.
My question I asked some while back should have a great deal of useful information in it here:
What handles dynamics:// URLs?
Some more can be found: http://technet.microsoft.com/en-us/library/aa834337.aspx
EDIT:
It sounds like you are confused or the posts weren't clear enough. I think you have 3 basic options.
Dynamics:// URLs are handled by AxHLink.exe and they only seem to handle drilldown, viewalert, and viewalertrule. So if you want to use Dynamics:// URLs, you will need to hi-jack those somehow. There is a pastbin from Jan in that other stack post.
Create a custom URI handler and event poller (lot of work) see http://axcoder.blogspot.dk/2010/10/how-to-open-form-in-running-ax-from.html
Extend SysStartupCmd and then instead of using Dynamics:// URLs, just call Ax32.exe -startupCmd directly and a parameter can be passed to your custom class.

Resources