Using Kotti side-by-side with another Pyramid app

300 views
Skip to first unread message

Andreas Jung

unread,
Nov 4, 2012, 10:21:54 AM11/4/12
to ko...@googlegroups.com
Hi there,

here is my scenario: I am currently rewriting the produce-and-publish.com website
using Pyramid where the main part of the application is already implemented
with some views and interactive features using Twitter Bootstrap. Now I want to maintain
some editorial content through a CMS (Kotti) and aggregate the content in order to show it up
inside my own main application.

Is 


the right way using Kotti as a "secondary" application besides my own "primary" application?

If yes then I have a slightly problem with the pipeline configuration. I get the following error

sucmac:pp-demo ajung$ ../bin/pserve development.ini 
Traceback (most recent call last):
  File "../bin/pserve", line 8, in <module>
    load_entry_point('pyramid==1.4a3', 'console_scripts', 'pserve')()
  File "/Users/ajung/sandboxes/pp-demo/lib/python2.6/site-packages/pyramid/scripts/pserve.py", line 47, in main
    return command.run()
  File "/Users/ajung/sandboxes/pp-demo/lib/python2.6/site-packages/pyramid/scripts/pserve.py", line 290, in run
    relative_to=base, global_conf=vars)
  File "/Users/ajung/sandboxes/pp-demo/lib/python2.6/site-packages/pyramid/scripts/pserve.py", line 318, in loadapp
    return loadapp(app_spec, name=name, relative_to=relative_to, **kw)
  File "/Users/ajung/sandboxes/pp-demo/lib/python2.6/site-packages/paste/deploy/loadwsgi.py", line 247, in loadapp
    return loadobj(APP, uri, name=name, **kw)
  File "/Users/ajung/sandboxes/pp-demo/lib/python2.6/site-packages/paste/deploy/loadwsgi.py", line 271, in loadobj
    global_conf=global_conf)
  File "/Users/ajung/sandboxes/pp-demo/lib/python2.6/site-packages/paste/deploy/loadwsgi.py", line 296, in loadcontext
    global_conf=global_conf)
  File "/Users/ajung/sandboxes/pp-demo/lib/python2.6/site-packages/paste/deploy/loadwsgi.py", line 320, in _loadconfig
    return loader.get_context(object_type, name, global_conf)
  File "/Users/ajung/sandboxes/pp-demo/lib/python2.6/site-packages/paste/deploy/loadwsgi.py", line 408, in get_context
    object_type, name=name)
  File "/Users/ajung/sandboxes/pp-demo/lib/python2.6/site-packages/paste/deploy/loadwsgi.py", line 594, in find_config_section
    self.filename))
LookupError: Ambiguous section names ['app:main', 'pipeline:main'] for section 'main' (prefixed by 'app' or 'application' or 'composite' or 'composit' or 'pipeline' or 'filter-app') found in config /Users/ajung/sandboxes/pp-demo/pp-demo/development.ini

My .ini files looks like this:

ucmac:pp-demo ajung$ cat development.ini 
###
# app configuration
###

[app:main]
use = egg:pp-demo

pyramid.reload_templates = true
pyramid.debug_authorization = false
pyramid.debug_notfound = false
pyramid.debug_routematch = false
pyramid.default_locale_name = en
pyramid.includes = 
#    pyramid_debugtoolbar

# By default, the toolbar only appears for clients from IP addresses
# '127.0.0.1' and '::1'.
# debugtoolbar.hosts = 127.0.0.1 ::1


[app:myapp]
use = egg:myapp
pyramid.includes = pyramid_tm
mail.default_sender = yourname@yourhost
sqlalchemy.url = sqlite:///%(here)s/myapp.db
kotti.secret = secret

[filter:fanstatic]
use = egg:fanstatic#fanstatic

###
# wsgi server configuration
###

[server:main]
use = egg:waitress#main
host = 0.0.0.0
port = 6547

[pipeline:main]
pipeline =
    fanstatic
    myapp

###
# logging configuration
###

[loggers]
keys = root, ppdemo

[handlers]
keys = console

[formatters]
keys = generic

[logger_root]
level = INFO
handlers = console

[logger_ppdemo]
level = DEBUG
handlers =
qualname = ppdemo

[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic

[formatter_generic]
format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s

Is there anything I am missing or am I on the wrong trail? Or is there a better way
integration two different Pyramid applications into one? What I don't want is using 
Kotti as a "primary" app and rewriting my own code in order to make it work with Kotti.



Andreas

Daniel Nouri

unread,
Nov 4, 2012, 12:34:15 PM11/4/12
to ko...@googlegroups.com, Andreas Jung
Hi Andreas,

On 11/04/2012 04:21 PM, Andreas Jung wrote:
> Hi there,
>
> here is my scenario: I am currently rewriting the
> produce-and-publish.com website
> using Pyramid where the main part of the application is already implemented
> with some views and interactive features using Twitter Bootstrap. Now I
> want to maintain
> some editorial content through a CMS (Kotti) and aggregate the content
> in order to show it up
> inside my own main application.
>
> Is
>
> http://kotti.readthedocs.org/en/latest/developing/as-a-library.html
>
> the right way using Kotti as a "secondary" application besides my own
> "primary" application?

The right way of using Kotti as a separate WSGI app completely would
be to use something like Paste#urlmap [1], so the two apps would map
to different URLs. (Your app might map to /, Kotti to /cms.)

You should then be able to pull content from Kotti using
kotti.DBSession and display it in your app.

Using the 'as-a-library' approach that you link to is really
equivalent to writing a Kotti add-on (but having a little more
control), so it's not what you want apparently.

[1] http://pythonpaste.org/deploy/#composite-applications
The problem with your specific configuration is that it defines two
"main" entry points for the app: "[app:main]" and "[filter:main]". If
you were to use a single app and integrate with Kotti (which you say
you want to avoid), you'd merge your "[app:main]" and "[app:myapp]"
into one.

But using Paste#urlmap, as discussed above, your configuration should
look something like this:

[composite:main]
use = egg:Paste#urlmap
/ = pp
/cms = kotti

[app:pp]
use = egg:pp-demo
# ... Your app's configuration

[pipline:kotti]
pipeline =
fanstatic
kotti-app

[filter:fanstatic]
use = egg:fanstatic#fanstatic

[app:kotti-app]
use = egg:kotti
# ... Kotti configuration

# ... and then [server:main] and the rest ...



Daniel

filtered

unread,
Nov 5, 2012, 3:55:48 AM11/5/12
to Daniel Nouri, ko...@googlegroups.com

Using the urlmap approach seems to the right path but there is still one thing missing.

I am get to the "Welcome to Kotti" page through /cms but I can not get to the Login page which is /wired
to /edit. 

My configuration is:

[composite:main]
use = egg:Paste#urlmap
/ = mainapp
/cms = kotti


[app:mainapp]
use = egg:pp-demo

pyramid.reload_templates = true
pyramid.debug_authorization = false
pyramid.debug_notfound = false
pyramid.debug_routematch = false
pyramid.default_locale_name = en
pyramid.includes = 


[app:kotti]
use = egg:kotti
sqlalchemy.url = sqlite:///%(here)s/Kotti.db
#mail.default_sender = yourname@yourhost
kotti.configurators = kotti_tinymce.kotti_configure
kotti.site_title = My Kotti site
kotti.secret = qwerty

#[filter:fanstatic]
#use = egg:fanstatic#fanstatic

#[pipeline:main]
#pipeline =
#   fanstatic
#  kotti

[server:main]
use = egg:waitress#main
host = 0.0.0.0
port = 6548


and the initialization code is:

from pyramid.config import Configurator

default_settings = {
    'pyramid.includes': 'myapp myapp.views',
    'kotti.authn_policy_factory': 'myapp.authn_policy_factory',
    'kotti.base_includes': (
        'kotti kotti.views kotti.views.login kotti.views.users'),
    'kotti.use_tables': 'orders principals',
    'kotti.populators': 'myapp.resources.populate',
    'kotti.principals_factory': 'myapp.security.Principals',
    'kotti.root_factory': 'myapp.resources.Root',
    'kotti.site_title': 'Myapp',
}



def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    settings2 = default_settings.copy()
    settings2.update(settings) 
    config = Configurator(settings=settings2)
    config.add_static_view('static', 'static', cache_max_age=3600)
    config.include('pyramid_mailer')
    config.add_route('home', '/')
    config.scan()
    return config.make_wsgi_app()

What is missing here?

Andreas

2012/11/4 Daniel Nouri <daniel...@gmail.com>

Nuno Teixeira

unread,
Nov 5, 2012, 7:35:26 AM11/5/12
to ko...@googlegroups.com
Hi Andreas!

What do you mean about not getting the login page? Are you refering to
'login' button on the "Welcome to Kotti" page itself?
If so then that is an hard coded link that is editable. There you'll
need to modify it to '/cms/edit'

Nuno

Daniel Nouri

unread,
Nov 5, 2012, 10:22:22 AM11/5/12
to filtered, ko...@googlegroups.com
On 11/05/2012 09:55 AM, filtered wrote:
>
> Using the urlmap approach seems to the right path but there is still one
> thing missing.
>
> I am get to the "Welcome to Kotti" page through /cms but I can not get
> to the Login page which is /wired
> to /edit.

That "Login" link was wrongly pointing to an absolute path. I've
fixed it here:


https://github.com/Pylons/Kotti/commit/973949b6bd24449d25f027b062d35e4aad36befe

Note that this is just the sample initial page though, so you can hit
"edit" and fix the link yourself. (Or remove the page altogether.)
You can always go to the log in by appending /edit to any URL.

I've also found a related bug with the "brand" link that pointed to
"/" instead of ${application_url}. Fixed here:


https://github.com/Pylons/Kotti/commit/273f6a35e2a12798696ceb1bfda93d5849f68c14


Daniel

filtered

unread,
Nov 5, 2012, 11:59:04 AM11/5/12
to Daniel Nouri, ko...@googlegroups.com
Thanks...one last thing....the Kotti pages have not styles.

My configuration is (copied from the Kotti checkout):

[composite:main]
use = egg:Paste#urlmap
/ = mainapp
/cms = kotti


[app:mainapp]
use = egg:pp-demo

pyramid.reload_templates = true
pyramid.debug_authorization = false
pyramid.debug_notfound = false
pyramid.debug_routematch = false
pyramid.default_locale_name = en
pyramid.includes = 


[app:kotti]
use = egg:kotti
sqlalchemy.url = sqlite:///%(here)s/Kotti.db
#mail.default_sender = yourname@yourhost
kotti.configurators = kotti_tinymce.kotti_configure
kotti.site_title = My Kotti site
kotti.secret = qwerty

[filter:fanstatic]
use = egg:fanstatic#fanstatic
#
[pipeline:main]
pipeline =
    fanstatic
    kotti

[server:main]
use = egg:waitress#main
host = 0.0.0.0
port = 6548


The [pipeline:main] does not seem to work with my setup:

LookupError: Ambiguous section names ['composite:main', 'pipeline:main'] for section 'main' (prefixed by 'app' or 'application' or 'composite' or 'composit' or 'pipeline' or 'filter-app') found in config /Users/ajung/sandboxes/zopyx.pyramid.ppdemo/development.ini

What must be fixed here?

Andreas



2012/11/5 Daniel Nouri <daniel...@gmail.com>

Nuno Teixeira

unread,
Nov 5, 2012, 1:31:02 PM11/5/12
to ko...@googlegroups.com
Hey Andreas!

From Paster docs you may use ``filter-with`` configuration variable.

So instead of ``pipeline:main`` section you should add the following
option inside ``app:kotti`` section:

filter-with = fanstatic

I've tested it by defining a single kotti app on ``composite:main`` but
I'm not sure if it collides with your app.

Nuno

Daniel Nouri

unread,
Nov 5, 2012, 2:52:28 PM11/5/12
to filtered, Kotti mailing list
You need to rename the pipeline to something else. 'main' (the main
entry point) is already taken by 'composite'.

Try renaming [app:kotti] to [app:kottiapp], and rename [pipeline:main]
to [pipeline:kotti]. Inside of [pipeline:kotti], refer to 'fanstatic'
and 'kottiapp' (instead of 'kotti').

This should work if everyone plays nice (fanstatic?). The
[composite:main] will point /cms to the pipeline including fanstatic,
instead of merely the Kotti WSGI app.

Daniel

filtered

unread,
Nov 6, 2012, 1:24:49 AM11/6/12
to Daniel Nouri, Kotti mailing list
The styles still do not show up.

Codes base:


WSGI configuration:


Is there something in the configuration code to be added for Kotti?


I promise to document this integration of Kotti with a different application
when I got it working :-)

Andreas







2012/11/5 Daniel Nouri <daniel...@gmail.com>
On Mon, Nov 5, 2012 at 5:59 PM, filtered <zopyx...@gmail.com> wrote:

Andreas Kaiser

unread,
Nov 6, 2012, 3:16:43 AM11/6/12
to ko...@googlegroups.com
Hi Andreas,


On 06.11.2012, at 07:24, filtered <zopyx...@gmail.com> wrote:

> The styles still do not show up.
>
> Codes base:
>
> https://github.com/zopyx/zopyx.pyramid.ppdemo
>
> WSGI configuration:
>
> https://github.com/zopyx/zopyx.pyramid.ppdemo/blob/master/development.ini
>
> Is there something in the configuration code to be added for Kotti?
>
> https://github.com/zopyx/zopyx.pyramid.ppdemo/blob/master/ppdemo/__init__.py
>
> I promise to document this integration of Kotti with a different application
> when I got it working :-)

fair enough. ;-)

I cloned your repo, only added the line mentioned by Nuno before and
have styles working as expected. The complete config now looks like
this (only relevant lines):

--------8<--------schnipp--------8<--------
[composite:main]
use = egg:Paste#urlmap
/ = mainapp
/cms = kottiapp

[app:mainapp]
use = egg:pp-demo

[app:kottiapp]
use = egg:kotti
sqlalchemy.url = sqlite:///%(here)s/Kotti.db
kotti.configurators = kotti_tinymce.kotti_configure
kotti.site_title = My Kotti site
kotti.secret = qwerty
filter-with = fanstatic

[filter:fanstatic]
use = egg:fanstatic#fanstatic

[pipeline:kotti]
pipeline =
fanstatic
kottiapp

[server:main]
use = egg:waitress#main
host = 0.0.0.0
port = 6548
--------8<--------schnapp--------8<--------

HTH,
> --
>
>

Andreas Kaiser

unread,
Nov 6, 2012, 3:21:32 AM11/6/12
to ko...@googlegroups.com
Followup: you can even drop the complete [pipeline:kotti] section when
using the filter-with config option.

Andreas
> --
>
>

Andreas Kaiser

unread,
Nov 6, 2012, 3:28:13 AM11/6/12
to ko...@googlegroups.com
An alternative approach could be to reference the [pipeline:kotti]
section in your urlmap (instead of [app:kottiapp]):

[composite:main]
use = egg:Paste#urlmap
/ = mainapp
/cms = kotti

Sorry for the noise - I should have completed my research before
sending the answer to the list in first place…

Andreas


On 06.11.2012, at 09:21, Andreas Kaiser <di...@binary-punks.com> wrote:

> Followup: you can even drop the complete [pipeline:kotti] section when
> using the filter-with config option.
>
> --
>
>

Daniel Nouri

unread,
Nov 6, 2012, 3:28:14 AM11/6/12
to Kotti mailing list
True. Or you point [composite:main] to the pipeline ('kotti') and not
to the app ('kottiapp'), which is what I tried to say:

[composite:main]
use = egg:Paste#urlmap
/ = mainapp
/cms = kotti

Important to include fanstatic one way or the other.

That said, filter-with seems more compact. I guess we should change
our standard INIs to use it.
> --
>
>



--
http://danielnouri.org
Reply all
Reply to author
Forward
0 new messages