Re: am I evil?

2011-03-01 Thread Andrey Popp
Hello,

On Feb 27, 2011, at 10:40 PM, Chris Withers wrote:
 I'm writing a SQLAlchemy SessionExtension based on this pattern:
 
 http://www.sqlalchemy.org/trac/browser/examples/versioning/history_meta.py?rev=7253:3ef75b251d06#L171
 
 So, in the listener, I want to record the user that made the change.
 How should I get hold of the currently authenticated user?

Maybe, you should consider another approach to this problem? I don't think that 
recipe you've mentioned is a good way of versioning content. I like more 
explicit approach here -- versioning logic be in application logic, but not 
inside persistence engine:

  some_obj = some_objects.get(123)
  user = request.user
  # mutate some_obj
  some_objects.store_revision(some_obj, user)
  

-- 
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 Andrey Popp
 The event_manager could be ZCA event API. You could also move event-firing 
 logic inside subclass of  class of some_objects repository:

Oh, sorry, I was thought of wrapping repository inside versioning repository 
proxy, not subclassing. :-)

-- 
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: pyramid_beaker vs beaker wsgi middleware

2011-03-01 Thread Andrey Popp
Hello Tres, 

 FWIW, repoze.who 2.0 explicitly works to enable / ease using the
 machinery where needed in the app by exposing the configured plugins via
 an API (the login and logout views are the obvious consumers). It also
 retainis the flexibility of middleware for enforcing policies.

sorry for some kind of off-topic, but what's the status on repoze.who 2.0? It 
seems a great piece of software, but why it's still in alpha stage?

-- 
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.



pyramid pagination gotcha: depend on WebHelpers, not paginate

2011-03-01 Thread Chris Withers

On 25/02/2011 00:20, Mike Orr wrote:

What version of webhelpers should I use? Are there any changes to the query
I should make to make it more efficient?


Just follow the WebHelpers instructions, and define a URL generator
callback to pass.

WebHelpers 1.2 is the current version and has been stable since last August.


Indeed, but just as a gotcha, make sure your install_requires lists 
WebHelpers and not paginate.


If you specify paginate, you'll get an ancient version of paginate that 
doesn't work with SQLAlchemy 0.5+


cheers,

Chris

--
Simplistix - Content Management, Batch Processing  Python Consulting
   - http://www.simplistix.co.uk

--
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.



webhelpers.paginate: html entity for symbol_previous|next

2011-03-01 Thread Chris Withers

Hi All,

I like to use laquo; and raquo; as my batch links.
If I pass these as symbol_previous and symbol_next, they get html quoted.

How can I stop that happening?

cheers,

Chris

--
Simplistix - Content Management, Batch Processing  Python Consulting
   - http://www.simplistix.co.uk

--
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 Chris Withers

On 01/03/2011 12:58, Daniel Nouri wrote:

Spurred by this discussion, I implemented a simple events system
that's akin to Zope3's object events.


For a fuller version of this pattern, check out:

http://pydispatcher.sourceforge.net/

cheers,

Chris

--
Simplistix - Content Management, Batch Processing  Python Consulting
   - http://www.simplistix.co.uk

--
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.



computing url for view registered by name

2011-03-01 Thread Chris Withers

Hi All,

I have two views:

@view_config(renderer='templates/index.pt')
class IndexView(..):
   ...

@view_config(name='history',renderer='templates/history.pt')
class HistoryView(..):
   ...

How should I generate urls to these?

cheers,

Chris

--
Simplistix - Content Management, Batch Processing  Python Consulting
   - http://www.simplistix.co.uk

--
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: webhelpers.paginate: html entity for symbol_previous|next

2011-03-01 Thread Daniel Holth
Wrap laquo; in webhelpers.html.literal() or ...set # -*- coding: utf-8 -*- 
in your Python file and just pass the unicode character to the batcher.

-- 
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.



WebTest doesn't like Pyramid NotFound rendering

2011-03-01 Thread Chris Withers

Hi All,

I have a view that raises a NotFound if it can't find the model it's 
trying to render.


I have a functional test for this that uses WebTest along the lines of:

def test_not_there(self):
self.testapp.get('/not_there', status=404)

This results in the following barf from WebTest:

self.testapp.get('/not_there', status=404)
  File build/bdist.linux-i686/egg/webtest/__init__.py, line 156, in get
  File build/bdist.linux-i686/egg/webtest/__init__.py, line 378, in 
do_request
  File 
/home/chris/buildout-eggs/WebOb-1.0.1-py2.6.egg/webob/response.py, 
line 278, in _body__get

body = self._body = ''.join(self._app_iter)
  File build/bdist.linux-i686/egg/webtest/lint.py, line 272, in next
AssertionError: Iterator listiterator object at 0xa930f6c returned a 
non-str object: u'\n html\n title404 Not 
Found/title\n body\n h1404 Not 
Found/h1\n codenot_there/code\n /body\n 
/html\n


So, looks like WebTest is complaining about the unicode object returned 
here. But, who's in the wrong? Pyramid or WebTest?


cheers,

Chris

--
Simplistix - Content Management, Batch Processing  Python Consulting
   - http://www.simplistix.co.uk

--
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.



Question about virginia

2011-03-01 Thread Georges Dubus
Hi there

I was looking at the virginia sample application, and I have a few
question :

- What mechanism protects the application from viewing the /../ dir ?
I know the open method from Filesystem check the path before opening a
file, but that doesn't explain that when going to the url 
http://localhost:6543/../
, I am redirect to http://localhost:6543/../ .

- Is there a reason so much interfaces are used ? IFilesystem is never
referenced outside of Filesystem, and IStructuredText isn't even
implemented.

Thank for helping me understand that.


Cheers,

Georges

-- 
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.



view_config registers twice if module is imported more than once with scan

2011-03-01 Thread Chris Withers

Hi All,

So, the symptom of this is an exception as follows when the config commits:

ConfigurationConflictError: Conflicting configuration actions
  For: ('view', None, '', None, InterfaceClass 
pyramid.interfaces.IView, None, None, None, 'user', None, False, None, 
None, None)

('...views.py', 119, 'module', 'class MyView(...):')
('...views.py', 119, 'module', 'class MyView(...):')

This happens because MyView is decorated with a view_config to register it.

However, I have another module (a test module as it happens, and yes I 
know importing from code under test at module level is evil in some 
peoples' eyes, but it's certainly legit to import from a module that 
contains a view class with a view_config decorator, and I believe that 
will trigger the same problem) that imports the view class and that 
import, at the time of the config.scan() appears to cause the duplicate 
registration above.


This feels like a bug to me but I thought I'd throw it out here in case 
I missed something...


My gut feels it that view_config (and likely any venusian thing) should 
do nothing if the thing it's decorating has already been visited...


cheers,

Chris

--
Simplistix - Content Management, Batch Processing  Python Consulting
   - http://www.simplistix.co.uk

--
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: computing url for view registered by name

2011-03-01 Thread Michael Merickel
I noticed in your example you aren't specifying a context= or for_= in the
view_config, implying you maybe intended to use route_name instead of name
with url dispatch.

If you are using traversal your application basically assumes a resource
tree, and so to get the url you provide a resource object that defines
__name__ and __parent__. The URL is then generated based on that resource's
location in the tree... the actual name of the view on that resource is
computed using the *elements on resource_url(). In the case of not defining
a context, you probably mean the root context object (although it could be
attached anywhere since you didn't specify). Assuming you wanted the root
context, you could do

resource_url(request.root, request)
and
resource_url(request.root, request, 'history')

HTH,
Michael

-- 
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.