Overriding view declaration

61 views
Skip to first unread message

Thierry Florac

unread,
Feb 28, 2018, 5:50:16 AM2/28/18
to pylons-...@googlegroups.com
Hi,
I created a view in a first package.
In another package (which is an optional extension of the first one), I need to create another view but with the same name and the same settings as the previous one but with another class which inherits from the first one.
By default, this raises a "pyramid.exceptions.ConfigurationConflictError" exception: Conflicting configuration actions!
So how can I "override" or "replace" a view declaration? Eventually, can I "unregister" a view declaration before registering the new one?

Best regards,
T. Florac

Michael Merickel

unread,
Feb 28, 2018, 11:42:53 AM2/28/18
to Pylons
https://docs.pylonsproject.org/projects/pyramid/en/latest/narr/advconfig.html#automatic-conflict-resolution

Basically if each view is registered from some call within a config.include'd function then if you establish an appropriate include-chain then you can override one call from the other.

def include_orig(config):
    config.scan('.orig_pkg')

def include_override(config):
    config.include(include_orig)
    config.scan('.override_pkg')

def main(...):
    # do not config.include(include_orig) here, instead include the override
    # otherwise they would be siblings and thus no clear chain

    config.include(include_override)

Now pyramid will have a chain that says specifically that the override is "closer" to your main than orig and thus its directives should win.

- Michael


--
You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discuss+unsubscribe@googlegroups.com.
To post to this group, send email to pylons-discuss@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pylons-discuss/CAPX_VWDmDJKT5g3j8%3Dx7BW9mWuiYk1Z1rz9BTwzGxKy8Fxz2kA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Thierry Florac

unread,
Mar 1, 2018, 5:02:01 AM3/1/18
to pylons-...@googlegroups.com
Many thanks, it works perfectly !!

Best regards,
Thierry

To post to this group, send email to pylons-...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discuss+unsubscribe@googlegroups.com.
To post to this group, send email to pylons-discuss@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages