Re: Invoking WSGIController.__call__(..) again in case of an error (db deadlock)

2010-11-05 Thread Tomasz Nazar
so we did it...

import pylons
from pylons.controllers.util import Response
response_options = config['pylons.response_options']
request_counter = 1
while request_counter = MAX_REQUEST_TRIES:
try:
pylons_obj = environ['pylons.pylons']
registry = environ['paste.registry']
pylons_obj.response =
Response(content_type=response_options['content_type'],

charset=response_options['charset'])
pylons_obj.response.headers.update(response_options['headers'])
registry.register(pylons.response, pylons_obj.response)

transaction_filter.start()
result = WSGIController.__call__(self, environ, start_response)
transaction_filter.commit()

return result
except:
pass...


On Tue, Oct 19, 2010 at 3:25 PM, Tomasz Nazar tomasz.na...@gmail.com wrote:
 Hello there!
 I got this neat idea, and I'm not sure if it is supposed to work...

 Quick (if you're not interested in the full scenario)
 Is it possible to invoke: WSGIController.__call__(self, environ,
 start_response) many times during 1 http request to Pylons?


 A bit longer description:
 My user scenario is:
 Browser/user sends request ---
     1* server receives and calls some Controller
     1* WSGIController.__call__(self, environ, start_response) is
 being invoked, which..
     1* raises some Exception (database deadlock)
     -- error middleware catches exception, and redirects error page
 user gets error page --

 Above is normal situation. I'd like to improve it, so that server
 itself tries to handle db exception by restarting the request and
 _maybe_ next time DB will unlock tables, so that
 still-the-same-request can be processed without an error to the user.

 So here is what I do:

 Browser/user sends request ---
     * server receives and calls some Controller
     1* WSGIController.__call__(self, environ, start_response) is
 being invoked, which..
     1* raises some Exception (database deadlock)
     2* I catch the exception and run again:
 WSGIController.__call__(self, environ, start_response)
     2* still raises some Exception (database deadlock)
     3* I catch the exception and run again:
 WSGIController.__call__(self, environ, start_response)
     * db is now unlocked and requests completes
     -- some Mako page is returned to a user
 user SHOULD gets some success page --


 What happens is that returned value from __call__(..) is not quite
 HTML string. Rather, it's a concatenation of final HTML with the same
 HTML page with tags escaped...
 So instead of str(htmlHello/html)
 I get str(lt;htmlgt;Hellolt;/htmlgt;htmlHello/html) which is 
 wrong...

 Should I call sth else before calling __call__ again()
 Will it work, can it be done?

 Thanks for any response

 T.



 --
 _i__'simplicity_is_the_key'__tomasz_nazar
 _ii'i_am_concern_oriented'JKM-UPR
 _iii__'patsystem.sf.net'___linux_user
 _'aspectized.com'___prevayler




-- 
_i__'simplicity_is_the_key'__tomasz_nazar
_ii'i_am_concern_oriented'JKM-UPR
_iii__'patsystem.sf.net'___linux_user
_'aspectized.com'___prevayler

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



Invoking WSGIController.__call__(..) again in case of an error (db deadlock)

2010-10-19 Thread Tomasz Nazar
Hello there!
I got this neat idea, and I'm not sure if it is supposed to work...

Quick (if you're not interested in the full scenario)
Is it possible to invoke: WSGIController.__call__(self, environ,
start_response) many times during 1 http request to Pylons?


A bit longer description:
My user scenario is:
Browser/user sends request ---
 1* server receives and calls some Controller
 1* WSGIController.__call__(self, environ, start_response) is
being invoked, which..
 1* raises some Exception (database deadlock)
 -- error middleware catches exception, and redirects error page
user gets error page --

Above is normal situation. I'd like to improve it, so that server
itself tries to handle db exception by restarting the request and
_maybe_ next time DB will unlock tables, so that
still-the-same-request can be processed without an error to the user.

So here is what I do:

Browser/user sends request ---
 * server receives and calls some Controller
 1* WSGIController.__call__(self, environ, start_response) is
being invoked, which..
 1* raises some Exception (database deadlock)
 2* I catch the exception and run again:
WSGIController.__call__(self, environ, start_response)
 2* still raises some Exception (database deadlock)
 3* I catch the exception and run again:
WSGIController.__call__(self, environ, start_response)
 * db is now unlocked and requests completes
 -- some Mako page is returned to a user
user SHOULD gets some success page --


What happens is that returned value from __call__(..) is not quite
HTML string. Rather, it's a concatenation of final HTML with the same
HTML page with tags escaped...
So instead of str(htmlHello/html)
I get str(lt;htmlgt;Hellolt;/htmlgt;htmlHello/html) which is wrong...

Should I call sth else before calling __call__ again()
Will it work, can it be done?

Thanks for any response

T.



-- 
_i__'simplicity_is_the_key'__tomasz_nazar
_ii'i_am_concern_oriented'JKM-UPR
_iii__'patsystem.sf.net'___linux_user
_'aspectized.com'___prevayler

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



Re: pylons and hoteditor

2009-02-17 Thread Tomasz Nazar

As far as I understand I have similar problem. Here's solution.
(The topic it's not related to Pylons at all ;)


Instead of direct output of i18n key's value:
var x = '${_('my.key')}

I do:
* use Jquery to simplify (not required)
* use mix of HTML/JS helpers

A) Create html list of all keys accessed in the page:
pre id='translations' style='display: none'
   pre id='my.key'${_('my.key')}/pre
   pre id='my.key2'${_('my.key2')}/pre
   .

B) Get all values into dict object
script
  var translations = get_translations(); //code below

C) access without \n\r problems
  var x = translations['my.key']


  var get_translations = function(){
var dict = new Object();
var jq_div = $('#translations  pre');
for (var i=0; ijq_div.length; i++){
dict[jq_div[i].id] = jq_div[i].innerHTML;
}
return dict;
  }
/script



On Wed, Feb 4, 2009 at 10:12 AM, przemek.ch przemek...@gmail.com wrote:

 There's a nice wysiwyg/bbcode editor 
 http://www.ecardmax.com/hoteditor/index.html.

 But I'm confused about one thing.

 The editor works like that:
 td
 script
   var getdata =[B]Test me[/B];
   Instantiate(min,editor, getdata , 600px, 200px);
 /script
 /td

 So the editor will be loaded and the content form getdata will be
 added.


 But there's one big problem wilt new line and return carriage
 characters.

 Example:

 1. Enter characters in new lines

 a
 b
 c

 2. Save it into db as bbcode.
 It will be saved as a \n\r b \n\r c - of course \n\r will not be
 visible as string '\n\r'

 3. Then I want to load that content to the editor from DB

 var getdata =${h.content_form_db};
 Instantiate(min,editor, getdata , 600px, 200px);


 And here's the problem, generated code looks like that:

 var getdata =a
 b
 c;
 Instantiate(min,editor, getdata , 600px, 200px);

 So it's not a valid js code and it will fail.

 Ok so I've done something like that:
 Before i save bbcode content to db i replace \n to \\n and remove all
 \r.
 This works and now the generated code looks like that.

 var getdata =a\nb\nc;
 Instantiate(min,editor, getdata , 600px, 200px);

 But there's a new problem.
 If a user will put into editor '\n' or '\r' string my replace method
 will fail...

 Any suggestions?

 




-- 
_i__'simplicity_is_the_key'__tomasz_nazar
_ii'i_am_concern_oriented'JKM-UPR
_iii__'patsystem.sf.net'___linux_user
_'aspectized.com'___prevayler

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



Re: 'c' variable between redirects

2008-11-12 Thread Tomasz Nazar

Just a quick summary of what I found to be useful (though I don't yet
use new Pylons)
Flash Messages. It solves issues of 'c' being too transient, and
session scope being too wide.

T.

-- 
_i__'simplicity_is_the_key'__tomasz_nazar
_ii'i_am_concern_oriented'JKM-UPR
_iii__'patsystem.sf.net'___linux_user
_'aspectized.com'___prevayler

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



Re: Pylons: pros and cons

2008-10-20 Thread Tomasz Nazar

Let me thank all of you who took part in this discussion.
I'm glad that I put my remarks about Pylons and related components
here. I gained some new knowledge and updated existing one.
Thanks :) and see you around..

T.

-- 
_i__'simplicity_is_the_key'__tomasz_nazar
_ii'i_am_concern_oriented'JKM-UPR
_iii__'patsystem.sf.net'___linux_user
_'aspectized.com'___prevayler

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



Re: Pylons: pros and cons

2008-10-16 Thread Tomasz Nazar
-- 
_i__'simplicity_is_the_key'__tomasz_nazar
_ii'i_am_concern_oriented'JKM-UPR
_iii__'patsystem.sf.net'___linux_user
_'aspectized.com'___prevayler

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



pycon.tar.gz
Description: GNU Zip compressed data


Re: Pylons: pros and cons

2008-10-16 Thread Tomasz Nazar

On Thu, Oct 16, 2008 at 2:08 AM, Mike Orr [EMAIL PROTECTED] wrote:

 On Wed, Oct 15, 2008 at 4:35 PM, Tomasz Nazar [EMAIL PROTECTED] wrote:

 On Tue, Oct 14, 2008 at 5:20 AM, Michael Bayer [EMAIL PROTECTED] wrote:


 On Oct 13, 12:14 pm, Tomasz Nazar [EMAIL PROTECTED] wrote:
 1) all model classes are defined in 1 file together with database mapping

 like everyone is saying, you can roll this however you want and
 however is appropriate to the type of app you're building.


 Michael and Mike - I've just found your new tutorial on how to use
 SQLA and how to setup classes in separate files! That's it!
 I wasn't looking into docs for a while :(
 http://wiki.pylonshq.com/display/pylonsdocs/Using+SQLAlchemy+with+Pylons

 It looks I can split my big file - I dreamed about that. That is great!

 One stuff that doesn't work for me is autoload a table definition. I
 almost copied your MyApp.tar.gz sources and adjusted to autoload. But
 doesn't work.

 -- sqlalchemy.exceptions.UnboundExecutionError: The MetaData is not
 bound to an Engine or Connection.  Execution can not proceed without a
 database to execute against.  Either execute with an explicit
 connection or assign the MetaData's .bind to enable implicit
 execution.

 I tried to move all mappings + t_tables to init_model (as engine is
 only available then), but still fail.
 Is it too much asking for similar source code, but with classes split
 into files and working with 'autoload'?
 Or point to a right way at least :) I can upload source when I'm done with 
 it..

 I think you need to read the SQLAlchemy manual about how engines
 propagate and autoloading works.  Then you'll be able to do it
 yourself.

 In summary, SQL queries (including ORM operations) need a database
 connection on which to operate.  The engine gives out connections in a
 thread-safe manner, so you can just pretend the engine is a connection
 and everything works.  The engine is necessary only when you *execute*
 a query; e.g., SQL.execute(), Session.execute(), Session.commit().
 query.all(), using a query as an iterator, etc.

 Most execution methods take a bind= argument to make it use that
 engine.  Autoloading is an exception because its argument is
 autoload_with= .  (I think it was a bad design choice to not call it
 bind=, but that's the way it is.)  If you don't use bind=, a
 Session-based query will look for an engine bound to the session, and
 then for an engine bound to the metadata.  If neither exists the query
 will fail with the error you're seeing.  A non-session-based SQL query
 will look in the metadata for an engine, and fail in the same way if
 there is none.

 So you should bind your engine to the session, use Session.execute()
 for any non-ORM operations you have to do, and pass bind= and
 autoload_with= to the remaining methods which don't fit into either
 category: table(autoload_with=), meta.create_all(bind=).

 You can also bind the engine to the metadata to avoid the
 inconvenience of those  bind= and autoload_with= arguments.  Bound
 metadata is no longer recommended for beginners because it's a bit
 magical, and because you can get into trouble if you have an ORM
 transaction open and simultaneously modify the database at the SQL
 level without going through Session.execute() -- this may give the ORM
 an incorrect impression of the database state, or the database may
 implicitly commit the pending transaction without the ORM realizing
 it.  But it does work.

 --
 Mike Orr [EMAIL PROTECTED]

OK. I have clean Pylons 0.9.6.2 app working with 3 classes into
separate modules.
Works with MySql. Sqlite seems not to store objects (code the same,
just exchanging sqlalchemy.url). Why?
Cyclic dependencies do not work just that simple. Cyclic imports
unfortunately have to placed inside a method - not at the top of
module.
I'd still use some help here.

I'll try to attach full source - hope googlegroups allows that..
For impatient sample code below:
app=pycon, requires mysql or sqlite, 3 classes defined

#
pycon.model.phone.py:
class Phone(object):
pass

pycon.model.participant.py
from pycon.model.conference import Conference
class Participant(object):
pass

pycon.model.conference.py:
from datetime import datetime
class Conference(object):
def __init__(self, subject=None):
self.subject = subject
self.date = datetime.now()

def __str__(self):
return %s, s: %s % (self.__class__.__name__, self.subject)

def cyclic_dependency(self):
#importing at the top of module causes cyclic import issue :(
from pycon.model.participant import Participant
pass


pycon.model.__init__.py:
import sqlalchemy as sa
from sqlalchemy import orm
from pycon.model import meta

from pycon.model.phone import Phone
from pycon.model.participant import Participant
from pycon.model.conference import Conference

def init_model(engine):
Call me before using any of the tables or classes

Re: Pylons: pros and cons

2008-10-16 Thread Tomasz Nazar

On Thu, Oct 16, 2008 at 2:41 PM, cropr [EMAIL PROTECTED] wrote:

 wrt to organizing the model into different files, I've changed the
 scheme that's is autogenerated in 0.9.7rc2.

 My __init__.py looks like

 ##
 from sqlalchemy import MetaData
 from sqlalchemy.orm import scoped_session, sessionmaker

 engine = None
 meta = MetaData()

 def init_model(engine):
Call me before using any of the tables or classes in the
 model
sm = sessionmaker(autoflush=True, autocommit=False, bind=engine)
meta.engine = engine
meta.Session = scoped_session(sm)

 # below are all individual classes
 from user import *
 from item import *
 from folder import *
 from page import *
 ###

 every class file contains the tabel definition, the class defintion
 and the mapper. example
 page.py, containing, Page a derived class from Item

 
 from sqlalchemy import MetaData, Column, Table, types, ForeignKey
 from sqlalchemy.orm import mapper, relation, backref

 from project.model import *

 page = Table('page', meta.metadata,
Column('id', types.Integer, ForeignKey('item.id'),
 primary_key=True),
Column('path', types.String(255)),
Column('language', types.String(2)),
Column('label', types.String(255)),
)

 class Page(Item):
def __init__(self, identifier, **arg):
self.identifier = identifier
for (k,v) in arg.iteritems():
setattr(self,k,v)

 mapper(Page, page, inherits=Item, polymorphic_identity='page')
 ###

 but of course this all is a personal preference

 Ruben

I wouldn't mind to also have table + mapping inside a file with class.
But there are some issues with mapping using 'autoload'  - engine does
not exist yet. Isn't it?

T.


-- 
_i__'simplicity_is_the_key'__tomasz_nazar
_ii'i_am_concern_oriented'JKM-UPR
_iii__'patsystem.sf.net'___linux_user
_'aspectized.com'___prevayler

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



Re: Pylons: pros and cons

2008-10-16 Thread Tomasz Nazar

On Thu, Oct 16, 2008 at 8:55 PM, Mike Orr [EMAIL PROTECTED] wrote:

 On Thu, Oct 16, 2008 at 4:12 AM, Tomasz Nazar [EMAIL PROTECTED] wrote:
 Cyclic dependencies do not work just that simple. Cyclic imports
 unfortunately have to placed inside a method - not at the top of
 module.

 Importing in a function is the best way to deal with cyclic imports,
 yes.  Although even better is to avoid them entirely.

Yes. Of course it is :)
It's a matter of taste. I don't like having imports inside a method,
though sometimes that's the only way..


 Why do conference and participant have to import each other?  Neither
 is using the other as its base class.  If  you have a tight
 relationship between two classes like this, it's a good reason to put
 them in the same module.

That was just a fake example to test if that works.
In real examples I have few such situations and I won't elaborate on that.
I feel sorry that Python import works this way. It's just the way it
is.. So I look for best method to work round that.
I do not have and don't want to design my classes and modules in a
tree like graph. IMHO Python forces me here too much - and my nature
is to resist when pushed too much ;)

T.



-- 
_i__'simplicity_is_the_key'__tomasz_nazar
_ii'i_am_concern_oriented'JKM-UPR
_iii__'patsystem.sf.net'___linux_user
_'aspectized.com'___prevayler

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



Re: Pylons: pros and cons

2008-10-15 Thread Tomasz Nazar

Thanks for such detailed answer Michael.

On Tue, Oct 14, 2008 at 5:20 AM, Michael Bayer [EMAIL PROTECTED] wrote:


 On Oct 13, 12:14 pm, Tomasz Nazar [EMAIL PROTECTED] wrote:
 2) SQLAlchemy 2nd level cache

 That is most frustrating for me coming from Hibernate, where it's
 built in. You may point to memcached or whatever, but the truth is it
 improves performance and coding style hugely!
 I would love to optimize later and be a bit lazy.
 Maybe the authors do not have resources -- it's a great soft anyway --
 but that should be one of the 1st features on the roadmap.

  pull from the giant vat of identifiers when needed.  This was one of
 the original issues SQLA sought to solve, and makes it a whole lot
 easier to load several levels of objects, with or without a LIMIT/
 OFFSET applied to the overall results, with only one round trip.


I started to play with SQLa joins and 'add_entity' feature lately, so
if I would get all objects in one query that would be not so bad.
However, to do that one needs to learn SQLa query language a lot, and
build some advanced queries (and there aren't lots of examples in the
documentation :( ).
And also with 'add_entity' I loose my OO, and relations between
objects. Query result is not just a list of objects, but a touple of
all the different objects from the query...


Or one can write custom SQL query instead of SQLA query. Then we have
a list of kind of DTO objects. Also not that pretty.
Both ways (I use them) but have disadvantages.


Having 2nd level cache would allow a developer to write short and easy code.
I could write basic SQLA queries for objects and iterate through their
relations (even when few levels deep).
Of course, for the first time it would take long to hit DB with many
queries, but -- with cache -- further requests do not exist, cause
cache is hit instead.

That has advantage in early (even after 1 year) stage of project, so I
do not have to worry about fancy SQL queries or about learning SQLA
query language. I worry more about other stuff (understanding business
domain, etc..) So as developer spend precious time elsewhere.

Also code would be a lot simpler:
confs = dbsession().query(Conference).filter(XXX).all()
%for conf in confs:
   ${conf} ${conf.author} ${conf.author.phone}  etc...

It's that simple with cache being used.
Without that... code is more complicated.


 But eager loading isn't as good as no loading at all - so onto caching
 for SQLA.  There's some reasons they're inconvenient.   ORM mapped
 objects usually need to load additional data (i.e. lazyloading) which
 implies an association with an active database connection.  Caching
 the ORM objects means you have to dance around all the lazy loaders to
 ensure none fire off, since there is no active database connection -
 furthermore, even if you re-associated them with one, now you have a
 concurrency issue.

 Secondly, its incredibly common to get some ORM mapped objects from
 somewhere and start using them in a transaction.  If you get them from
 a cache, again you lose because they're global objects - you can't map
 them back to your transaction.  So ORM caching which seems very simple
 and automatic quickly leads to some very broken use cases for those
 who don't understand what they're doing.

I'd live with that. I mostly need cached objects for read-only view
layer, to iterate over objects and their relations..
Hibernate guys did that and I didn't had any problems with that cache.
For updating object from cache, I will load it from db anyway (or merge).


 Pylons and Mako offer some of the most flexible view level caching
 around - you can cache controller methods, functions, template
 renders, and individual components (defs) of templates.  I recently
 just wrote a small %def which sits in the globally inherited layout
 template, wraps the middle of the page in a conditional cache which is
 enabled and configured by a method called in the controller - so that
 context-sensitive info in the header (like login info) stays context
 sensitive, the content-heavy middle is optionally cached, all the
 parameters and zoning of the cache is configured at the controller
 level, the ORM fetches data purely from the DB (but less often), and
 none of the templates have any idea whether or not they're cached or
 for how long.   This is likely the subject of my next Pylons/Mako blog
 entry.

I was thinking about your idea of caching view layer, instead of
having 2nd level object cache.
Yes - it is new for me. In Java it might be it is not so common.
I will give it a try..
Please, do write a blog then. It would be nice to listen to.
With examples please :)

T.


-- 
_i__'simplicity_is_the_key'__tomasz_nazar
_ii'i_am_concern_oriented'JKM-UPR
_iii__'patsystem.sf.net'___linux_user
_'aspectized.com'___prevayler

--~--~-~--~~~---~--~~
You received this message because you

Re: Pylons: pros and cons

2008-10-15 Thread Tomasz Nazar

On Tue, Oct 14, 2008 at 5:20 AM, Michael Bayer [EMAIL PROTECTED] wrote:


 On Oct 13, 12:14 pm, Tomasz Nazar [EMAIL PROTECTED] wrote:
 1) all model classes are defined in 1 file together with database mapping

 like everyone is saying, you can roll this however you want and
 however is appropriate to the type of app you're building.


Michael and Mike - I've just found your new tutorial on how to use
SQLA and how to setup classes in separate files! That's it!
I wasn't looking into docs for a while :(
http://wiki.pylonshq.com/display/pylonsdocs/Using+SQLAlchemy+with+Pylons

It looks I can split my big file - I dreamed about that. That is great!

One stuff that doesn't work for me is autoload a table definition. I
almost copied your MyApp.tar.gz sources and adjusted to autoload. But
doesn't work.

-- sqlalchemy.exceptions.UnboundExecutionError: The MetaData is not
bound to an Engine or Connection.  Execution can not proceed without a
database to execute against.  Either execute with an explicit
connection or assign the MetaData's .bind to enable implicit
execution.

I tried to move all mappings + t_tables to init_model (as engine is
only available then), but still fail.
Is it too much asking for similar source code, but with classes split
into files and working with 'autoload'?
Or point to a right way at least :) I can upload source when I'm done with it..

T.



-- 
_i__'simplicity_is_the_key'__tomasz_nazar
_ii'i_am_concern_oriented'JKM-UPR
_iii__'patsystem.sf.net'___linux_user
_'aspectized.com'___prevayler

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



Pylons: pros and cons

2008-10-13 Thread Tomasz Nazar

Hi there!

I've been a Pylons user for more than a year already. Few other people
in the neighbourhood ask me for Pylons advantages often, so I also
talk about Pylons disadvantages also.
Here I'd like to point out some of them and ask you for your
opinion/answer.. (basically I'm a happy Pylons user :) )

It may also be hard to define things below as related to Pylons only,
as Pylons is often just a glue to other frameworks (aka SQLA..).
Nevertheless full Pylons books contains several chapters treat about
these, so let me also point them out.

Here goes:

1) all model classes are defined in 1 file together with database mapping

That is 2nd most frustrating on my daily work. Even in Pylons tutorial
you've advised to mix all the code together in models/__init__.py.
Business logic in my small app contains more than 3K of code and is in
a single file!
I already moved out DB SQLA mappings into separate file, but that's
just a tip of the iceberg.

So I ask: why is that? Each model class should be in a separate file
(aka Rails, java frameworks, etc)
Is reason other than problems with pure Python imports (which don't
work well for recursive dependencies)?
Why: __init__.py -- there are lot's better names.
Also, when one uses IDE and tries to find (by incremental file search)
__init* there are many of them. Name it domain.py or model.py
And finally: any Python ways to split _my_ big file?


2) SQLAlchemy 2nd level cache

That is most frustrating for me coming from Hibernate, where it's
built in. You may point to memcached or whatever, but the truth is it
improves performance and coding style hugely!
I would love to optimize later and be a bit lazy.
Maybe the authors do not have resources -- it's a great soft anyway --
but that should be one of the 1st features on the roadmap.


3) flash messages : data persisted somewhere between http session
and http request, which lives through one session of http redirects,
but then is purged.

I often need that, as I place some common controller logic in some
controllers. Say: home.py:home which redirects to home.mako, and loads
complete user profile. I often use
h.redirect_to(cont=home,action=home) from inside other controllers.
I think such feature should be built in, similar to c, and session
variables.


4) CRUD: generate view + controller methods

Having controller file with CRUD methods already defined (using SQLA)
and redirecting to template files would be nice to have.
I don't need that at this stage of project, where I use custom views
all over the place. But for beginners it would be nice to have
CRUD*.mako(s) created (as option?) and to have working application
almost instantly.
It's often said that Django does that, and Pylons not :(


5) easy_install pylons - Beta

It's a minor, but let me say that: When last time I installed Pylons
in Windows for a friend, it downloaded some eggs which were beta stage
(sqlalchemy?). I just know that proper 0.9.6 app was not working.. We
had to downgrade few eggs to make it work.


OK. So that'd be it. Don't make me wrong. Using Pylons so much time I
like it's simplicity. I don't like things above.

I look to hear your opinions - Tomasz







-- 
_i__'simplicity_is_the_key'__tomasz_nazar
_ii'i_am_concern_oriented'JKM-UPR
_iii__'patsystem.sf.net'___linux_user
_'aspectized.com'___prevayler

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



Re: Pylons: pros and cons

2008-10-13 Thread Tomasz Nazar

Thanks both of you for answers...

On Mon, Oct 13, 2008 at 7:39 PM, Wayne Witzel [EMAIL PROTECTED] wrote:
 On Oct 13, 12:14 pm, Tomasz Nazar [EMAIL PROTECTED] wrote:
 Hi there!

 1) all model classes are defined in 1 file together with database mapping

 That is 2nd most frustrating on my daily work. Even in Pylons tutorial
 you've advised to mix all the code together in models/__init__.py.
 Business logic in my small app contains more than 3K of code and is in
 a single file!
 I already moved out DB SQLA mappings into separate file, but that's
 just a tip of the iceberg.

 So I ask: why is that? Each model class should be in a separate file
 (aka Rails, java frameworks, etc)
 Is reason other than problems with pure Python imports (which don't
 work well for recursive dependencies)?
 Why: __init__.py -- there are lot's better names.
 Also, when one uses IDE and tries to find (by incremental file search)
 __init* there are many of them. Name it domain.py or model.py
 And finally: any Python ways to split _my_ big file?


 You can take this as far as you would like. I have my init_model
 method and mappers in model/__init__.py
 My tables and their classes and logic are each in their own file in
 model/tables

 from project.model.tables import table1

 __init__.py is a Python convention and really has nothing to do with
 Pylons.

Table definitions might be in one place. I don't bother about that.
It's around 50 lines.
What I want is to separate classes definition into separate files / modules.
I always hit the wall with Python saying 'cannot import name ..' --
cause of recursive dependencies.
And for that I see place of having a doc for that.

I'm influenced a bit by Java, so I might not fully understand Python modules.
If modules are the only way to separate into files - I'm fine.
I will try again to split with latest Pylons code, maybe I'm having
some stupid bug. But I was trying 2 times and failed. Let's make it 3
then.



 2) SQLAlchemy 2nd level cache

 That is most frustrating for me coming from Hibernate, where it's
 built in. You may point to memcached or whatever, but the truth is it
 improves performance and coding style hugely!
 I would love to optimize later and be a bit lazy.
 Maybe the authors do not have resources -- it's a great soft anyway --
 but that should be one of the 1st features on the roadmap.

 Memcached works great. Why implement an maintain another 2nd level
 caching system when a good one already exists and is very easy to
 plugin to SA?

 mapper(Foo, foo_table, extension=MemCachedMapper(mc, timeout=35))

I don't bother if it's implemented with memcached or any other. I
bother about having it at all.
Don't say to me it's easy to implement. If it's easy then as an author
I'd feel obliged to provide that. Other ORMs in the world have that.
Should I say more.. (?)

OK. Back to your code? What is this MemCachedMapper.. google 2 hits
only. Is it your own solution, does it work, can you share?



 3) flash messages : data persisted somewhere between http session
 and http request, which lives through one session of http redirects,
 but then is purged.

 I often need that, as I place some common controller logic in some
 controllers. Say: home.py:home which redirects to home.mako, and loads
 complete user profile. I often use
 h.redirect_to(cont=home,action=home) from inside other controllers.
 I think such feature should be built in, similar to c, and session
 variables.

 Make yourself a component template and include it on pages you need to
 present a flash

 %def name=flash()
% if session.has_key('flash'):
div id=flashp${session.get('flash')}/p/div
%
del session['flash']
session.save()
%
% endif
 /%def

Yeah. I already did that months ago. I just feel it's good to propose
to include in Pylons, so you know one would make use of that..



 4) CRUD: generate view + controller methods

 Having controller file with CRUD methods already defined (using SQLA)
 and redirecting to template files would be nice to have.
 I don't need that at this stage of project, where I use custom views
 all over the place. But for beginners it would be nice to have
 CRUD*.mako(s) created (as option?) and to have working application
 almost instantly.
 It's often said that Django does that, and Pylons not :(

 But what if I don't want that? .. 2-way street. Take a look at the
 template for RESTful controllers. You could easily implement yourself
 a CRUD controller to do just this. Then make a patch and open a
 feature ticket and attach your patch. Who knows :)

If it's 2-way you don't go it. Someone else could go..
I don't insist on that. It'd be nice to have. I will have look at what
you propose. Thanks.




 5) easy_install pylons - Beta

 It's a minor, but let me say that: When last time I installed Pylons
 in Windows for a friend, it downloaded some eggs which were beta stage
 (sqlalchemy?). I just know that proper 0.9.6 app was not working.. We
 had to downgrade few

Re: Pylons, sqlalchemy db awareness

2008-02-18 Thread Tomasz Nazar

Just noticed this not responded topic... maybe I can still help..

The Pylons session (nor even Java/Hibernate) DOES NOT have any
knowledge of any parallel changes to underlying database that you use.
So you a) shouldn't do concurrent modifications on database
b) if you have to, then like you suggested: pool some DB info with
some frequency.

T.


On Nov 10, 2007 9:13 AM, kettle [EMAIL PROTECTED] wrote:

 Maybe I can rephrase this more simply.  I want to know if my pylons/
 sqlalchemy session has realtime knowledge of the database it is
 working with, or if the only way to achieve this is through a stored
 procedure or constant polling. -joe


 On Nov 10, 4:57 pm, kettle [EMAIL PROTECTED] wrote:
  Hi,
I am new to pylons/sqlalchemy, and not sure whether this question
  belongs in a sqlalchemy forum or this pylons forum but... basically
  I'd like to know what kind of awareness the sqlalchemy model for my
  pylons application has of the database.  Specifically, does it have
  any kind of realtime knowledge of the database with regard to table
  updates or row insertions?  If I want to know about updates to the
  database (many of which are coming from remote clients) and convey
  this information or log it in my pylons application, is there any way
  to do this without constantly polling the database, and if possible,
  also without implementing a trigger in the db, or an in memory copy of
  the latest updates/insertions?
If sqlalchemy already has this awareness, how can access it/leverage
  it for my application?
  -joe


 




-- 
_i__'simplicity_is_the_key'__tomasz_nazar
_ii'i_am_concern_oriented'JKM-UPR
_iii__'patsystem.sf.net'___linux_user
_'aspectized.com'___prevayler

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



Bug about substitution of _ (gettext) in 'Error Traceback' console

2007-11-22 Thread Tomasz Nazar

I think I have found some strange behaviour in Pylons and it is repeatable.
It is related to _ (gettext) function and having debug sessions with
nice Pylons 'Error Traceback' console

How to repeat:

1) request /testing/debug which raises exception on purpose
code:
class TestingController(MyBaseController):
def debug(self):
raise debugging_console_in_browser()


1a) use the console to inspect some variables.
code:
request.cookies
in my case it gives:
 request.cookies
{'portal': '55da4a783da7a244abe0258bc769fdeb8c997d6274ddde81afe285239fb5e441'}

2) request another valid page which uses i18n gettext in Mako
template, i.e ${_('hello')} and this page
should not throw any error

2b) this page will raise exception saying - depending on one's
inspections of variables in previous request:
- exceptions.TypeError: 'dict' object is not callable
- or: exceptions.TypeError: 'unicode' object is not callable
- or a list is not callable
- etc...

2c) Stacktrace (in case with showing 'request.cookies' variable in
console in 1st request):
File '.../project/controllers/testing.py', line 8 in i18n
  return render('/testing/i18n.tmpl')
File 
'/usr/lib/python2.4/site-packages/Pylons-0.9.6.1-py2.4.egg/pylons/templating.py',
line 343 in render
  format=format, namespace=kargs, **cache_args)
File 
'/usr/lib/python2.4/site-packages/Pylons-0.9.6.1-py2.4.egg/pylons/templating.py',
line 227 in render
  return engine_config['engine'].render(namespace, template=full_path,
File 
'/usr/lib/python2.4/site-packages/Mako-0.1.9-py2.4.egg/mako/ext/turbogears.py',
line 49 in render
  return template.render(**info)
File '/usr/lib/python2.4/site-packages/Mako-0.1.9-py2.4.egg/mako/template.py',
line 114 in render
  return runtime._render(self, self.callable_, args, data)
File '/usr/lib/python2.4/site-packages/Mako-0.1.9-py2.4.egg/mako/runtime.py',
line 287 in _render
  _render_context(template, callable_, context, *args,
**_kwargs_for_callable(callable_, data))
File '/usr/lib/python2.4/site-packages/Mako-0.1.9-py2.4.egg/mako/runtime.py',
line 304 in _render_context
  _exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
File '/usr/lib/python2.4/site-packages/Mako-0.1.9-py2.4.egg/mako/runtime.py',
line 337 in _exec_template
  callable_(context, *args, **kwargs)
File '/.../project/data/templates/base.tmpl.py', line 83 in render_body
  context.write(unicode(self.default_content()))
File '/usr/lib/python2.4/site-packages/Mako-0.1.9-py2.4.egg/mako/runtime.py',
line 193 in lambda
  return lambda *args, **kwargs:callable_(self.context, *args, **kwargs)
File '/.../project/data/templates/base.tmpl.py', line 207 in
render_default_content
  context.write(unicode(next.body()))
File '/usr/lib/python2.4/site-packages/Mako-0.1.9-py2.4.egg/mako/runtime.py',
line 193 in lambda
  return lambda *args, **kwargs:callable_(self.context, *args, **kwargs)
File '.../project/data/templates/testing/i18n.tmpl.py', line 57 in render_body
  context.write(unicode(_('hello')))
TypeError: 'dict' object is not callable


2d) when printing _ in current console it says!:
 _
{'portal': '55da4a783da7a244abe0258bc769fdeb8c997d6274ddde81afe285239fb5e441'}

WHAT IS IN FACT a variable inspected in 1st request
but should be gettext function


3) so it looks that _ was substituted to whatever I have last used in
previous request's debug session's console

!?

4) now all requests using _ in templates will fail
5) rm -rf data/templates/* data/sessions/* helps

;)

-- 
_i__'simplicity_is_the_key'__tomasz_nazar
_ii'i_am_concern_oriented'JKM-UPR
_iii__'patsystem.sf.net'___linux_user
_'aspectized.com'___prevayler

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



Reloading on changes to i18N *.po/*.mo files..

2007-11-08 Thread Tomasz Nazar

Hi there!

I'd really like, that when changing translations (localized
i18n/**/*.po/mo files) pylons/paster are reloaded with newly, updated
texts.
(similar like changes to templates, public files are instantly visible).

Is it possible?

And btw, is it possible to get rid of PO-to-MO-compilation step? Or
can it be done on the fly somehow?

Thanks - Tomasz



-- 
  _i__'simplicity_is_the_key'__tomasz_nazar
_ii'i_am_concern_oriented'JKM-UPR
_iii__'patsystem.sf.net'___linux_user
_'aspectized.com'___prevayler

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



Re: Pylons 0.9.6.1 + nosetests: No Translator object registered for this thread

2007-10-10 Thread Tomasz Nazar
Hmmm. Sounds odd. I had similar issues
http://groups.google.com/group/pylons-discuss/browse_thread/thread/a292b60bf24ce4b6/8b73ea6501c641eb?lnk=gstq=nosernum=6#8b73ea6501c641eb

But they are all gone after upgrade to 0.9.6.1/0.4 without any
setup.cfg configuration..

Some code snippets:
environment.py;
config['pylons.g'].sa_engine = engine_from_config(config,
'sqlalchemy.default.')

test_user.py:
from portal.models.domain import User,
class TestUser(WiBaseTest):

@transactional
def test_create_empty_user(self):
u = WiBaseTest.random_empty_user()
u2 = User()
my_session().save(u)
my_session().flush()
self.assertTrue(u.id)


setup.cfg is default one

I run tests with: nosetests tests/test_user.py

t.

On 10/10/07, Marek Stępniowski [EMAIL PROTECTED] wrote:
 I wanted to doctest my application (running on Pylons 0.9.6.1) with nose.

 I followed Ben Bangert advice in thread Testing models with SQLAchemy 0.4
 ( 
 http://groups.google.com/group/pylons-discuss/browse_thread/thread/2fa02ceb15bdf76d
 )
 but I got another ERROR:


 ERROR: test module lektury.controllers.catalogue in ...
 --
 Traceback (most recent call last):
   File c:\python25\lib\site-packages\nose-0.9.3-py2.5.egg\nose\suite.py,
 line 51, in run
 self.setUp()
   File c:\python25\lib\site-packages\nose-0.9.3-py2.5.egg\nose\suite.py,
 line 200, in setUp
 self.module = _import(self.moduleName, [self.path], self.conf)
   File c:\python25\lib\site-packages\nose-0.9.3-py2.5.egg\nose\importer.py,
 line 101, in _import
 mod = load_module(fqname, fh, filename, desc)
   File 
 C:\home\Projekty\Python\WolneLektury.pl\lektury\controllers\catalogue.py,
 line 5, in module
 from lektury.lib.choices import Choices
   File C:\home\Projekty\Python\WolneLektury.pl\lektury\lib\choices.py,
 line 11, in module
 N_('author') : _('author'),
   File 
 c:\python25\lib\site-packages\pylons-0.9.6.1-py2.5.egg\pylons\i18n\translation.py,
 line 105, in ugettext
 return pylons.translator.ugettext(value)
   File c:\python25\lib\site-packages\paste-1.4-py2.5.egg\paste\registry.py,
 line 125, in __getattr__
 return getattr(self._current_obj(), attr)
   File c:\python25\lib\site-packages\paste-1.4-py2.5.egg\paste\registry.py,
 line 182, in _current_obj
 'thread' % self.name__)
 TypeError: No object (name: Translator) has been registered for this thread


 Is there any way to register Translator object for a thread during
 testing? Or maybe there is another solution for this problem?


 --
 Marek Stępniowski
 email: [EMAIL PROTECTED] || [EMAIL PROTECTED]
 gg: 5354504

 



-- 
  _i__'simplicity_is_the_key'__tomasz_nazar
_ii'i_am_concern_oriented'JKM-UPR
_iii__'patsystem.sf.net'___linux_user
_'aspectized.com'___prevayler

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



Re: Pylons 0.9.5 + SAContext and nosetests gives additional warnings

2007-10-04 Thread Tomasz Nazar

I confirm that in 0.9.6, SQLAlchemy o.4b7 and nose 0.9.3 my tests (app
upgraded from 0.9.5) work like a charm  :-) [well, except these still
not green ;) ]
Thanks.

T.


On 9/26/07, Ben Bangert [EMAIL PROTECTED] wrote:
 On Sep 26, 2007, at 2:09 AM, Jim Musil wrote:

  This is probably too late, but I had the same problem.
 
  The problem is that tests are collected and tests/__init__.py runs
  before any configuration is loaded and therefore cannot be referenced.
  This makes it tough to test your db if you have connection variables
  set in your test.ini files. Or sqlalchemy, which is looking for
  configuration settings there.

 Pylons 0.9.6.1 in addition to including the security fix for private
 methods, will include a nose plugin that ensures the app is loaded
 before scanning for doctests. This way doc tests will work fine with
 your models.

 Cheers,
 Ben



-- 
  _i__'simplicity_is_the_key'__tomasz_nazar
_ii'i_am_concern_oriented'JKM-UPR
_iii__'patsystem.sf.net'___linux_user
_'aspectized.com'___prevayler

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



Re: mako in pylons: docs don't tell how to make caller.body() work

2007-09-20 Thread tomasz . nazar

I think there is sth wrong with your installation or sth else. It
works for my Pylons app w/o problems.

I also can have nested defs/calls. I do use namespaces...

My working examples: with Mako:
%def name=field(name)
tr
td style=white-space:nowrap;width:1%;
${name}
/td
td style=white-space:nowrap;width:98%;
${caller.body()}
/td
/tr
/%def

 %call expr=field('First (Given) Name')
input class=form-text validator-required
   id=first_name name=first_name
   title=First (Given) Name type=text
   value=${c.first_name}/
 /%call


Output:
 tr
td style=white-space:nowrap;width:1%;
First (Given) Name
/td
td style=white-space:nowrap;width:98%;

input class=form-text validator-required
   id=first_name name=first_name
   title=First (Given) Name type=text
   value=/

/td
/tr


On 9/17/07, wolf [EMAIL PROTECTED] wrote:


 hi all,

 today i tried to `%def`s and `%namespace`s in mako under pylons,
 and it so happened i found that the minimal example from the mako
 docs,

   %def name=buildtable() buffered=True
   table
   trtd
   ${caller.body()}
   /td/tr
   /table
   /%def

   %call expr=buildtable()
   I am the table body.
   /%call

 does not work inside a mako template rendered by pylons (nit: the
 actual code at
 http://www.makotemplates.org/docs/defs.html#defs_defswithcontent
 lacks the parentheses in the `%call` tag).

 turns out it's possible to have a reference to `caller.body()` under
 said circumstances *only* after saying   `
 %caller=context.get('caller')%` in the function definition, so under
 pylons the example becomes

   %def name=buildtable() buffered=True
   %caller=context.get('caller')%
   table
   trtd
   ${caller.body()}
   /td/tr
   /table
   /%def

   %call expr=buildtable()
   I am the table body.
   /%call

 it would just be great if this detail could make it into the docs.
 guess it was pure luck that i found the solution so quickly. or did i
 make some stupid mistake? i didn't find any postings concerned with
 exactly this problem, but someone should have been bitten by it
 earlier, no?

 _wolf


 



-- 
  _i__'simplicity_is_the_key'__tomasz_nazar
_ii'i_am_concern_oriented'JKM-UPR
_iii__'patsystem.sf.net'___linux_user
_'aspectized.com'___prevayler

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



accessing _action awith -action

2007-09-20 Thread Tomasz Nazar

Hi there!

In the controller I do have 'def _a(self):' action (private method really)
It's I think odd what is happening when I access it these ways:

http://localhost:5000/controller/_a , Result is good: Error 404 Not Found
http://localhost:5000/controller/.a , Result is good: 
exceptions.NotImplementedError: Action .a is not implemented 
http://localhost:5000/controller/-a , Result is not well: It actually
executed action! Is it on purpose? Does 'dash' have a special meaning
in the url.. ?


Tomasz




-- 
  _i__'simplicity_is_the_key'__tomasz_nazar
_ii'i_am_concern_oriented'JKM-UPR
_iii__'patsystem.sf.net'___linux_user
_'aspectized.com'___prevayler

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



Re: 'c' variable between redirects

2007-08-25 Thread Tomasz Nazar
On 8/25/07, Jose Galvez [EMAIL PROTECTED] wrote:



 Tomasz Nazar wrote:



 On 8/24/07, Christoph Haas [EMAIL PROTECTED] wrote:
 
 
   As I understand 'c' is always reset before any controller's action -
  what is
   not fun for me, as in my app one user request/click is often 2 (or
  more)
   Pylons controllers' actions, hence http redirects..
 
  Without knowing your application I dare say that this sounds like you
  are using redirect_to in the wrong places. If the application is
  supposed to do multiple things when a user does a certain HTTP request
  then why can't one controller's action do that alone?
 
  Christoph
 

 Simple said, because of the duplication of some parts of the code.


 Let's have this example from my app for discussion:

 Usecase 1: Go to Home Page - issues 'controller: home/home' - renders
 'home.mako'
 Usecase 2: Send email to a friend, and show Home Page - issues
 'controller: email/send', then redirects to 'controller: home/home' -
 renders ' home.mako'

 Of course 'home' action of controller 'home' does some specific logic,
 like showing current user's data from DB. That is a reason, I just can't
 show 'home.mako' in 'email/send' page after sending an email.

 And it is really bad to implement that logic twice in different places..

 Rather then using return redirect_to('home') in your email controller, why
 not just call home directly return self.home(), of course that assumes
 that home and email are in the same controller which they might not be, but
 you should be able to simply import what ever actions you need from waht
 ever controllers you you've already written.  Or did I miss something very
 fundamental in the the conversation?
 Jose



That is exactly what I was thinking of during writing my reply..  (see
below).
If it works I could like it..

Though I sometimes handle such situations by just _calling_ (not
 redirecting) 2nd action from a controller, only when 2 actions used are in
 the same controller.
 Hmm...however when I think about that now, I think I could also not to
 redirect, but could try to call 'home/home' action from another controller
 ('email') class/object.. could I? Can I access that object somehow?

 Tomasz


 



-- 
  _i__'simplicity_is_the_key'__tomasz_nazar
_ii'i_am_concern_oriented'JKM-UPR
_iii__'patsystem.sf.net'___linux_user
_'aspectized.com'___prevayler

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



'c' variable between redirects

2007-08-24 Thread Tomasz Nazar
Hi there!

Whatever variable attached to 'c', it is available in the template when
rendered via 'render_response('x.tmpl')'.

I often however use redirects 'h.redirect_to(another_action)' to reuse
controller's code. And the 'c'-attached variables are not present in the
redirected template.

As I understand 'c' is always reset before any controller's action - what is
not fun for me, as in my app one user request/click is often 2 (or more)
Pylons controllers' actions, hence http redirects..

What other options instead of putting variables to http session does one
have for passing variables through redirects?

T.

-- 
  _i__'simplicity_is_the_key'__tomasz_nazar
_ii'i_am_concern_oriented'JKM-UPR
_iii__'patsystem.sf.net'___linux_user
_'aspectized.com'___prevayler

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



Re: sqlalchemy is returning the wrong data

2007-08-08 Thread Tomasz Nazar
On 8/7/07, Mike Orr [EMAIL PROTECTED] wrote:


 On 8/6/07, jose [EMAIL PROTECTED] wrote:
  On a different note with my current setup (using extension=sac.ext) I
  thing that the explicit save (rec.save() from the example above) is
  not really necessary is it?

 No, sac.ext implicitly does the save for yoi.



.. and this becomes problem, when one doesn't want to do it. (at least
became for me)
I sometimes do not need each object created to be saved in DB
automagically..
I have deleted 'sac.ext' from my configuration and manage objects by hand
with `save(object)'





-- 
  _i__'simplicity_is_the_key'__tomasz_nazar
_ii'i_am_concern_oriented'JKM-UPR
_iii__'patsystem.sf.net'___linux_user
_'aspectized.com'___prevayler

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



Pylons 0.9.5 + SAContext and nosetests gives additional warnings

2007-08-03 Thread Tomasz Nazar

Hi there!

In short:
Using Pylons 0.9.5 + SQLAlchemy + SaContext
When running app or tests all is OK.
But after change from pylons.database to sacontext for each 'nosetests
test_*.py' I get a configuration error in addition: AttributeError:
No configuration has been registered for this process or thread (full
error below)


In long:
I am a new user to Pylons. I do not fully _yet_ understand the whole
framework, but yet in the project we have managed to implement some
quite nice functionality.
I started a month ago with Pylons 0.9.5 and are not willing to upgrade yet.
Nevertheless, initially I was using default pylons.database for
SQLAlchemy, but a week ago I have tried successfully SAContext with
0.9.5 and it works. No major problems overall.

But when I run 'nosetests' for any test, then the test runs fine - all
the SQLAlchemy objects are managed properly, transaction management,
sqla sessions cool - but I always get additional 2 errors for each one
test class (2 errors are the same). Here it is:

error
==
ERROR: test module yyy in F:\xxx\svn\trunk\portal\portal
--
Traceback (most recent call last):
  File 
c:\programy\python\python24\lib\site-packages\nose-0.9.2-py2.4.egg\nose\suite.py,
line 51, in run
self.setUp()
  File 
c:\programy\python\python24\lib\site-packages\nose-0.9.2-py2.4.egg\nose\suite.py,
line 200, in setUp
self.module = _import(self.moduleName, [self.path], self.conf)
  File 
c:\programy\python\python24\lib\site-packages\nose-0.9.2-py2.4.egg\nose\importer.py,
line 101, in _import
mod = load_module(fqname, fh, filename, desc)
  File F:\xxx\svn\trunk\portal\portal\models\__init__.py, line 10, in
 ?
sac.add_engine_from_config(None)
  File F:\xxx\svn\trunk\portal\portal\lib\sacontext.py, line 533, in
add_engine_from_configconfig_key)
  File F:\xxx\svn\trunk\portal\portal\lib\sacontext.py, line 578, in
parse_engine_optionsfor full_key in config.iterkeys():
  File 
c:\programy\python\python24\lib\site-packages\PasteDeploy-1.3.1-py2.4.egg\paste\deploy\config.py,
line 101, in __getattr__
raise AttributeError(
AttributeError: No configuration has been registered for this process or thread

--
Ran 1 test in 2.438s

FAILED (errors=2)
/error


Here is some details of configuration:
-Pylons-0.9.5-py2.4
-sqlalchemy-0.3.8-py2.4
-nose-0.9.2-py2.4
-Paste-1.4-py2.4
-PasteDeploy-1.3.1-py2.4

+ manually downloaded sacontext.py (0.3.3)

And part of my models/__init__.py:
#From 'SQLAlchemy for people in hurry'
import sqlalchemy as sqla
from sqlalchemy.orm import mapper
from portal.lib.sacontext import PylonsSAContext

sac = PylonsSAContext()
sac.add_engine_from_config(None)  # --- LINE 10

#All the businness classes are here..
from portal.models.domain import User

users_t = sqla.Table('users', sac.metadata, autoload=True)
#Etc...
mapper(User, user_t)
#Etc...


The are no modifications to Pylons base classes, configurations or whatever.
Just the necessary ones for using Mako.
config/* are almost original except routing.py,
lib/* the same..

Any ideas?


Tomasz Nazar


-- 
  _i__'simplicity_is_the_key'__tomasz_nazar
  _ii'i_am_concern_oriented'JKM-UPR
  _iii__'patsystem.sf.net'___linux_user
  _Heaven__Fellows,_PPP__prevayler

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