Django: Change pagination style - pagination

I am using pagination on my view by adding paginate_by something like this:
class ProductView(ListView):
model = Product
template_name = "product_table.html"
paginate_by = PAGE_SIZE
It generates a paging element that appears as follows on the page:
I want to customize this paging element to make it more useful. Maybe something more like this:
How do I override the default paging style?

This django doc has the code to get the page_obj into the context. It also shows how to use the has_next property, so you would use that to see if there are a few more pages to show. Alternatively, you could just simplify your html and calculate # pages len(object_list)/PAGE_SIZE and then pass the list of page links in the context.

Related

Display pagination number on page title

Currently, I have an issue about display pagination title in Shopware, template use Twig, load pagination pages by ajax, multi languages use snippet.
Detail:
The pagination title that need to be displayed: Page "X". X is page number.
The site used multi languages site, ex: english (Page "X"), german (Seite "X") ...
For default url (ex: abc.com/category-name) or page = 1 (ex: abc.com/category-name/?p=1): Not display pagination title.
For other pages (page 2, 3, 4): Display Page 2 ...
Page items will be loaded by use ajax when click the page number.
So, I don't know what to do display the pagination title on page title with multi languages.
Can everyone help me to resolve this issue?
Thank everyone.
You can hook into this method:
ListingPaginationPlugin.onChangePage (see the source code in vendor/shopware/storefront/Resources/app/storefront/src/plugin/listing/listing-pagination.plugin.js)
And after calling the parent method, insert - for a proof of concept - code like this:
document.title = event.target.value;
This would simply show the page number in the title (but losing the original title)
I suggest you back-up the original title and just append the "Page X" / "Seite X" information to it according to your necessary logic.
Now you need the translated word for "Page" available in the Javascript code.
You could attach this as a data-attribute to the title tag in the according twig template and use the normal `|trans' filter. I am not sure if there is a better way to have translations available in Javascript code in Shopware, so I asked.

Using Django paginator with nested templates with different number of displays

I am working with Django Paginator to set up my list view. In my default list view I've used "paginate_by=12" and then I need to show links with drop down to paginate by 20 and all. The list view includes Grid View and List View templates. I am including the templates with grid and list view but I can't control pagination with different numbers. Simply I am using a single view and including multiple templates for that list view...but how to use different paginator size in different tempaltes when I've set it as paginate_by=20 in my class based list view.
View:
class ProductListView(ListView):
model = Product
paginate_by = 10
I tried using {% include 'listview30.html' paginate_by=30 %} but it didn't worked. How to use multiple pagination with a single list view.
Kindly advise.
I found the solution at https://pypi.python.org/pypi/django-pagination. I've tested it on different pages and it is working fine for me.

What's currently the best way to pass data from a given content item to a variable Form in Orchard

I have a product package with several options in my Orchard site and I need users to be able to send an enquire based on a single option:
I've seen out there many articles about Tokens, Dynamic Forms (the examples using Dynamic Forms seem to be just for a single form type), I can think of many ways to achieve this but I don't know what is really the cleanest and fastest way to implement this functionality.
I would need a hint on what to keep researching to speed this up.
Thank you in advance
In your view, I'd wrap the button around an <a> tag something like this:
<a href="#(String.Format("/{0}/{1}", "x", y))" target="_blank">
//put button code or whatever here
</a>
Where 'x' is the extended url and y could be the query string such as: www.google.com/game/q=2
When you do this and get the redirect correct, in your driver for the page, you can get the page number from the url using something like this:
private readonly IHttpContextAccessor _httpContextAccessor;
var httpContext = _httpContextAccessor.Current();
var query = httpContext.Request.QueryString["q"];

nodejs + jade, can we render partial views as we do in ASP.NET?

how can we easily render partial views in JADE using the model-view pattern like this: (pseudocode)
response.render('view', model)
and inside view we have
foreach element in model
render('_elementPartial', element)
or JADE doesnt support partial views this way?
actually i fixed this, didnt know we dont have to pass parameters if we are within same scope
so
if we do something like:
p #{someVariable}
include _partial.jade
we can also use #{someVariable} from within _partial.jade

Orchard query content items in my custom controller

The title pretty much sums it up. I created my own module in Orchard. I can access its actions via http requests like an ordinary controller in any MVC application.
I generated the controller using the command line interface and it came with IOrchardServices property that is populated in the constructor.
On my Orchard site I have a blog which I filled up with about 40 blog posts.
How can I query these blog posts from within my controller?
First I would like to start by saying: "read the source luke". You may find Orchard lacking in documentation and examples, but because it is open source, pretty much everything you want to know can be found there.
You should use the BlogPostService, inject that into your controller to get the blog posts you want.
https://orchard.codeplex.com/SourceControl/latest#src/Orchard.Web/Modules/Orchard.Blogs/Services/BlogPostService.cs
You can see it being used in several controllers within Orchard.Blogs:
https://orchard.codeplex.com/SourceControl/latest#src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogPostController.cs
https://orchard.codeplex.com/SourceControl/latest#src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogAdminController.cs
Check out the code in the BlogPostService to see how it works, it is a little confusing because blogs are content items with blog posts underneath them. If you want to learn about simpler querying of content items I would check out how the BlogService works, it is a little easier to get to grips with:
https://orchard.codeplex.com/SourceControl/latest#src/Orchard.Web/Modules/Orchard.Blogs/Services/BlogService.cs
Here is an example of what I was looking for:
var query = Services.ContentManager.Query();
var list = query.ForType(new []{"BlogPost"}).List();
var result = new List<dynamic>();
foreach (var contentItem in list) {
result.Add(new
{
title = contentItem.As<TitlePart>().Title, // dynamically typed: ((dynamic)contentItem).TitlePart.Title
text = contentItem.As<BodyPart>().Text
});
}

Resources