Adding new modules positions to OpenCart 3 - opencart

I am using OpenCart Version 3.0.2.
By default OpenCart has 4 areas where we can drop the modules in our layouts. i.e.
Left Column
Right Column
Top Content
Bottom Content
My question is if somehow we can drop modules elsewhere also or maybe if we can somehow call a module within the HTML-Module and wrap is with some HTML codes. Basically I am stuck with a design where I wanted to add few dynamic banners in the home page but to display them according to the design, they much be wrapped within row and than col-6 each since bootstrap is the framework I am using.
To elaborate my requirement I am writing sample HTML so that I can show where I wanted to add modules for the home page
<header></header>
<div id="home" class="row">
<div class="col-12"> Slideshow Module as "content top" </div>
<div class="col-6"> Big Banner Module </div>
<div class="col-6"> Few more Banners </div>
<div class="col-12"> Latest Products Module as "content Bottom" </div>
<div class="col-12"> Featured Products Module as "content Bottom" </div>
<div class="col-12"> HTML CONTENT Module as "content Bottom" </div>
</div>
<footer></footer>
There is a possibility that I can drop Big Banner Module and a few more Banners modules in left and right columns and a bit of jQuery to change the wrapping HTML of the columns from <aside id="column-left"> to <div class="col-6"> but this solution do not seems right and will effect the google crawling as well.
Would someone suggest a better way to add modules like this only for the home page?
A structure image in case if I am unable to explain the problem with HTML:

You need to create new position.
File:
admin/language/en-gb/design/layout.php
Find:
$_['text_content_bottom']
Add before it:
$_['text_content_new'] = 'Content New';
File:
admin/view/template/design/layout_form.twig
Find:
<table id="module-content-top" class="table table-striped table-bordered table-hover">
Add before it:
<table id="module-content-new" class="table table-striped table-bordered table-hover">
<thead>
<tr>
<td class="text-center">{{ text_content_new }}</td>
</tr>
</thead>
<tbody>
{% for layout_module in layout_modules %}
{% if layout_module.position == 'content_new' %}
<tr id="module-row{{ module_row }}">
<td class="text-left"><div class="input-group">
<select name="layout_module[{{ module_row }}][code]" class="form-control input-sm">
{% for extension in extensions %}
<optgroup label="{{ extension.name }}">
{% if not extension.module %}
{% if extension.code == layout_module.code %}
<option value="{{ extension.code }}" selected="selected">{{ extension.name }}</option>
{% else %}
<option value="{{ extension.code }}">{{ extension.name }}</option>
{% endif %}
{% else %}
{% for module in extension.module %}
{% if module.code == layout_module.code %}
<option value="{{ module.code }}" selected="selected">{{ module.name }}</option>
{% else %}
<option value="{{ module.code }}">{{ module.name }}</option>
{% endif %}
{% endfor %}
{% endif %}
</optgroup>
{% endfor %}
</select>
<input type="hidden" name="layout_module[{{ module_row }}][position]" value="{{ layout_module.position }}" />
<input type="hidden" name="layout_module[{{ module_row }}][sort_order]" value="{{ layout_module.sort_order }}" />
<div class="input-group-btn"> <i class="fa fa-pencil"></i>
<button type="button" onclick="$('#module-row{{ module_row }}').remove();" data-toggle="tooltip" title="{{ button_remove }}" class="btn btn-danger btn-sm"><i class="fa fa fa-minus-circle"></i></button>
</div>
</div></td>
</tr>
{% set module_row = module_row + 1 %}
{% endif %}
{% endfor %}
</tbody>
<tfoot>
<tr>
<td class="text-left"><div class="input-group">
<select class="form-control input-sm">
<option value=""></option>
{% for extension in extensions %}
<optgroup label="{{ extension.name }}">
{% if not extension.module %}
<option value="{{ extension.code }}">{{ extension.name }}</option>
{% else %}
{% for module in extension.module %}
<option value="{{ module.code }}">{{ module.name }}</option>
{% endfor %}
{% endif %}
</optgroup>
{% endfor %}
</select>
<div class="input-group-btn">
<button type="button" onclick="addModule('content-new');" data-toggle="tooltip" title="{{ button_module_add }}" class="btn btn-primary btn-sm"><i class="fa fa-plus-circle"></i></button>
</div>
</div></td>
</tr>
</tfoot>
</table>
Create the following file:
catalog/controller/common/content_new.php
it's content:
<?php
class ControllerCommonContentNew extends Controller {
public function index() {
$this->load->model('design/layout');
if (isset($this->request->get['route'])) {
$route = (string)$this->request->get['route'];
} else {
$route = 'common/home';
}
$layout_id = 0;
if ($route == 'product/category' && isset($this->request->get['path'])) {
$this->load->model('catalog/category');
$path = explode('_', (string)$this->request->get['path']);
$layout_id = $this->model_catalog_category->getCategoryLayoutId(end($path));
}
if ($route == 'product/product' && isset($this->request->get['product_id'])) {
$this->load->model('catalog/product');
$layout_id = $this->model_catalog_product->getProductLayoutId($this->request->get['product_id']);
}
if ($route == 'information/information' && isset($this->request->get['information_id'])) {
$this->load->model('catalog/information');
$layout_id = $this->model_catalog_information->getInformationLayoutId($this->request->get['information_id']);
}
if (!$layout_id) {
$layout_id = $this->model_design_layout->getLayout($route);
}
if (!$layout_id) {
$layout_id = $this->config->get('config_layout_id');
}
$this->load->model('setting/module');
$data['modules'] = array();
$modules = $this->model_design_layout->getLayoutModules($layout_id, 'content_new');
foreach ($modules as $module) {
$part = explode('.', $module['code']);
if (isset($part[0]) && $this->config->get('module_' . $part[0] . '_status')) {
$module_data = $this->load->controller('extension/module/' . $part[0]);
if ($module_data) {
$data['modules'][] = $module_data;
}
}
if (isset($part[1])) {
$setting_info = $this->model_setting_module->getModule($part[1]);
if ($setting_info && $setting_info['status']) {
$output = $this->load->controller('extension/module/' . $part[0], $setting_info);
if ($output) {
$data['modules'][] = $output;
}
}
}
}
return $this->load->view('common/content_new', $data);
}
}
Create the following file:
catalog/view/theme/default/template/common/content_new.twig
it's content:
{% for module in modules %}
{{ module }}
{% endfor %}
File:
catalog/controller/common/home.php
Find:
$data['content_top'] = $this->load->controller('common/content_top');
Add before it:
$data['content_new'] = $this->load->controller('common/content_new');
File:
catalog/view/theme/default/template/common/home.twig
Find:
{{ header }}
Add after it:
{{ content_new }}

#digitcart did a pretty decent answer, and for those who like videos, here is a video tutorial I did exactly for your case
https://dreamvention.com/blog/how-to-add-an-extra-position-in-opencart-header/
hope it helps.
Also, you can find an OCMOD that will do this for you and you can copy it to make more extra positions. pretty cool stuff
https://github.com/Dreamvention/youtube_files/tree/master/extra_position_1

Related

Django - how to access local audio files in different URL paths?

Thanks in advance for reading. I'm working on my final project for CS50W which involves working with a series of local audio files (user cannot upload additional files at this time). The issue occurs when I try to populate an src attribute with the file. I have two URL paths which deal with accessing these files: new/ and edit/int:id. When I access the audio files in new/, it works as intended and I can play the file from the tag. However, when I try to access the files in the edit/int:id path, I get this error:
GET http://localhost/edit/8/media/Aminor_Ipi3udk.mp3 net::ERR_ABORTED 404 (Not Found)
I am relatively new to coding (just did CS50x and then started CS50w) and I don't understand why I'm getting this error or how I can fix it - I'm doing the same thing for both paths and yet it only works in one of them. I would be grateful if someone could help me to remedy this or at least point me in the direction of understanding why this is happening.
views.py
def edit(request, id):
song = Song.objects.get(id=id)
sections = Section.objects.filter(song=song).order_by('order')
chords = Chord.objects.all()
if request.method == "GET":
return render(request, "songbud/edit.html", {
'song':song,
'sections':sections,
'chords':chords
})
songbud.js
function select_audio_edit(elem) {
var parent_Node = elem.parentNode;
console.log(parent_Node.childNodes);
var file = parent_Node.childNodes[3].options[parent_Node.childNodes[3].selectedIndex].getAttribute('data-file');
//console.log(file);
//console.log(parent_Node.childNodes);
parent_Node.childNodes[5].setAttribute("src", file);
return false;
};
function fill_audio() {
let elements = document.querySelectorAll("#chordtemp");
elements.forEach(div => {
let chord = div.childNodes[1].innerHTML;
Array.from(div.childNodes[3].options).forEach(function(option_element) {
if (option_element.text == chord) {
option_element.selected = true;
let file = option_element.dataset.file;
console.log(file);
div.childNodes[5].setAttribute("src", file);
}
});
});
};
edit.html
{% extends "songbud/layout.html" %}
{% load static %}
{% block body %}
<div id="songcreate" style="margin: 30px; font-family: 'Courier New';">
<h1 id="song-title">{{ song.title }}</h1>
<button class="btn btn-outline-warning" id="addsection" onclick="return add_section()">+ add section</button>
</div>
{% for section in sections %}
<div style="display: block; margin: 20px;" id='sectiontemplate'>
<label for='sectiontype'>Choose a section:</label>
<br>
<select class="form-select" aria-label="Default select example" name='sectiontype' id='sectiontype' style="display: inline-block;">
{% if section.sectiontype == 'Intro' %}
<option selected>Intro</option>
{% else %}
<option >Intro</option>
{% endif %}
{% if section.sectiontype == 'Verse' %}
<option selected>Verse</option>
{% else %}
<option>Verse</option>
{% endif %}
{% if section.sectiontype == 'Chorus' %}
<option selected>Chorus</option>
{% else %}
<option>Chorus</option>
{% endif %}
{% if section.sectiontype == 'Bridge' %}
<option selected>Bridge</option>
{% else %}
<option>Bridge</option>
{% endif %}
{% if section.sectiontype == 'Interlude' %}
<option selected>Interlude</option>
{% else %}
<option>Interlude</option>
{% endif %}
{% if section.sectiontype == 'Breakdown' %}
<option selected>Breakdown</option>
{% else %}
<option>Breakdown</option>
{% endif %}
{% if section.sectiontype == 'Solo' %}
<option selected>Solo</option>
{% else %}
<option>Solo</option>
{% endif %}
{% if section.sectiontype == 'Outro' %}
<option selected>Outro</option>
{% else %}
<option>Outro</option>
{% endif %}
</select>
<button class="btn btn-outline-warning" id="addchord" onclick='add_chord(this)' style="display: inline-block;">+ add chord</button>
<br>
{% for chord in section.chords %}
<div id='chordtemp'>
<p style='display: none;'>{{ chord }}</p>
<select name="chordselect" id="chordselect" class="form-select" aria-label="Default select example" style="display: inline-block; vertical-align: center;" onchange="return select_audio_edit(this)">
{% for chrd in chords %}
<option data-file="media/{{ chrd.file }}">{{ chrd }}</option>
{% endfor %}
</select>
<audio controls id='audiofile' style="display: inline-block; position: relative; top: 23px;">
<source src="" type="audio/mp3">
</audio>
</div>
{% endfor %}
</div>
{% endfor %}
<!-- These are the templates for sections and chords -->
<div style='display:none;' data-type='sectiontemplate' id='sectiontemplate'>
<label for='sectiontype'>Choose a section:</label>
<br>
<select class="form-select" aria-label="Default select example" name='sectiontype' id='sectiontype' style="display: inline-block;">
<option>Intro</option>
<option>Verse</option>
<option>Chorus</option>
<option>Bridge</option>
<option>Interlude</option>
<option>Breakdown</option>
<option>Solo</option>
<option>Outro</option>
</select>
<button class="btn btn-outline-warning" id="addchord" onclick='add_chord(this)' style="display: inline-block;">+ add chord</button>
<br>
<br>
</div>
<div style='display:none;' data-type='chordtemplate' id='chordtemplate'>
<select name="chordselect" id="chordselect" class="form-select" aria-label="Default select example" style="display: inline-block; vertical-align: center;" onchange="return select_audio(this)">
{% for chord in chords %}
<option data-file="media/{{ chord.file }}">{{ chord }}</option>
{% endfor %}
</select>
<audio controls style="display: inline-block; position: relative; top: 23px;">
<source src="" type="audio/mp3">
</audio>
</div>
<button class="btn btn-outline-warning" id="savesong" onclick="return save_song()">save</button>
<button class="btn btn-outline-warning" id="exportsong" onclick="return export_song_edit()">export</button>
{% endblock %}
{% block script %}
<script src="{% static 'songbud/songbud.js' %}"></script>
{% endblock %}
The quick fix here is to change media/{{ chord.file }} to /media/{{ chord.file }}. However, you shouldn't be manually creating this path in the first place. I think you can do {{ chord.file.url }} instead. Here I'm assuming that chord is a model object with a FileField named file. I suggest you check the documentation for FileField to verify this and understand it better.

Flask Pagination - Filter - Search Option - Please need support

I am pretty new in the world of programming with python, especially using flask for my current WebApp project:-)
Currently, I am trying to combine the pagination functionality with a filtering option which works perfectly for the first page :-( The filter value gets lost every time, when I change from e.g. page 1 to page 2.
How could you prevent the value from not being lost using different radios?
Attached are the relevant code sections for your review:
#data.route('/search', methods=['POST', 'GET'])
def search():
radios = request.form.get('size')
page = request.args.get('page', 1, type = int)
articles = Data.query.order_by(Data.id.desc()).paginate(page = page, per_page = 5)
if request.method == 'POST' and 'number' in request.form and radios == 'size_1':
number = request.form['number']
search = "%{}%".format(number)
articles = Data.query.filter(Data.sizes.like(search)).paginate(page = page, per_page=7)
elif request.method == 'POST' and 'number' in request.form and radios == 'size_2':
...
...
...
return render_template('search.html',articles = articles)
----HTML_Pagination----
<div class="row justify-content-md-center" style="margin: 3px; padding-top: 30px; text-align: center;">
<div class="col-12">
{% if articles.iter_pages(articles.total < 10) %}
{% for page_num in articles.iter_pages() %}
{% if page_num %}
{% if articles.page == page_num %}
<a class="btn btn-secondary mb-3" style="font-size: 10px;"
href="{{ url_for('data.search', page = page_num) }}">{{ page_num }}</a>
{% else %}
<a class="btn btn-outline-secondary mb-3" style="font-size: 10px;"
href="{{ url_for('data.search', page = page_num)}}">{{ page_num }}</a>
{% endif %}
{% else %}
...
{% endif %}
{% endfor %}
{% else %}
{% for page_num in articles.iter_pages(left_edge = 2, right_edge = 2, left_current = 2, right_current = 2) %}
{% if page_num %}
{% if articles.page == page_num %}
<a class="btn btn-secondary mb-3" style="font-size: 10px;"
href="{{ url_for('data.search', page = page_num)}}">{{ page_num}}</a>
{% else %}
<a class="btn btn-outline-secondary mb-3" style="font-size: 10px;"
href="{{ url_for('data.search', page = page_num)}}">{{ page_num}}</a>
{% endif %}
{% else %}
...
{% endif %}
{% endfor %}
{% endif %}
----HTML----
---Radio & Input---
<div class="form-check">
<input class="form-check-input" type="radio" name="size" id="size" value="size_1">
<label class="form-check-label" for="size">
Size 1
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="size" id="size" value="size_2">
<label class="form-check-label" for="size">
Size 2
</label>
</div>
...
...
<div class="col-6" style="text-align: right;">
<div class="col-12" style="padding-right: 10px;">
<input class="form-control form-control-sm" name="number" id="number" value="{{ request.form['number'] }}" placeholder="Filter by...">
</div>
</div>
---Submit Button---
<div class="col-4" style="padding-left: 20px;">
<div class="col-md-auto" style=" padding-bottom: 15px;">
<div class="btn-group" role="group" aria-label="Basic outlined example">
{{ filter_articles.submit(class="btn btn-outline-secondary", style="font-size: 14.5px; ") }}
</div>
</div>
</div>
Any guide is highly appreciated. Thank you!

how to render image and remove the html tags in content from django ck editor in django template

I tried so many times , but i didn't get any solution for rendering image and content without html tags , i used {{content|safe}} for rendering content on template and i tried strip_tags for html tags removal but it didn't work well for url's , can anyone suggest me why i am getting html tags while rendering in templates.
Models.py
class Product(models.Model):
name = models.RichTextUploadingField(max_length="125")
description = models.RichTextUploadingField()
views.py
def poll():
context = questions.object.all()
return render(request, 'quiz.html', context)
template:
<html>
<body>
{% for q in context %}
<div id="section{{forloop.counter}}">
<script type="text/javascript">
marks.push(Number("{{marks}}"));
neg_marks.push(Number("{{neg_marks}}"));
</script>
<p id="{{forloop.counter}}"><span>{{forloop.counter}}.{{q.question|linebreaks}}
</span></p>
{% if q.figure %}
<img src="{{q.figure.url}}" alt="image" class="img-fluid" width="200px" height="200px"><br><br>
{% endif %}
<input type="radio" id="{{forloop.counter}}option1" name="{{forloop.counter}}" value="1">
<label for="{{forloop.counter}}option1">{{q.option_1|safe }}</label><br>
<input type="radio" id="{{forloop.counter}}option2" name="{{forloop.counter}}" value="2">
<label for="{{forloop.counter}}option2">{{q.option_2|safe}}</label><br>
{% if q.option_3 != "" %}
<input type="radio" id="{{forloop.counter}}option3" name="{{forloop.counter}}" value="3">
<label for="{{forloop.counter}}option3">{{q.option_3|safe}}</label><br>
{% endif %}
{% if q.option_4 != "" %}
<input type="radio" id="{{forloop.counter}}option4" name="{{forloop.counter}}" value="4">
<label for="{{forloop.counter}}option4">{{q.option_4|safe}}</label><br>
{% endif %}
{% if q.option_5 != "" %}
<input type="radio" id="{{forloop.counter}}option5" name="{{forloop.counter}}" value="5">
<label for="{{forloop.counter}}option5">{{q.option_5|safe }}</label><br>
{% endif %}
{% if forloop.first %}
<p role="button" class="btn btn-warning" id="next{{forloop.counter}}" onclick="next_section(this.id)"
style="float: right;">Next</p>
{% elif forloop.last %}
<p role="button" class="btn btn-warning" id="prev{{forloop.counter}}" onclick="prev_section(this.id)"
style="float:left;">Previous</p>
{% else %}
<p role="button" class="btn btn-warning" id="next{{forloop.counter}}" onclick="next_section(this.id)"
style="float: right;">Next</p>
<p role="button" class="btn btn-warning" id="prev{{forloop.counter}}" onclick="prev_section(this.id)"
style="float:left;">Previous</p>
{% endif %}
<br>
<hr>
</body>
</html>
there is no direct way to access images in ck-editor field ... but if you have the direction to the img you can get it like /media/uploads/2020/12/21/my_img.jpg
i suggest to use image field to store external field with image you want
and you have problem here : context = questions.object.all() it should be
context = {'context':questions.object.all()}

Page is opening but search is not working when i am using {% for i in kitty_list %} but in case of {% for i in kitty %} then NoReverseMatch error

In the below scenario, the page is opening but search functionality is not working when i am using {% for i in kitty_list %} in the template. However, when i am using {% for i in kitty %} then I get a NoReverseMatch error.
Url: path('kitty_view',views.kitty_view,name='kitty_view')
View: kitty_list = kitty_list.filter(status = status1)
kittys = kitty.objects.all()
ctx = {'kitty': kitty_list,'kitty_code':kittys}
return render(request, 'kitty/kitty_view.html', ctx)
This is the HTML page which is giving NoReverseMatch error when {% for i in kitty %} is used. When i am using {% for i in kitty_list %} then the page is rendering but the search button is not working.
template:
{% extends 'base.html' %}
{% load static %}
{% block content %}
<form class="form-signin" action="{% url 'kitty_view' %}" method="get">
{% csrf_token %}
<div class="form-row">
<div class="mb-3">
<select class="custom-select center-block" name="code1" id="code1">
<option value="">Choose Kitty...</option>
{% for j in kitty_code %}
<option value="{{ j.code }}"> {{ j.code|add:' - '|add:j.name }} </option>
{% endfor %}
</select>
</div>
<div class="mb-3">
<input type="text" name="nam" id="nam" class="form-control-sm center-block" placeholder="Name" autofocus>
</div>
<div class="mb-3">
<select class="custom-select center-block" name="stat" id="stat" placeholder="Status">
<option value="">Choose Status...</option>
<option>A</option>
<option>I</option>
</select>
</div>
<div class="mb-3">
<button type="submit" class=" btn btn-info " role="button">Search</button>
</div>
</div>
</form>
<table class="table table-dark">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Kitty Code</th>
<th scope="col">Name</th>
</tr>
</thead>
{% if kitty %}
{% for i in kitty_code %}
<tbody>
<tr>
<td>{{ i.id }} </td>
<td>{{ i.code }} </td>
<td>{{ i.name }} </td>
</tr>
</tbody>
{% endfor %}
{% endif %}
</table>
{% endblock %}
Inside the template file, you need to modify the below line. {% url 'kitty_view' %} to {% url '<app_name>:kitty_view' %}. If this would not work then, please give me an error in more detail.

Django and HTML template : Group by panels with common object attributes

One more time, I come back to you in order to get advices or your help.
I'm displaying in my django template a list of objects and I would like to sort them through a common attributes : category.
Each object displayed (a publication) gets some attributes : category, format, language ...
For example :
The white text with blue background indicates the category. I have 2 publications with category = BIOLOGICAL STANDARDISATION PROGRAMME and 1 publication with category = TEST
I would like to group both BIOLOGICAL STANDARDISATION PROGRAMME in one panel but I don't find a way to do that.
This is my HTML template file :
{% for element in test_research|dictsort:"publication.category.name" %}
<div class="col-sm-12">
<div class="panel panel-default request-panel">
<div class="panel-heading" role="tab">
<h4 class="panel-title">
{{ element.publication.category }}
</h4>
</div>
<div class="panel-body">
<div class="row">
<div class="col-sm-9">
<p class="request-publication">{{ element.publication }} </p>
</div>
<div class="col-sm-3 request-cover">
{% if element.publication.cover %}
<a href="{{ element.publication.cover.url }}" target="_blank">
{% thumbnail element.publication.cover "40x40" crop="center" as im %}
<img src="{{ im.url }}" width="{{ im.width }}" height="{{ im.height }}">
{% endthumbnail %}</a>
{% endif %}
</div>
</div>
</div>
<div class="panel-footer">
<div class="row">
<table>
<tbody>
<tr>
<td class="col-md-1">
<div class="material-switch pull-right">
<input id="someSwitchOptionSuccess_{{ element.id }}" name="DocumentChoice" type="checkbox"
value="{{ element.id }}"/>
<label for="someSwitchOptionSuccess_{{ element.id }}" class="label-success"></label>
</div>
</td>
<td class="col-md-1 request-language"> {{ element.language }}</td>
<td class="col-md-1 request-format">
{% if element.format == 'pdf' %}
<span class="badge alert-danger">{{ element.format }}</span>
{% endif %}
{% if element.format == 'epub' %}
<span class="badge alert-info">{{ element.format }}</span>
{% endif %}
</td>
<td class="col-md-1 request-flag">
{% if element.publication.new_publication == True %}
<span class="glyphicon glyphicon-flag"></span>
{% else %}
<span></span>
{% endif %}
</td>
<td class="col-md-offset-5 col-md-3 text-right">{{ element.title }}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
{% endfor %}
And in my views.py file :
def get_context_data(self, **kwargs):
search_category = Document.objects.values_list('publication__category__name', flat=True).distinct()
kwargs['search_category'] = search_category
search_format = Document.objects.values_list('format', flat=True).distinct()
kwargs['search_format'] = search_format
search_language = Document.objects.values_list('language', flat=True).distinct()
kwargs['search_language'] = search_language
checkbox_category = self.request.GET.getlist('CategoryChoice')
checkbox_format = self.request.GET.getlist('FormatChoice')
checkbox_language = self.request.GET.getlist('LanguageChoice')
choice_title = self.request.GET.get('TitleChoice')
kwargs['checkbox_category'] = checkbox_category
kwargs['checkbox_format'] = checkbox_format
kwargs['checkbox_language'] = checkbox_language
kwargs['choice_title'] = choice_title
# default to all documents
test_research = Document.objects.all().order_by('publication__category__name')
kwargs['test_research'] = test_research
if "SubmitChoice" in self.request.GET:
test_research = Document.objects.all()
# if user entered any search criteria, add those filters
if checkbox_category:
test_research = test_research.filter(publication__category__name__in=checkbox_category)
if checkbox_format:
test_research = test_research.filter(format__in=checkbox_format)
if checkbox_language:
test_research = test_research.filter(language__in=checkbox_language)
if choice_title:
test_research = test_research.filter(
Q(title__icontains=choice_title) | Q(publication__title__icontains=choice_title))
kwargs['test_research'] = test_research
return super(HomeView, self).get_context_data(**kwargs)
I can add models.py file if necessary. How it's possible to group them under the same category panel ?
EDIT :
I maybe found something with that :
{% for category in checkbox_category %}
<div class="col-sm-12">
<div class="panel panel-default request-panel">
<div class="panel-heading" role="tab">
<h4 class="panel-title">
{{ category }}
</h4>
</div>
{% for element in test_research %}
{{ element.publication.category }} - {{ category }}
{% if element.publication.category == category %}
But the if condition doesn't seems to work even if {{element.publication.category}} == {{category}}
You should restructure your data in the view so that it's already prepared for the template. Django's template system is built in a way to avoid this type of logic.
You might be able to do it simply like this:
from collections import defaultdict
research_categories = defaultdict(list)
for element in test_research:
research_categories[element.publication.category].append(element)
Then use research_categories in your template.