Use different wagtail page as root without slug - python

I'm attempting to set a page as the root home page of my wagtail based site.
I know you can set the homepage using the sites setting. But, my use case is different.
I'm using a "redirect" page which redirects to an index page as the homepage. The index is restricted to only allow ertain page types (since it's an index....). But, this causes issues with other pages not being in the tree if it was set at the root.
Hence, the redirect. But, upon redirecting the serve view of the redirect page to use this page it picks up the slug.
I still want it to appear at the root url. Meaning, /. How can I achieve this?
High level description:
from django.shortcuts import redirect
class IndexPage(Page):
# children restricted to IndexSubpage
class IndexSubpage(Page):
# parent restricted to IndexPage
class RedirectPage(Page):
def serve(request):
# Link is a link to a page through a ForeignKey....
return redirect(self.link, permanent=True)
So, this will pick up the slug of IndexPage instead of being at /

Related

Managing django urls

I am making a personal site. I have a blog page(site.com/blog), where I have a list of my blog posts. If I want to check a blog post simple enough I can click it and the code:
<h1>{{ obj.topic_title }}</h1>
will get me there. Also if I want to go to my contacts page (site.com/contacts). Easy enough I click nav contacs button and I go there
Contacts
but if I enter a blog post (site.com/blog/1), I am using the same template and if I want to go to my contacts page I have to yet again click the
Contacts
link, but that will port me to a 404 page site.com/blog/contacts . How do I deal with this problem without harcoding every single page
Use the built-in Django url template tag, which takes the view name and returns an absolute path to it.
Returns an absolute path reference (a URL without the domain name) matching a given view and optional parameters.
You can give it a view name and any of its view parameters as well. This is much better than how you link to the blog page:
{% url 'blog-view-name' obj.id %}
This ensures that if you ever change the structure of your views, it will still not break your links.

How to point blog to menu item in Mezzanine?

How do you point blogs to a menu item in Mezzanine? I am able to point my blogs to Home using urls.py but how about to page types like link and richtextpage?
Add a rich text page, call it Blog or however you want, then in meta data group, in the field URL add /blog/ or whichever is the url to the main blog app. Mezzanine will match the url with the page and will add the Page object to the rendering context, so you can use it in templates.

django-stronghold not using next parameter for redirecting

I'm not sure whether this is a problem with django-stronghold or with django itself.
What happens:
Calling any front end URL (e.g. http://www.myapp.com/careers) leads me to the login page
The URL shown looks like this: http://www.myapp.com/accounts/login/?next=/careers
Upon login, I am forwarded to the admin interface (like when logging in at http://www.myapp.com/admin)
The displayed URL is still http://www.myapp.com/accounts/login/?next=/careers
What I want:
Upon login, I want to be forwarded to the URL called originally, as correctly stored in the next parameter (in the example: http://www.myapp.com/careers)
My setup:
I'm using Django 1.6.
As suggested in the docs, I have installed django-stronghold via pip and activated it in my project like so:
INSTALLED_APPS = (
...
'stronghold', # last entry
)
MIDDLEWARE_CLASSES = [
...
'stronghold.middleware.LoginRequiredMiddleware', # last entry
]
At first, I ran into a redirect loop, so I defined the STRONGHOLD_PUBLIC_URLS:
STRONGHOLD_PUBLIC_URLS = (
r'^/admin.*?$', # Don't touch the admin pages
r'^/accounts/login/$', # Avoid redirect loop
)
What I tried:
Explicitly setting LOGIN_URL and LOGIN_REDIRECT_URL, as suggested here - didn't help.
In the context of logging into the admin interface, django's login mechanism works fine, just like it is documented here:
Here’s what django.contrib.auth.views.login does:
If called via GET, it displays a login form that POSTs to the same URL. [...]
If called via POST with user submitted credentials, it tries to log the user in. If login is successful, the view redirects to the URL specified in next. [...]
If I call an admin URL other than .../admin (e.g. http://www.myapp.com/admin/myapp_base/event/), the displayed URL remains the same while the login form is shown (no next parameter). After logging in, I see the requested page.
Ideas?
Any ideas why the redirect isn't working for the front end URLs?

Viewing a django-cms page via the slug

How do you view a published django-cms page using a path that incorporates the slug?
I installed django-cms without error, and I can view the default cms homepage just fine. I created and published a simple "About" page with the slug "about", but when I visit http://localhost:8000/about/ I get a 404 error. I can see the page if I use the "View on site" button, but that takes me to http://localhost:8000/?preview=1&language=en, not the real published path.
What am I doing wrong?
you won't get access until you check the published in cms page list view in admin.
View on site help with a preview before page is published.
After digging through the code, I discovered that django-cms doesn't actually expose pages via their slug unless they're created UNDER a home page. The code that looks up a page via their slug looks in the cms_title table, and it stores '' for the slug for any page that's not a child. Very unintuitive, but after I re-created the page under a "Home" page, I could then access it via the /about/ page.

django: restrict url reachable only from one view

i'm new in Django.
I have a form once filled i keep the datas and redirect to another page, but i notice if i put the correct url i can access to this second page without passing by the first form.
here is my urls:
urlpatterns = patterns('',
url(r'newworkflow/$','access_mgmt.views.newworkflowform'),
url(r'newrole/$','access_mgmt.views.newrole'),
)
So if in my browser url i put /newrole i get the page but i want to have access to it only if the form on the first page "/newworkflow/ is filled.
Is it possible to restrict the access to the second page only if the first form page is filled?
Only by recording somewhere - say in the session - that the user has completed page1, and checking that in the view for page2.

Categories

Resources