Re: EuroPython interest?

2012-03-26 Thread Daniel Nouri
On Tue, Mar 20, 2012 at 9:51 PM, Andrew Mleczko  wrote:
> We (redturtle.net) have submitted proposals and are planning to go.
> Andrew

I'm also going.  And planning to do a Pyramid tutorial for beginners:
https://ep2012.europython.eu/conference/voting/?abstracts=not-voted&talk_type=t&language=all&order=vote&tags=


-- 
http://danielnouri.org

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-devel" group.
To post to this group, send email to pylons-devel@googlegroups.com.
To unsubscribe from this group, send email to 
pylons-devel+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-devel?hl=en.



Re: How to make Pyramid subscribers/events work in testing

2011-11-20 Thread Daniel Nouri
On Sun, Nov 20, 2011 at 3:13 AM, Ryan  wrote:
> I've got a simple subscriber that's working fine:
> @subscriber(BeforeRender)
> def add_localization(event):
>     request = event.get('request')
>     if not request:
>         request = get_current_request()
>     event['_'] = request._
> Inside of my Pryamid app's main() function:
> ...
> config.scan('app.subscribers')
> ...
> In my integration tests of view code, I'm getting an error:
> TypeError: 'Undefined' object is not callable
>
> It's because the ${_()} function isn't available to Mako because the
> subscriber didn't bind to the event.
> In my test setup I've got:
> self.config = testing.setUp()
>
> What must I do to the configurator object in order to get the events
> working?

Add this in your integration test's setup:

  self.config.scan('app.subscribers')


-- 
http://danielnouri.org

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-devel" group.
To post to this group, send email to pylons-devel@googlegroups.com.
To unsubscribe from this group, send email to 
pylons-devel+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-devel?hl=en.



Re: Context sensitive authentication policy callback??

2011-11-03 Thread Daniel Nouri
On Thu, Nov 3, 2011 at 3:38 AM, Brian  wrote:
> I have a routes based application where users create "projects", each
> projects has two types of users "administrators" and "users"
>
> I use a route factory to create a project instance as the context of
> most of my views.
>
> I use the built in AuthTktAuthenticationPolicy, inside my callback
> function I add principals, say "group:project_admins"
> "group:project_users" based on the current project.
>
> To do this my authentication policy callback is calling my project
> factory to get the current project to determine the correct principals
> for the context. The project factory is called again by the route to
> generate a context for the view. Really, I want the authentication
> policy callback to vary based on the context of the view, but I'm
> guessing authentication takes place before the routes factory is
> called.

I believe you should have a 'request.context' available in your callback.


-- 
http://danielnouri.org

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-devel" group.
To post to this group, send email to pylons-devel@googlegroups.com.
To unsubscribe from this group, send email to 
pylons-devel+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-devel?hl=en.



Re: request lifecycle

2011-03-31 Thread Daniel Nouri
On Thu, Mar 31, 2011 at 4:44 PM, Chris Withers  wrote:
> On 31/03/2011 15:40, Daniel Nouri wrote:
>> FWIW, get_current_request() works with 'before_insert' and
>> 'before_update' events.
>
> I don't see these listed here:
>
> http://www.sqlalchemy.org/docs/orm/interfaces.html?highlight=sessionextension#sqlalchemy.orm.interfaces.SessionExtension
>
> Where are you getting them from?

sqla 0.7 has them


-- 
http://danielnouri.org

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-devel" group.
To post to this group, send email to pylons-devel@googlegroups.com.
To unsubscribe from this group, send email to 
pylons-devel+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-devel?hl=en.



Re: request lifecycle

2011-03-31 Thread Daniel Nouri
On Thu, Mar 31, 2011 at 4:23 PM, Chris Withers  wrote:
> Hi All,
>
> I'm using zope.sqlalchemy to commit a a SQLAlchemy session.
> As part of that commit, I want to record the user making the change as an
> attribute of the changed object.
>
> To do this, in a SessionExtension's before_flush method I do:
>
>  user_id = authenticated_userid(get_current_request())
>
> Now, the problem is that get_current_request() is returning None at this
> point.

FWIW, get_current_request() works with 'before_insert' and
'before_update' events.


-- 
http://danielnouri.org

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-devel" group.
To post to this group, send email to pylons-devel@googlegroups.com.
To unsubscribe from this group, send email to 
pylons-devel+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-devel?hl=en.



Re: am I evil?

2011-03-01 Thread Daniel Nouri
Spurred by this discussion, I implemented a simple events system
that's akin to Zope3's object events.

>From the docs:

  To subscribe only to insert events of documents, do::

  def document_insert_handler(event):
  print event.object, event.request
  kotti.events.objectevent_listeners[(kotti.events.ObjectInsert,
kotti.resources.Document)].append(
  document_insert_handler)

The actual insert, update, delete events are still coming from
SQLAlchemy but turned into events that hide away calls to
"get_current_request" and the necessity to deal with SQLAlchemy
internals, that is, calls to "session.is_modified" on update.

See https://github.com/dnouri/Kotti/blob/master/kotti/events.py


-- 
Daniel Nouri
http://danielnouri.org

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-devel" group.
To post to this group, send email to pylons-devel@googlegroups.com.
To unsubscribe from this group, send email to 
pylons-devel+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-devel?hl=en.



Re: am I evil?

2011-03-01 Thread Daniel Nouri
On Tue, Mar 1, 2011 at 8:09 AM, Chris Withers  wrote:
> On 28/02/2011 18:42, Tres Seaver wrote:
>>
>> -BEGIN PGP SIGNED MESSAGE-
>> Hash: SHA1
>>
>> On 02/28/2011 12:53 PM, Chris Withers wrote:
>>>
>>> On 28/02/2011 16:58, Tres Seaver wrote:
>>>>>
>>>>> I'm worried that I'm being evil. Am I being evil?
>>>>> How else can I get hold of Pyramid's notion of the current user id
>>>>> inside a SessionExtension?
>>>>
>>>> The "approved" way to share request-specific information is to just pass
>>>> the request:  in this case, the obvious candidate is to make the request
>>>> an attribute of the event.
>>>
>>> What event are you referring to?
>>
>> The one published to your listener.
>
> What listener?
>
> I'm using a SessionExtension:
>
> http://www.sqlalchemy.org/docs/orm/interfaces.html#session-events

That probably qualifies for "not being able to change the event code".

> The only way I can think to get request there would be to try and stick it
> on either the model object, or the session object, both of which feel even
> more hacky than getting it from a thread local...

I have very similar code in Kotti that gets hold of the request to set
the owner id:

  https://github.com/dnouri/Kotti/blob/master/kotti/events.py

And I don't feel evil at all.  Though testing it turned out to be
indeed a bit tricky:

  https://github.com/dnouri/Kotti/blob/master/kotti/tests.py#L626

Maybe the docs should be changed to say it's OK if you're working with
a third party API and you know what you're doing.


Daniel


-- 
Daniel Nouri
http://danielnouri.org

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-devel" group.
To post to this group, send email to pylons-devel@googlegroups.com.
To unsubscribe from this group, send email to 
pylons-devel+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-devel?hl=en.



Re: varying template name which matches route path

2011-02-25 Thread Daniel Nouri
On Thu, Feb 24, 2011 at 9:13 PM, AwaisMuzaffar  wrote:
>
> Lets assume, I have the following route set up:
>
> config.add_route('pages', '/{page}/', view='testproject:views.pages',
> view_renderer='testproject:templates/page.mak')
>
> Would it be possible to make the template name e.g page.mak a variable
> that matches the name of the response path.
>
> something like: view_renderer = .. templates/{page}.mak
>
> So template name uses the path name.
>
> I hope you guys understand what I am getting at.

You can leave out 'view_renderer' here and return a rendered template
from your view instead.  Your view function could then look like this:

def pages(request):
name = request.matchdict['page']
return render_to_response('templates/%s.pt' % name, request=request)

See http://docs.pylonsproject.org/projects/pyramid/dev/narr/templates.html


-- 
Daniel Nouri
http://danielnouri.org

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-devel" group.
To post to this group, send email to pylons-devel@googlegroups.com.
To unsubscribe from this group, send email to 
pylons-devel+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-devel?hl=en.