Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for plugins to register URL patterns #1237

Merged
merged 9 commits into from
Aug 19, 2013

Conversation

mitar
Copy link
Contributor

@mitar mitar commented Jun 2, 2012

New pull request for #738. Hopefully this time not in the time of feature freeze.

@ojii
Copy link
Contributor

ojii commented Jun 2, 2012

isn't this what apphooks are for?

@mitar
Copy link
Contributor Author

mitar commented Jun 2, 2012

No. This is for plugins. For example, I have a markup plugin for Django CMS which renders previews when user is editing the plugin content in Django CMS. So it has to have some views accessible from users. By using API in this pull request, it can publish such views under /admin/ prefix. So this is just for plugins to be used when editing them.

@digi604
Copy link
Contributor

digi604 commented Jun 7, 2012

tests please

@fivethreeo
Copy link
Contributor

also should be just a classmethod

@digi604
Copy link
Contributor

digi604 commented Mar 28, 2013

i want this for 3.0

@digi604
Copy link
Contributor

digi604 commented Jul 10, 2013

@mitar do you want to give this an other go?

@mitar
Copy link
Contributor Author

mitar commented Jul 10, 2013

@digi604 What do you mean?

@digi604
Copy link
Contributor

digi604 commented Jul 10, 2013

I still like the idea... and with some tests i might include it in 3.0

@mitar
Copy link
Contributor Author

mitar commented Jul 10, 2013

Against which branch should I do it?

@digi604
Copy link
Contributor

digi604 commented Jul 11, 2013

develop

@mitar
Copy link
Contributor Author

mitar commented Jul 18, 2013

Rebased to current develop branch and added tests. But tests do not really work because plugin should be registered before Django urls are constructed. In a similar way Django admin solves this (with autodiscovery). So in my code I just made sure that plugins were loaded from admin autodiscovery. I am not sure what could be a solution to this.


def get_patterns(self):
# We want untranslated name of the plugin for its slug so we deactivate translation
lang = get_language()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think you should call: self.discover_plugins() here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And how will this find plugins in tests?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can do a overwrite settings and add something to installed apps... or add the plugin in cms/plugin_utils/cli.py to the INSTALLED_APPS

@mitar
Copy link
Contributor Author

mitar commented Jul 18, 2013

Fixed. :-) I used my own API wrong. :-) I had get_plugin_url instead of get_plugin_urls.

@digi604
Copy link
Contributor

digi604 commented Jul 19, 2013

could you check python 3.3 support? The tests fail for that.

@mitar
Copy link
Contributor Author

mitar commented Jul 19, 2013

Fixed. It fails now on some other test on Django 1.5, not affected with this pull request.

@yakky
Copy link
Member

yakky commented Jul 19, 2013

Travis still flaky... after restart all the tests passed

@mitar
Copy link
Contributor Author

mitar commented Jul 19, 2013

Great!

url_patterns = []
for plugin in self.get_all_plugins():
p = plugin()
slug = slugify(force_unicode(p.name))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plugin name is not guaranteed to be unique, probably the plugin class name would be a better option here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And plugin class is unique?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there some other "verbose name" available?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plugin class name is unique in the project (it's the registration key in the plugin pool)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there already some function which makes nice verbose name from the class name?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope.

@mitar
Copy link
Contributor Author

mitar commented Jul 21, 2013

Fixed.

.. method:: get_plugin_urls(instance)

Returns URL patterns for which the plugin wants to register views for.
They are included under Django CMS PageAdmin in the plugin path
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit-picking: django CMS not Django CMS :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What? I didn't know that. But Django is Django? And django CMS is django CMS? Strange.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Fixed.)

@mitar
Copy link
Contributor Author

mitar commented Jul 28, 2013

Fixed.

@yakky
Copy link
Member

yakky commented Jul 28, 2013

LGTM

@yakky
Copy link
Member

yakky commented Aug 17, 2013

Sorry @mitar, it remained unmerged and a further rebase is needed against develop.
Would you do that? I'll merge it as soon as it's rebased.

@ghost ghost assigned yakky Aug 17, 2013
@mitar
Copy link
Contributor Author

mitar commented Aug 19, 2013

@yakky: Done.

yakky added a commit that referenced this pull request Aug 19, 2013
Support for plugins to register URL patterns
@yakky yakky merged commit cf643b5 into django-cms:develop Aug 19, 2013
@yakky
Copy link
Member

yakky commented Aug 19, 2013

@mitar thanks! it took a while but it landed at last :-)

@digi604
Copy link
Contributor

digi604 commented Aug 19, 2013

yep thanks @mitar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants