I am using Frappe Framework: v15.27.0 (version-15)
I deployed a portal web page in my app. It works perfectly in developed environment and not working in production environment. The problem is if do any changes in the text field and perform search. The new values are not fetched but it displays the record based on the old search field value.
My route is
http://**.**.**.**1/directory?search_by=firstname&search_name=&status=Type1&people_address=
Filter is not applied so displays the all record but it only works if developer mode is on
My Html:
{% extends "templates/web.html" %}
{% block title %}people Directory{% endblock %}
{% block content %}
<div class="site-section">
<div class="container">
<div class="row pt-8 pb-10">
<form class="form-search col-12">
<div class="row align-items-end">
<div class="col-sm-3 pt-2">
<label for="list-types">Category</label>
<div class="select-wrap">
<select name="status" id="list-types" class="form-control d-block rounded-0"> <option value="" {% if not category_selected %}selected{% endif %}>Select an option
</option>
{% for category in categories %}
<option value="{{category.status}}" {% if category.status==category_selected %}selected{%
endif %}>
{{category.status}}</option>
{% endfor %}
</select>
</div>
</div>
<div class="col-sm-3 pt-2">
<label for="list-types">Address</label>
<div class="select-wrap">
<select name="people_address" id="list-types" class="form-control d-block rounded-0">
<option value="" {% if not type_selected %}selected{% endif %}>Select an option</option>
{% for type in address %}
<option value="{{type.people_address}}" {% if type.people_address==type_selected %}selected{% endif
%}>
{{type.people_address}}</option>
{% endfor %}
</select>
</div>
</div>
<div class="col-sm-3 pt-5">
<input type="submit" class="btn btn-success text-white btn-block rounded-0 custom-btn"
value="Search">
</div>
</div>
</form>
</div>
</div>
</div>
<div class="container-fluid">
<div class="row">
{% for record in records %}
<div class="col-md-4 mb-4">
<div class="card">
<div class="card-body">
<h5 class="card-title">{{ record.first_name }} {{ record.surname }}</h5>
<h6 class="card-subtitle mb-2 text-muted">{{ record.status }}</h6>
<p class="card-text">people Name: {{ record.people_name }}</p>
<p class="card-text">people Address: {{ record.people_address }}</p>
</div>
</div>
</div>
{% endfor %}
</div>
</div>
{% endblock %}
My index.py
import frappe
from frappe.utils.data import ceil
def get_context(context):
filters = {
"status": ["in", ["Type I", "Type II"]]
}
categories = frappe.get_list("Directory", filters=filters, fields=["status"], group_by="status")
context.categories = categories
address = frappe.get_list("Directory", filters=filters, fields=["people_address"], group_by="people_address", order_by="people_address asc")
context.address = address
# Extracting filters from form dictionary
status = frappe.form_dict.get("status")
people_address = frappe.form_dict.get("people_address")
search_by = frappe.form_dict.get("search_by")
search_name = frappe.form_dict.get("search_name")
# Set context variables
if status:
context.category_selected = status
if people_address:
context.type_selected = people_address
if search_by:
context.search_by = search_by
# Adjust search_by field if needed
if search_by == "firstname":
search_by_field = "first_name"
elif search_by == "surname":
search_by_field = "surname"
elif search_by == "people_name":
search_by_field = "people_name"
else:
# Default to first_name if search_by is not provided or invalid
search_by_field = "first_name"
else:
# Default to first_name if search_by is not provided
search_by_field = "first_name"
if search_name:
context.search_name = search_name
# Pagination
page_length = 9 # Number of records per page
current_page = frappe.form_dict.get("page", 1) # Current page number, default is 1
limit_start = (int(current_page) - 1) * page_length
# Fetch records based on filters and pagination
records_filters = filters.copy() # Create a copy of the original filters
if status:
records_filters["status"] = status
if people_address:
records_filters["people_address"] = people_address
if search_by_field and search_name:
records_filters[search_by_field] = ["like", "%" + search_name + "%"]
total_records = frappe.db.count("Directory", filters=records_filters)
total_pages = ceil(total_records / page_length)
records = frappe.get_list("Directory", filters=records_filters, fields=["first_name", "surname", "people_name", "status", "people_address"], limit_start=limit_start, limit_page_length=page_length)
# Pass context variables
context.records = records
context.total_pages = total_pages
context.current_page = current_page
return context
Reference: