How to create page hierarchy in Odoo? - python

In Odoo, pages are created with url /page/page-name and basically it creates a template with id website.page-name and going to /page/website.page-name redirects to /page/page-name.
I need to create a page category with subpages and have the url look like /category-name/subpage-name (e.g. example-website.com/films/sherlock). Is this possible without having to define a web controller that renders the page? Is it possible to map /page/category-name.subpage-name to /category-name/subpage-name?

Related

How do i send the data of a form (retrieved from a function of an HTML page) to a function of another HTML page in Django/Python?

The sequence is:
- The user fills the 'a' form in the 'A' HTML page.(URL: AppName/A)
- The user is directed to 'B' HTML page with other forms to fill.(URL: AppName/A/B)
In the python code,
How do i send the data of the 'a' form (retrieved from the function corresponding to the 'A' HTML page) to the function corresponding to the 'B' HTML page in views.py ?
Notes:
I do not want to retrieve the data from the 'A' HTML page in the 'B'HTML page but in the function corresponding to the 'B' HTML page as the user goes from 'A' to 'B' HTML page.
Thank you.
You can use sessions or database to store form states (form data) for user.
Sessions
How to use sessions in Django official Doc
Django Sessions by mozilla
Database
Models according to your forms to store form data and also maintain form no which form is filled or not.
Render both forms
Render both form in same template and do what you want.

How can I redirect to a new page after submitting a form using Jinja template?

I'm working my way through Google's App Engine Guestbook example (to be found here: https://cloud.google.com/appengine/docs/standard/python/getting-started/creating-guestbook)
I'm trying to redirect the output (the Greetings) to another page as opposed to the index.html where they're currently displayed after a user presses the "Sign the Guestbook" button. I created a separate page called greetings.html where I copied the display code from the index.html page. However, I don't know how to modify guestbook.py to make the output go to the new page.
webapp2 has a built-in redirect method:
return redirect('/some-path')
However, I think you would probably rather send the gathered data to the greetings.html template? Under the POST method, you could do:
template_values = {
'guestbook_name': guestbook_name,
# etc.,
}
template = JINJA_ENVIRONMENT.get_template('greetings.html')
self.response.write(template.render(template_values))

Wagail one page with different content

I am new to Wagtail and python, so could apprectiate some help with my problem.
I have a web app (wagtail web site + rest api backend).
On my website I have 2 pages:
HomePage with list of accessible objects (e.g. photos)
PhotoPage with a detailed information on photo
What I want to achive:
When I click on photo on homepage I am redirected to the photopage
I fill the photopage with information I got from backend
And the photopage url is smth like this http://example.com/photo?id=12345
So, I want to
have 1 model for photopage
fill photopage based on a requested url (i.e. from homepage I redirect user to example.com/photo?id=12345 and it is filled with information on photo with id=12345)
I guess there should be some middleware to parse requested url to get the id and fill the page with info from API. Is there any standard solution to this issue?
Page objects (and any classes that inherit from Page) have a get_context method that can be used to add context pre-rendering of your templates.
from django.shortcuts import get_object_or_404
class PhotoPage(Page):
# your model definition ...
def get_context(self, request):
context = super(PhotoPage, self).get_context(request)
photo_pk = request.GET.get('id',None)
photo = get_object_or_404(YourPhotoModel,pk=photo_pk) # if no matching photo, return 404. You can do whatever you like instead :)
context['photo'] = photo
return context
Now in your photo template you can access your Photo model instance directly...
{{ photo.some_attribute }}
{{ photo.some_other_attribute }}

How can i remove the GET parameters from url in django

I have the form which i am showing by normal view. Then i am send the GET parameters to djnago ChangeList view like django does for lookups like this
student/?region__id__exact=1&status__exact=Published
now is there any way to remove that from the URL in the address bar.
I don't users to see what i am doing
The whole point of GET is that they are retrieved from the URL itself, removing them from the URL removes them entirely.
If you want them 'hidden' you will need to use POST.
The HTTP GET method of form submission passes the information from template to views through URL. If you want to "hide" information from URL use POST instead. In your form do like this:
<form action="/view_name/" method="post">
and in views:
request.POST['name']

How to alter the URI in django?

http://packages.python.org/django_simple_feedback/ref/request-response.html tells that the absolute URI is built using the server variables available in this request. So, How can I alter the URI using HttpRequest.build_absolute_uri.
My situation is:
/foo/bar/2/ is the url having corresponding view load_view(request) Before rendering the template I want to alter the URI by attaching the new absolute URI in the request. So, that My templte renders on the URL /foo/.
You can use django.shortcuts.redirect to redirect to a different location:
def load_view(request):
return redirect('/foo/')
You will still need a corresponding view setup for that url, of course, as this will cause the user's browser to redirect to /foo/. If you want to change the url without refreshing the page, you can do this with HTML5 now:
window.history.pushState('','foo','/foo/');

Categories