Chris has recommended storing stuff in the view, and the
Pyramid/Pylons guide I'm working on will document it as an alternative
to t'mpl_context'.
===
class MyViewClass(object):
def __init__(self, request):
self.request = request
self.variable_for_site_template = "value"
# The above variable is used only in HTML rendering; it's not
part of the view's return dict for JSON, etc.
@view_config(route_name="...", renderer="...")
def index(self):
return {"project": "Hello"}
# Site template
<head>
<meta name="keywords" content="${view.variable_for_site_template}" />
...
# Index template
<p>Welcome to ${project}.</p>
</head>
===
> def _shared_setup_a():
> "used by one or more methods , but not all"
> self.db = newdb()
> self.gaq= new_google_analaytics()
This looks reasonable. It's essentially what I do in Pylons, and what
I'd do in Pyramid. I like this approach for processing common input
such as record IDs: the method validates the parameter type (numeric),
fetches the database record, and attaches it to 'self', or aborts the
request if the record doesn't exist.
--
Mike Orr <slugg...@gmail.com>
Handlers are views too. So this works there as well, if you'd rather
continue using those.
- C
Chris, Blaise, something to think about for the documentation:
People are getting the idea that handlers are some big separate thing;
i.e., more than they are. I think this is due to how pyramid_handlers
was originally marketed. Part of it I think was an expectation that
ex-Pylons developers wouldn't accept the standard Pyramid API, whereas
actual experience has shown that they're more accepting of it than we
thought.
So in my Pyramid/Pylons guide (and in the Akhet manual) I've tried to
emphasize that a handler is just another name for a view class (i.e.,
a class containing view methods). What pyramid_handlers really gives
you is config.add_handler() and @action. It doesn't give you a base
class: that's an Akhet invention (to parallel Pylons' Base
controller). So I think that where the docs talk about view classes,
they should mention that handler is a common term for a view class,
but it means nothing more than that, and that pyramid_handlers is just
one way of managing them.
--
Mike Orr <slugg...@gmail.com>
--
You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
To post to this group, send email to pylons-...@googlegroups.com.
To unsubscribe from this group, send email to pylons-discus...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.
I also use the Pylon-esque context object pattern to make a globally
accessible "c.attrib" object available in my templates.
I also use this, mostly for the session's user object which I cache into
redis.
Mike Orr <slugg...@gmail.com> writes:
--
Parnell "ixmatus" Springmeyer (http://ixmat.us)
I'd hope it'd be enough to put somewhere in the handlers docs that
handlers are just special class-based views. I'm not apt to introduce
the term "handlers" into the main Pyramid docs to describe class-based
views, because then we don't have a name for the bundle of logic that we
currently call handlers.
- C
>
> --
> Mike Orr <slugg...@gmail.com>
>
Ben explicitly didn't want them to be called controllers for fear of
people getting them confused with Pylons controllers, which work
slightly differently, FWIW.
- C
Renaming pyramid_handlers would raise backward compatibility issues,
and there's already a proliferation of things being renamed and
retired.
I'm just suggesting a sentence in passing, "Class-based views are
sometimes called 'handlers'", so that users know what that term means
and won't misunderstand it.
--
Mike Orr <slugg...@gmail.com>
--
You received this message because you are subscribed to the Google Groups "pylons-discuss" group.