Re: how (Tosca)Widgets fits into MVC concept

2007-01-25 Thread Ksenia

Thanks for feedback! New google groups interface seems not to have
accepted my reaction from yesterday :( 
Just testing now...


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



Pagination research

2007-01-25 Thread Christoph Haas

Evening...

as some of you may have read on IRC I'm trying to use webhelpers' pagination
package. That's a pretty frustrating trip that's more a pydoc text adventure
than something that saves me more time than re-inventing the wheel. Anyway...

I'm using SQLAlchemy and have defined my Table()s in models/__init__.py. 
To use the pagination I used

  from webhelpers import pagination

in the lib/helpers.py.

Then in a controller I'm trying to paginate like this:

  domains_paginator, domain_set = \
h.pagination.paginate(
  model.session_context.current.query(model.DnsDomain),
  page=0,
  per_page=100
)
  set_count = int(domains_paginator.current)
  total_pages = len(domains_paginator)

While this works it looks very ugly to me. To get a paginable query object 
of my model I have to call 
model.session_context.current.query(model.DnsDomain).
E. So I used the source of webhelpers/pagination/orm.py and found out
that I can feed the webhelpers.pagination.paginate() function either

 - a Table object or
 - a Query object

Since the above query object was ugly I tried to feed the Table object directly:

  domains_paginator, domain_set = \
h.pagination.paginate(
  model.powerdns_domains_table,
  page=0,
  per_page=100
)
  set_count = int(domains_paginator.current)
  total_pages = len(domains_paginator)

This looks a lot cleaner but doesn't work. The traceback I get is:

File '/home/chaas/projekte/dnsdhcp/dnsdhcp/controllers/domains.py', line 12 in 
index
  domains_paginator, domain_set = 
h.pagination.paginate(model.powerdns_domains_table, page=0, per_page=100)
File 
'/usr/lib/python2.4/site-packages/WebHelpers-0.2.2-py2.4.egg/webhelpers/pagination/__init__.py',
 line 48 in paginate
  item_count = len(collection)
File 
'/usr/lib/python2.4/site-packages/WebHelpers-0.2.2-py2.4.egg/webhelpers/pagination/orm.py',
 line 56 in __len__
  return self.fn([func.count(1)], from_obj=[s])
NameError: global name 'func' is not defined

And at least in the webhelpers/pagination/orm.py there is no reference to
any 'func' object. Might this be a bug? Relevant part of the orm.py:

class SQLAlchemyLazyTable(Partial):
def __getitem__(self, key):
if not isinstance(key, slice):
raise Exception, SQLAlchemyLazy doesn't support getitem without 
slicing
limit = key.stop - key.start
offset = key.start
fn = self.fn
self.fn = fn.select
results = self(limit=limit, offset=offset).execute()
self.fn = fn
return results

def __len__(self):
s = self.fn.select(*self.args, **self.kw)
return self.fn([func.count(1)], from_obj=[s])   # --- bug?

Any other attempt to use a 'partial' (whatever that is) leads to the string
You shouldn't have this (which is not really a helpful error message).

It appears like paginate() should be able to accept an sqlalchemy.Query()
object (which in Pylons's context is
model.session_context.current.query(model.DnsDomain)) or an sqlalchemy.Table()
object (which in Pylon should mean a models.mymapper coming from 
assign_mapper()).

Wow, this email is pretty cryptic already. :) I hope someone has an idea on
how to use pagination correctly. Ben implied on IRC that the pagination stuff
could use a facelift. Any comments? Should I put this mail into a Trac ticket?
Does anyone have a good example on how to use pagination? The documentation at
http://pylonshq.com/WebHelpers/module-webhelpers.pagination.html is poor.
I'm willing to send in patches or anything. Just teach me how the holy thing
works. :) Thanks.

Kindly
 Christoph

--~--~-~--~~~---~--~~
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: UTF-8 ... help

2007-01-25 Thread MySZ

Hello,

I have similar problem.
I'm using Mako templates with sqlalchemy. In templates I have line:
# coding: utf-8
OK, I can put UTF-8 chars into templates. But I can't do:

${h.options_for_select(
(
(u'brudnopis', u'draft'),
(u'opublikowany', u'published'),
(u'usunięty', u'hidden')
), c.frm_status)}

or:

li class=${h.cond(h.current_page('/admin/news/list'), 'selected',
'')}${h.link_to_unless_current(u'Zarządzaj',
h.url(controller='admin_news', action='list'))}/a/li

or neither:

${asdą}

because it raise an exception:
type 'exceptions.UnicodeEncodeError': 'ascii' codec can't encode
character u'\u0119' in position 110: ordinal not in range(128)

selfcompiler.transformer.Transformer instance at 0x423bde2c
textuh.options_for_select(\n\t\t\t\t(\n\t\t\t\t\t(u'brudnopis',
u'draft'),\n\t\t\t\t\t(u'opublikowany',
u'published'),\n\t\t\t\t\t(u'usuni\u0119ty', u'hidden')\n\t\t\t\t),
c.frm_status)

or similar.

Of course, files are encoded in UTF-8, every file created by me have
line:
# -*- coding: utf-8 -*-
or similar, I use only unicode objects, etc etc.

MySZ

PS. How can I do persuade sqlalchemy in Pylons to use Unicode objects?
For now I hack [...]/Pylons[...]/pylons/database.py, line 42:
engine = sqlalchemy.create_engine(uri, echo=echo, convert_unicode=True,
encoding='utf-8')

Is any simpler method? Without this sqlalchemy doesn't work with
strings with non-ascii chars :/


--~--~-~--~~~---~--~~
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: how (Tosca)Widgets fits into MVC concept

2007-01-25 Thread Alberto Valverde


On Jan 25, 2007, at 12:42 PM, Ksenia wrote:




 On Jan 25, 11:31 am, Ksenia [EMAIL PROTECTED] wrote:
 Thanks for feedback! New google groups interface seems not to have
 accepted my reaction from yesterday :(
 Just testing now...

 (Ok, seems to work :)

 After reading al your helpfull reactions I see that my confusion with
 TG/TW widgets is more about it's implementation:
 - general widgets like TinyMCE, grids, js trees, select shuttle,  
 etc.
 belong to the concept of helpers. I dont care how they made, where
 they are installed on the system - I just want to use them. So the egg
 system and TW are great for that.
 - domain-specific widgets, like product info, is something that I see
 as a template that should be in the products view directory.  It makes
 more sense to me to see those widgets as clever templates with some
 extra python code in it. TW/TG widgets feels upside down for this
 use.

 Just the matter of taste I guess.

Of course. It's up to you to decide which views are general enough  
to deserve encapsulation in a reusable component or could benefit  
from being clever templates (being clever meaning they know what  
static resources (js, css, images...) they need for rendering and  
pull them automatically when they're used in a page).

But keep in mind, TW widgets are a superset of form widgets. Depends  
on your taste and style but widgets can be used for other things  
apart from validation (a js drop-down menu, for example). From a  
user's perspective they're just objects you can instantiate setting  
some initial state that affects how they behave and then be call them  
in a template to generate a chunk of markup. To sum up: they are  
equivalent of a template function but that can take care pulling  
static files and be encapsulated with all it's baggage into a  
reusable component. TW is just an API to create them, in fact,  
twForms ATM is more of a proof of concept which provides *very* basic  
widgets,  they could be much enhanced with client-side scripting,  
styling, etc...

Alberto



--~--~-~--~~~---~--~~
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: Another XMLHttpRequest question

2007-01-25 Thread Bob Ippolito

function () { ... } is the definition of an anonymous function. Like a
lambda in python.

On 1/25/07, Markm [EMAIL PROTECTED] wrote:

 Hi Uwe
 I am just begining here ... do you mind if I see that your complete (I
 mean your controller and defs) code? For eg, I did not understand this
 piece of code:

 xhr.onreadystatechange = function()

 What is this function() ??

 I'm fighting with the same problem and it'll be very useful if I could
 learn with you!

 Thanks in advance.
 Marcus


 On 5 jan, 22:48, Uwe Feldtmann [EMAIL PROTECTED] wrote:
  Robert Leftwich wrote:..snip That should be *onreadystatechange* not 
  onreadystatechage, i.e. there
   is a missing n in change.Isn't peer programming wonderful.  Thanks Robert.
  I've been looking at that code all day and just couldn't see the typo.
  New glasses needed perhaps.
 
  It's all working now thanks.


 


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



When does controllers/template/view get called?

2007-01-25 Thread Skip Montanaro

I modified controllers/template/view to

def view(self, url):
raise TypeError, url
print  sys.stderr, url
return render_response(/%s.myt % url)

If I visit (for example) http://localhost:5001/nonexistent I don't see
anything like a TypeError.  Instead, I get this traceback:

URL: http://localhost:5001/nonexistent
File
'/Users/skip/local/lib/python2.6/site-packages/Pylons-0.9.4.1-py2.6.egg/pylons/error.py',
line 226 in respond
  app_iter = self.application(environ, detect_start_response)
File
'/Users/skip/local/lib/python2.6/site-packages/Paste-1.1.1-py2.6.egg/paste/httpexceptions.py',
line 622 in __call__
  self.send_http_response, catch=HTTPException)
File
'/Users/skip/local/lib/python2.6/site-packages/Paste-1.1.1-py2.6.egg/paste/wsgilib.py',
line 226 in catch_errors_app
  app_iter = application(environ, start_response)
File
'/Users/skip/local/lib/python2.6/site-packages/PasteDeploy-1.1-py2.6.egg/paste/deploy/config.py',
line 161 in __call__
  app_iter = self.application(environ, start_response)
File
'/Users/skip/local/lib/python2.6/site-packages/Pylons-0.9.4.1-py2.6.egg/pylons/wsgiapp.py',
line 263 in __call__
  return self.app(environ, start_response)
File
'/Users/skip/local/lib/python2.6/site-packages/Beaker-0.6.2-py2.6.egg/beaker/cache.py',
line 124 in __call__
  return self.app(environ, start_response)
File
'/Users/skip/local/lib/python2.6/site-packages/Beaker-0.6.2-py2.6.egg/beaker/session.py',
line 105 in __call__
  response = self.wrap_app(environ, session_start_response)
File
'/Users/skip/local/lib/python2.6/site-packages/Routes-1.6.2-py2.6.egg/routes/middleware.py',
line 76 in __call__
  return self.app(environ, start_response)
File
'/Users/skip/local/lib/python2.6/site-packages/Pylons-0.9.4.1-py2.6.egg/pylons/wsgiapp.py',
line 92 in __call__
  raise Exception, No content returned by controller: %s %
controller.__name__
Exception: No content returned by controller: TemplateController

Where am I going wrong?

Thx,

Skip


--~--~-~--~~~---~--~~
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: Another XMLHttpRequest question

2007-01-25 Thread Uwe Feldtmann

Markm wrote:
 I am just begining here ... do you mind if I see that your complete (I
 mean your controller and defs) code? For eg, I did not understand this
 piece of code:

 I'm fighting with the same problem and it'll be very useful if I could
 learn with you!

Hi Markus.

I see that Bob Ippolito has already explained the function() { ... } 
definition  - thanks Bob.

Most of the code I used was only to test out sending data back and forth 
between the server and the browser without using html forms and would be 
more confusing than it's worth so I'll sum up what I've learned from 
experimentation and with the patient assistance of others on this list 
(thank you all).  If anything here is incorrect or could be done better 
then please let us all know.

Simple rules I read somewhere:-
Use GET if the data you are sending to the server is less than 512 bytes 
and can be sent on the url.
Use the POST method if the data is more than 512 bytes or needs to be 
more secure.

---

Sending from the browser using GET:-

function toServerByGET(url, fct) {
xmlhttp = new XMLHttpRequest();

xmlhttp.onreadystatechange = function() {
if ( xmlhttp.readyState==4 ) {
   fct( xmlhttp.responseText );
}
};

xmlhttp.open(GET,url);
xmlhttp.send(null);
}

and is called like this

urlAndData = /controllerName/methodName/?parm1= + value1 + 
amp;parm2= + value2;
toServer( urlAndData, responseHandler )

---

Sending from the browser using POST:-

function toServerByPOST( url, data, fct ) {
   xmlhttp = new XMLHttpRequest();

   xmlhttp.open( POST, url, true );

   // note setRequestHeader must appear after .open and is used
   // to encode the data as though it came from a form (thanks Robert)
   xmlhttp.setRequestHeader( Content-Type, 
application/x-www-form-urlencoded );

   xmlhttp.onreadystatechange = function() {
if ( xmlhttp.readyState==4 ) {
fct( xmlhttp.responseText );
}
   }

   xmlhttp.send( data ); 
};

and is called like this

var data = {
id: 1,
parm1: value1
parm2: value2
}
toServerByPOST( /controllerName/methodName, data, responseHandler );

---

The method in the controller is the same in both instances:-

class ControllerNameController(BaseController):
  
def methodName(self):
value1 = request.params['parm1']
value2 = request.params['parm2']

return Response( responseData )

---

Hope this helps in some way.

Uwe.


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