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

Howto to integrate django-page-cms with another app with custom url #129

Closed
iopsthecloud opened this issue Dec 30, 2015 · 6 comments
Closed

Comments

@iopsthecloud
Copy link

My goal is to manage some pages of our website using django-page-cms.

To do it here is my workflow:

  • declare in settings file the HTML file as template using PAGE_TEMPLATE
  • adding some placeholder to the HTML template
  • create a page using this template and filled the corresponding placeholder

Now where I'm lost is how rendering my page. I read the docs, but from my understanding I can call the corresponding pages using the URL http:///pages/

In my case I wanna manage the URL like I do usually in my urls.py, per example as root document ("/") or for another page with the URL http:///gallery but I didn't find howto do it.

I tried to create my own view:

class Homepage(TemplateView):
    template_name  = 'template.html'

and in my urls.py I do as usual:

url(r'^$', Homepage.as_view())

But using this approach permit me to render the template, but not to show the placeholders. I have to use the templatetags {% showcontent...... %} to show the contents because {% placeholder "xxxx" as data %} doesn't work :(

I'm sure that I'm not doing the right way, but I don't see where I'm wrong.

@batiste
Copy link
Owner

batiste commented Dec 30, 2015

You have 3 options:

  • Let the CMS main view do the URL handling. The CMS use the slug of the page to resolve automatically every page URLs
  • Let the CMS handle the URLs but delegate the rendering using your own view. Here is the documentation explaining how to do that: http://django-page-cms.readthedocs.org/en/latest/3rd-party-apps.html
  • You handle the URL yourself and use your own view. You should be able to do that without problems. All you need to do for all the templatetags to work properly is to make sure the context variables are present.

In this last case be sure to set those variables properly in your views:

  • current_page the page object,
  • lang the current language,
  • pages_navigation the list of pages used to render navigation.

@batiste batiste closed this as completed Jan 6, 2016
@9dogs
Copy link

9dogs commented Feb 26, 2016

I got a similar question about integration. My intention is to use django-page-cms for managing mostly-static content while using custom views for dynamic content. For example, I got "person detail" view which displays profile pages for users on site. Now I want to render profile page and use pages_breadcrumb template tag. pages_breadcrumb takes either page object or id to display proper ancestors. Of course, I can't have a page object for every user so I use a following hack:
I create a hidden page in a proper place of navigation tree, then refer this page in pages_breadcrumb tag in my user_profile template. I also provide current_page (the hidden one) and lang context objects in my view. It works fine, but current_page title in breadcrumbs is the same for every user while I want it to be a username. Breadcrumbs use {% show_content page "title" %} and I failed to find a proper multi-language way to change it and not breaking cms-manages pages. I wonder is there any proper way of doing it?

@batiste
Copy link
Owner

batiste commented Feb 27, 2016

@9dogs it is hard to understand what you want to do exactly...

But here are a few remarks:

  1. Nothing wrong with using a hidden page if you need one. But you could also imagine using this mechanism https://pythonhosted.org/django-page-cms/3rd-party-apps.html#delegate-the-rendering-of-a-page-to-an-application
  2. pages_breadcrumb was designed to display pages Object from the CMS. If your need are too specific (like displaying user name) most of the template tags will not work.
  3. Why do you even try to use {% show_content page "title" %} to display a user name? Can't you use {% user.name %} ? Maybe a bit of template inheritance could help there?

Breadcrumbs use {% show_content page "title" %} and I failed to find a proper multi-language way to change it and not breaking cms-manages pages

I don't understand what is the problem here... The CMS is multilingual by default so I don't understand how that doesn't work.

I think I starting to understand your need somehow... You want the navigation templates to be decoupled from Pages themselves? For now this CMS doesn't handle things this way... All the navigation templates are assuming a Page hierarchy. But nothing should stop you from developing your own custom tailored template tags. For example the code for the breadcrumb is very simple:

https://github.com/batiste/django-page-cms/blob/master/pages/templatetags/pages_tags.py#L238

Why not developing you own and adding your specific use case? e.g. {% user_profile_breadcrumb %}?
Would you rather have some kind of framework to integrate other models into the navigation templates?

@9dogs
Copy link

9dogs commented Feb 27, 2016

@batiste sorry for obscure description and thanks for the answer! Basically I want to place my own views in Pages navigation mechanism in some consistent way. But you are right, custom template tag/template should do the trick.

Would you rather have some kind of framework to integrate other models into the navigation templates?

It would be great if not at the expense of simplicity and clean design. Django-cms has similar functionality but it will devour any site in no time :).

@batiste batiste reopened this Feb 28, 2016
@batiste
Copy link
Owner

batiste commented Feb 28, 2016

@9dogs not that django-page-cms try to have the exact same feature than than Django-CMS, but this navigation abstraction is very simple and could implemented rather easily... Do you want to give it a try?

I might have some time in the next month and give a try a as well.

@batiste
Copy link
Owner

batiste commented Feb 28, 2016

@9dogs after reading the whole doc on Django-CMS I realised how complex the implementation is... I wonder if there is a sweet spot in implementing something a lot simpler but that provide just enough flexibility to do what you need to do.

@batiste batiste closed this as completed Jul 25, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants