How to get url query parameters in Clack, Lucerne or Caveman? - common-lisp

How can we access the url's query parameters in a Clack environment ?
It looks like they are in a clack *request* object, named query-string, but I don't know how to access them: clack is not documented and this doc isn't clear on that.
BTW, how to explore the *request* in slime's debugger, while I'm on a break for instance ? it only prints as "CLACK:REQUEST".
I see nothing in Lucerne's doc or code, and it's a shame because I like its with-params macro.
update: don't search more, this macro works very well !
Caveman has something but the common case isn't that clear to me (some find like me it is a bit cumbersome (and I'm trying out Lucerne)).

In Ningle, I can do (lack.request:request-query-parameters ningle:*request*) to get association list with all query parameters. May be it will work for you.
To inspect request in a frame, just hit "i" when cursor on a frame and enter something like ningle:*request*. I see the request like that:
#<LACK.REQUEST:REQUEST {100B2EDB73}>
--------------------
The object is a STRUCTURE-OBJECT of type LACK.REQUEST:REQUEST.
ENV: (:RAW-BODY #<FLEXI-STREAMS::VECTOR-INPUT-STREAM {100B2ED2D3}> :REQUEST-METHOD :GET :SCRIPT-NAME "" :SERVER-NAME "ws-dashb$
METHOD: :GET
SCRIPT-NAME: ""
PATH-INFO: "/some-path"
And can dive into each slot's value.
Probably it depends on optimization declarations. If does not work, try to enter (declaim (optimize (debug 3))) before loading your application.

Related

Plone traversing and forbidden Zope ids

Although you can generate by code contents with an id that starts with underscore, like "_foo" it seems that you can't traverse an item with this special id.
Every attempt to access a content named that way using a browser lead to a NotFound error. Neither methods like __bobotraverse__ or __getitem__ are called, like if this limitation is checked very early.
How this limitation works and how can I change it? Can I access subobjects with a prefix underscore in the id?
Found inside the unrestrictedTraverse implementation from OFS.Traversable:
if name[0] == '_':
# Never allowed in a URL.
raise NotFound, name
...but this is not enough. There's another check similar to the ones notified by #Mathias inside ZPublisher.BaseRequest.DefaultPublishTraverse in the publishTraverse method.
if name[:1]=='_':
raise Forbidden("Object name begins with an underscore at: %s" % URL)
The sad part is that is not simple to override this:
the unrestrictedTraverse is called on the Plone site context (so I can't customize it only for my content type)
the publishTraverse method is owned by the request implementation (maybe for this I can use ad custom publish traverser?)
The simplest way to fix this seems through monkeypatch.

Meteor handlebars {{#if}} turns strings into objects

The bug source code is here.
Let's say I'm looping over an array in Meteor using an ordinary {{#each}} loop. Each array element is a string, and I output the string every step using {{this}}. So far so good! If I use a handlebars helper to check typeof for this I'll get string. Sweet! Everything is as it should be.
But if I add an {{#if something }}-helper inside the {{#each}} (the something just returns true and thus keeps going and outputs {{this}}) the string will still look good in the HTML, but it is now an object in the typeof check!
This is super-annoying as all the (typeof someVarINeedToTest === 'string') my code might depend on now will return false.
Am I doing something wrong?
Or is this an actual bug?
If so: is it a Meteor-specific or Handlebars-specific bug?
Thanks!
Oh: the source link again. Just pull and run meteor and look in your browser console.
This is because the this variable is supposed to always be an object in JavaScript so when someFunction.apply(someContext); is called in by handlebars, JavaScript turns someContext into an object no matter what it started as. See an example here: http://jsfiddle.net/SyKSE/1/
(In this case, someFunction represents the part of your template that's within the {{#if}} statement.)
A simple (albeit ugly) workaround would be to just always pass your data in as an object, so
['this', 'is', 'an', 'array', 'that', 'we\'re', 'looping', 'through'];
becomes:
[{val: 'this'}, {val: 'is'}, {val: 'an'}, {val: 'array'}, {val: 'that'}, {val: 'we\'re'}, {val: 'looping'}, {val: 'through'}];
And then you'd change your template to look at val instead of this

How can I ask the state for a content object?

At the end of this tutorial several object attributes are listed. But I need access to the state (published, private,...). I also search that attribute using dir() but I don't see an attribute named as state or something similar. i.e, I need something like this:
>>> app.Plone.foo.bar.state
"published"
Or to keep your code more readable and not having to remember strange method names, you can use plone.api to do this:
from plone import api
api.content.get_state(obj=your_object)
Of course, you need to add plone.api to your eggs first, and re-run buildout.
You can always use the plone_workflow to determine current status:
workflowTool = getToolByName(self.portal, "portal_workflow")
status = workflowTool.getStatusOf("plone_workflow", object)
# where "object" is your content object
print (status)
Unfortunately there is no "state" attribute. Instead, check review_state using the workflow tool e.g.:
>>> app.Plone.portal_workflow.getInfoFor(app.Plone.foo.bar, "review_state")

Ploneinfo (as in phpinfo)

What is the most sraightforward (but not very hackish - unPlonish) way to create a "page" in Plone (v 4.x), which would show some Plone internals info? I'd like to generate a page document, which would paste dir() (or whatever my own function) result to <pre/> or something like that. Straightforward.. i mean, without having to create a Plone product or having to modify server files directly - just using ZMI..
You want to install plone.app.debugtoolbar
http://pypi.python.org/pypi/plone.app.debugtoolbar/
which gives you access to the most imporant informations about the current context object, request data etc.
Products.DocFinderTab adds a "Doc" tab in the ZMI that allows you to explore the current object and its methods. If you installed with the Unified Installer and use the "develop" configuration, it's already loaded.
Products.Clouseau may still work with recent Plone's, though it's aging. It gives you an AJAX interface to explore the context from within Plone.
Finally, to explore the request object, you may just add:
<div tal:replace="structure request" />
to a template. That will allow you to check all the HTTP and form variables as well as what's stored in the request.
Go to the ZMI, add a "Script (Python)", and define your function dir() and print the result like this :
print dir()
return printed

Is it possible to declare a default associative array in Smarty?

In Smarty, I know you can declare a string:
{$somevar|default:'some string'}
or even an array:
{$somevar|default:array('someval')}
How do you/Is it possible to set an associative array as a default value? as this doesn't seem to work:
{$somevar|default:array('default'=>array('subkey'=>'subval'))}
I just tried:
{$somevar|default:array('key'=>'val')}
It's the '=>' smarty doesn't like
I know its probably not the solution you're looking for, but you can always just use the {php} feature. However, I will try a few things and see if I can work the format out.
Just out of interest, why are you trying to do this in the tpl file and not in the calling PHP script?
Edit
From takeing a read, it doesn't seem like it is possible. However, there is a "set" plugin which allows it, see here (bottom example).

Resources