durusmail: quixote-users: Building a community
Building a community
2003-01-02
2003-01-02
2003-01-02
2003-01-02
2003-01-02
2003-01-04
2003-01-04
Building a community
Neil Schemenauer
2003-01-02
On Thu, Jan 02, 2003 at 05:15:23PM -0500, Tom Jenkins wrote:
> ah i was thinking along different lines.  i have a database connection,
> should i :
> - have a db connection instance in a module that everybody imports?
> - do i subclass Publisher (say) and add get_dbconn() so you can do
> get_publisher().get_dbconn()?
> - do i throw the db connection into request and grab it from there?
> - something else which i can't think of?

I don't see any advantage in attaching it to the publisher or request
object.  For global shared objects we use a function, something like
"from myapp.database import get_dbconn".  If you are sure your
application will never be multi-threaded you could just use a module
global.  A function seems to be more flexible though.

> please note, these are off the cuff and may be stupid.  Now I can sit
> and analyze them and conclude that the first one is probably the best
> way.  or i could be wrong.  it might not be a best practice in quixote.

The nice thing about Quixote is that questions like this are usually
questions about programming in Python rather than about using Quixote
(at least IMHO).

> but i wouldn't know simply because there isn't anything in place to
> facilitate communication.

Hmm, I thought the communication was flowing quite well.  What's wrong
with quixote-users@mems-exchange.org?  I think most Quixote experts hang
out here, the list is public and archived.  I think you can even read it
from Gmane.

> now how about this scenario:  I have a Department that has a list of
> Agencies.  In some AgencyUI we need some information from Department.
> The url is myapp/department/1/agency/5/showSomeInfo.  In Zope we'd use
> acquisition to call the right methods from the department to which the
> specific agency belongs (well actually in zope the above would be a pita
> to get right).  To paraphrase Jim Fulton, "acquisition is cool, until it
> isn't".  How do I handle it here?

I think I would do something like this:

    # myapp.department module

    class DepartmentUI:
        def __init__(self, component):
            self.department = get_department(component) # careful with input!

        def agency(self, request):
            return AgencyUI(self.department, component)

    def _q_getname(request, component):
        return DepartmentUI(component)

    class AgencyUI:
        def __init__(self, department):
            self.department = department
            self.agency = None

        def _q_getname(self, request, component):
            self.agency = get_agency(self.department, component)
            return self # or something else

        def showSomeInfo(self, request):
            ...

That's a little rough but hopefully enough to give you the idea.  The
key idea is that DepartmentUI passes the department object to AgencyUI.

> my original post was not so much a "hey can somebody answer this" type
> of post.  it was meant to be more of a "what i would love to see is more
> ways to communicate, to build the community, is there someplace i'm
> missing where snippets, scripts, hints, lessons learned, traps, etc are
> stored" type of message.

I realized that.  My response was a subtle attempt to indicate that
quixote-users is a pretty good place to discuss using Quixote.  Having a
community supported site would be cool but I suspect the community is
not large enough yet to support one.

  Neil

reply