prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  (List View): In sidebar filter link field show Title of Field if set
  **Is your feature request related to a problem? Please describe.**
  In sidebar filter link field show field.name but not field.title
  
  **Describe the solution you'd like**
  if link field has title field - show title.
  ![image](https://github.com/frappe/frappe/assets/4525776/843f4b1c-daaf-4de9-958f-33dc57137c95)
  
  </issue>
  <code>
  [start of frappe/desk/listview.py]
  1 # Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and Contributors
  2 # License: MIT. See LICENSE
  3 
  4 import frappe
  5 from frappe.model import is_default_field
  6 from frappe.query_builder import Order
  7 from frappe.query_builder.functions import Count
  8 from frappe.query_builder.terms import SubQuery
  9 from frappe.query_builder.utils import DocType
  10 
  11 
  12 @frappe.whitelist()
  13 def get_list_settings(doctype):
  14 	try:
  15 		return frappe.get_cached_doc("List View Settings", doctype)
  16 	except frappe.DoesNotExistError:
  17 		frappe.clear_messages()
  18 
  19 
  20 @frappe.whitelist()
  21 def set_list_settings(doctype, values):
  22 	try:
  23 		doc = frappe.get_doc("List View Settings", doctype)
  24 	except frappe.DoesNotExistError:
  25 		doc = frappe.new_doc("List View Settings")
  26 		doc.name = doctype
  27 		frappe.clear_messages()
  28 	doc.update(frappe.parse_json(values))
  29 	doc.save()
  30 
  31 
  32 @frappe.whitelist()
  33 def get_group_by_count(doctype: str, current_filters: str, field: str) -> list[dict]:
  34 	current_filters = frappe.parse_json(current_filters)
  35 
  36 	if field == "assigned_to":
  37 		ToDo = DocType("ToDo")
  38 		User = DocType("User")
  39 		count = Count("*").as_("count")
  40 		filtered_records = frappe.qb.get_query(
  41 			doctype,
  42 			filters=current_filters,
  43 			fields=["name"],
  44 			validate_filters=True,
  45 		)
  46 
  47 		return (
  48 			frappe.qb.from_(ToDo)
  49 			.from_(User)
  50 			.select(ToDo.allocated_to.as_("name"), count)
  51 			.where(
  52 				(ToDo.status != "Cancelled")
  53 				& (ToDo.allocated_to == User.name)
  54 				& (User.user_type == "System User")
  55 				& (ToDo.reference_name.isin(SubQuery(filtered_records)))
  56 			)
  57 			.groupby(ToDo.allocated_to)
  58 			.orderby(count, order=Order.desc)
  59 			.limit(50)
  60 			.run(as_dict=True)
  61 		)
  62 
  63 	if not frappe.get_meta(doctype).has_field(field) and not is_default_field(field):
  64 		raise ValueError("Field does not belong to doctype")
  65 
  66 	return frappe.get_list(
  67 		doctype,
  68 		filters=current_filters,
  69 		group_by=f"`tab{doctype}`.{field}",
  70 		fields=["count(*) as count", f"`{field}` as name"],
  71 		order_by="count desc",
  72 		limit=50,
  73 	)
  74
  [end of frappe/desk/listview.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/frappe/desk/listview.py b/frappe/desk/listview.py
  --- a/frappe/desk/listview.py
  +++ b/frappe/desk/listview.py
  @@ -60,10 +60,12 @@
   			.run(as_dict=True)
   		)
   
  -	if not frappe.get_meta(doctype).has_field(field) and not is_default_field(field):
  +	meta = frappe.get_meta(doctype)
  +
  +	if not meta.has_field(field) and not is_default_field(field):
   		raise ValueError("Field does not belong to doctype")
   
  -	return frappe.get_list(
  +	data = frappe.get_list(
   		doctype,
   		filters=current_filters,
   		group_by=f"`tab{doctype}`.{field}",
  @@ -71,3 +73,13 @@
   		order_by="count desc",
   		limit=50,
   	)
  +
  +	# Add in title if it's a link field and `show_title_field_in_link` is set
  +	if (field_meta := meta.get_field(field)) and field_meta.fieldtype == "Link":
  +		link_meta = frappe.get_meta(field_meta.options)
  +		if link_meta.show_title_field_in_link:
  +			title_field = link_meta.get_title_field()
  +			for item in data:
  +				item.title = frappe.get_value(field_meta.options, item.name, title_field)
  +
  +	return data
  
verification_info: {"golden_diff": "diff --git a/frappe/desk/listview.py b/frappe/desk/listview.py\n--- a/frappe/desk/listview.py\n+++ b/frappe/desk/listview.py\n@@ -60,10 +60,12 @@\n \t\t\t.run(as_dict=True)\n \t\t)\n \n-\tif not frappe.get_meta(doctype).has_field(field) and not is_default_field(field):\n+\tmeta = frappe.get_meta(doctype)\n+\n+\tif not meta.has_field(field) and not is_default_field(field):\n \t\traise ValueError(\"Field does not belong to doctype\")\n \n-\treturn frappe.get_list(\n+\tdata = frappe.get_list(\n \t\tdoctype,\n \t\tfilters=current_filters,\n \t\tgroup_by=f\"`tab{doctype}`.{field}\",\n@@ -71,3 +73,13 @@\n \t\torder_by=\"count desc\",\n \t\tlimit=50,\n \t)\n+\n+\t# Add in title if it's a link field and `show_title_field_in_link` is set\n+\tif (field_meta := meta.get_field(field)) and field_meta.fieldtype == \"Link\":\n+\t\tlink_meta = frappe.get_meta(field_meta.options)\n+\t\tif link_meta.show_title_field_in_link:\n+\t\t\ttitle_field = link_meta.get_title_field()\n+\t\t\tfor item in data:\n+\t\t\t\titem.title = frappe.get_value(field_meta.options, item.name, title_field)\n+\n+\treturn data\n", "issue": "(List View): In sidebar filter link field show Title of Field if set\n**Is your feature request related to a problem? Please describe.**\r\nIn sidebar filter link field show field.name but not field.title\r\n\r\n**Describe the solution you'd like**\r\nif link field has title field - show title.\r\n![image](https://github.com/frappe/frappe/assets/4525776/843f4b1c-daaf-4de9-958f-33dc57137c95)\n", "before_files": [{"content": "# Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and Contributors\n# License: MIT. See LICENSE\n\nimport frappe\nfrom frappe.model import is_default_field\nfrom frappe.query_builder import Order\nfrom frappe.query_builder.functions import Count\nfrom frappe.query_builder.terms import SubQuery\nfrom frappe.query_builder.utils import DocType\n\n\n@frappe.whitelist()\ndef get_list_settings(doctype):\n\ttry:\n\t\treturn frappe.get_cached_doc(\"List View Settings\", doctype)\n\texcept frappe.DoesNotExistError:\n\t\tfrappe.clear_messages()\n\n\n@frappe.whitelist()\ndef set_list_settings(doctype, values):\n\ttry:\n\t\tdoc = frappe.get_doc(\"List View Settings\", doctype)\n\texcept frappe.DoesNotExistError:\n\t\tdoc = frappe.new_doc(\"List View Settings\")\n\t\tdoc.name = doctype\n\t\tfrappe.clear_messages()\n\tdoc.update(frappe.parse_json(values))\n\tdoc.save()\n\n\n@frappe.whitelist()\ndef get_group_by_count(doctype: str, current_filters: str, field: str) -> list[dict]:\n\tcurrent_filters = frappe.parse_json(current_filters)\n\n\tif field == \"assigned_to\":\n\t\tToDo = DocType(\"ToDo\")\n\t\tUser = DocType(\"User\")\n\t\tcount = Count(\"*\").as_(\"count\")\n\t\tfiltered_records = frappe.qb.get_query(\n\t\t\tdoctype,\n\t\t\tfilters=current_filters,\n\t\t\tfields=[\"name\"],\n\t\t\tvalidate_filters=True,\n\t\t)\n\n\t\treturn (\n\t\t\tfrappe.qb.from_(ToDo)\n\t\t\t.from_(User)\n\t\t\t.select(ToDo.allocated_to.as_(\"name\"), count)\n\t\t\t.where(\n\t\t\t\t(ToDo.status != \"Cancelled\")\n\t\t\t\t& (ToDo.allocated_to == User.name)\n\t\t\t\t& (User.user_type == \"System User\")\n\t\t\t\t& (ToDo.reference_name.isin(SubQuery(filtered_records)))\n\t\t\t)\n\t\t\t.groupby(ToDo.allocated_to)\n\t\t\t.orderby(count, order=Order.desc)\n\t\t\t.limit(50)\n\t\t\t.run(as_dict=True)\n\t\t)\n\n\tif not frappe.get_meta(doctype).has_field(field) and not is_default_field(field):\n\t\traise ValueError(\"Field does not belong to doctype\")\n\n\treturn frappe.get_list(\n\t\tdoctype,\n\t\tfilters=current_filters,\n\t\tgroup_by=f\"`tab{doctype}`.{field}\",\n\t\tfields=[\"count(*) as count\", f\"`{field}` as name\"],\n\t\torder_by=\"count desc\",\n\t\tlimit=50,\n\t)\n", "path": "frappe/desk/listview.py"}]}