Are there any examples (beyond the test suite) of pyactiveresource in
use?
Specifically, I'm wondering if we are supposed to create an instance
of ActiveRecord to maintain connection state, and if people generally
subclass ActiveRecord to keep application-specific state? That is,
create a hierarchy like:
ActiveRecord -> MyApplication -> Resource
Where MyApplication has application specific state and class methods.
Example: I have a multi-tenant application that requires username,
password and domain to log in. So I create a class method to set all
three parameters:
class MyApplication(ActiveRecord):
@classmethod
def set_login(cls, user_=None, pass_=None, domain_=None):
cls.set_user(user_)
cls.set_password(pass_)
cls._domain = domain_
The reason I ask all this, is that the call to ActiveRecord.set_user()
is an instance method, whereas I'm calling it from a class method.
This gets interesting when I want to override set_user() -- which
makes me wonder if I should be instantiating MyApplication.
Not sure if you can follow all that or not -- but some real-world
examples of the library in use would be very helpful.
Cheers,
Cameron
given this hierarchy:
>>> class MyAppBase(activeresource.ActiveResource):
... _site = 'http://fakedomain'
...
>>> class Foo(MyAppBase):
... pass
...
>>> class Bar(MyAppBase):
... pass
...
Each of these classes have the same connection object.
>>> id(Foo.connection)
12823312
>>> id(Bar.connection)
12823312
>>> id(MyAppBase.connection)
12823312
Setting the user on the top-level of the hierarchy sets the attribute
on the connection object, so that is also shared:
>>> MyAppBase.set_user('mrroach')
>>> MyAppBase.connection.user
'mrroach'
>>> Bar.connection.user
'mrroach'
so, the short version of all that is that I think you are doing the
right thing in your example and you don't need an instance to set the
user or password.
Does that help at all?
-Mark
> --
> You received this message because you are subscribed to the Google Groups "pyactiveresource" group.
> To post to this group, send email to pyactive...@googlegroups.com.
> To unsubscribe from this group, send email to pyactiveresour...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/pyactiveresource?hl=en.
>
>