plugin or subpage in tg ?

0 views
Skip to first unread message

Lukasz Szybalski

unread,
Jul 23, 2008, 5:03:23 PM7/23/08
to TurboGears
Hello,
I am building separate part of the website which has its own
controller/model,templates,

localhost/mysubapp/index

The file structure is similar to tg registration:

/myapp/

-controller.py
-model.py
--\mysubapp
----controller.py
----model.py

I initiate my mysubapp controller in main controller.py like this:

class Root(controllers.RootController):
registration = reg_controllers.UserRegistration()
mysubapp = mysubapp_controllers.mysubappRoot()

I have a custom predicate in my first controller.py, how can I
reference it from the subapp controller.py?

@identity.require(is_in_my_group())

gives me:
File "/home/xxx/xturbogears/myapp/myapp/mysubapp/controllers.py",
line 69, in mysubappRoot
@expose(template="myapp.templates.mysubapp.view")
NameError: name 'is_in_my_group' is not defined

Do I use Super() to reference files from main controller.py?? or??

Thanks,
Lucas

Patrick Lewis

unread,
Jul 23, 2008, 10:13:06 PM7/23/08
to TurboGears


On Jul 23, 5:03 pm, "Lukasz Szybalski" <szybal...@gmail.com> wrote:

>
> @identity.require(is_in_my_group())
>
> gives me:
>  File "/home/xxx/xturbogears/myapp/myapp/mysubapp/controllers.py",
> line 69, in mysubappRoot
>     @expose(template="myapp.templates.mysubapp.view")
> NameError: name 'is_in_my_group' is not defined
>

how are you importing this?

If it's like:
from myapp.controller import is_in_my_group

@identity.require(is_in_my_group())

I would expect it to work.

Lukasz Szybalski

unread,
Jul 24, 2008, 10:01:37 AM7/24/08
to turbo...@googlegroups.com
On Wed, Jul 23, 2008 at 9:13 PM, Patrick Lewis <patric...@gmail.com> wrote:
>
>
>
> On Jul 23, 5:03 pm, "Lukasz Szybalski" <szybal...@gmail.com> wrote:
>
>>
>> @identity.require(is_in_my_group())
>>
>> gives me:
>> File "/home/xxx/xturbogears/myapp/myapp/mysubapp/controllers.py",
>> line 69, in mysubappRoot
>> @expose(template="myapp.templates.mysubapp.view")
>> NameError: name 'is_in_my_group' is not defined
>>
>
> how are you importing this?
>
> If it's like:
> from myapp.controllers import is_in_my_group

I don't know why but this is not working.
Traceback (most recent call last):
File "start-myapp.py", line 15, in ?
start()
File "/home/lucas/turbogears/myapp/myapp/commands.py", line 52, in start
from myapp.controllers import Root
File "/home/lucas/turbogears/myapp/myapp/controllers.py", line 16, in ?
from myapp.mysubapp import controllers as mysubapp_controllers
File "/home/lucas/turbogears/myapp/myapp/mysubapp/controllers.py",
line 19, in ?
from myapp.controllers import is_in_my_group
ImportError: cannot import name is_in_my_group

The is_in_my_group is defined above the main root class in main
controller. What else am I missing here?

Lucas

Lukasz Szybalski

unread,
Jul 24, 2008, 12:18:46 PM7/24/08
to turbo...@googlegroups.com

It works if I take out the code and put it in separate file, and then
I add this line to main controller and the plugin controller.

from myapp.somefile import is_in_my_group

Then it works, but it doesn't work if I import it the "from
myapp.controllers import is_in_my_group" .
I guess somehow the from myapp.controllers gets confused with "from
myapp.mysubapp.controllers"

Lucas

Lukasz Szybalski

unread,
Jul 25, 2008, 10:06:48 AM7/25/08
to turbo...@googlegroups.com

I have to say that the tg-registration plugin style, of where you keep
files works pretty nice. I got my localhost/subpage/index working,
and it is so much easier to maintain.

Now If I could find an easy way to go from sqlalchemy records (updated
daily) to rss feed, with usernam/password for outsiders and no
authentication for inside people.

Lucas

Reply all
Reply to author
Forward
0 new messages