Merge pull request #779 from anandpdoshi/anand-august-19
[fix] Preserve sequence of values when performing unique for autosuggest
This commit is contained in:
commit
7932c7f1b3
2 changed files with 9 additions and 2 deletions
|
|
@ -585,3 +585,10 @@ def quote_urls(html):
|
|||
return re.sub('(href|src){1}([\s]*=[\s]*[\'"]?)((?:http)[^\'">]+)([\'"]?)',
|
||||
_quote_url, html)
|
||||
|
||||
def unique(seq):
|
||||
"""use this instead of list(set()) to preserve order of the original list.
|
||||
Thanks to Stackoverflow: http://stackoverflow.com/questions/480214/how-do-you-remove-duplicates-from-a-list-in-python-whilst-preserving-order"""
|
||||
|
||||
seen = set()
|
||||
seen_add = seen.add
|
||||
return [ x for x in seq if not (x in seen or seen_add(x)) ]
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
import frappe.widgets.reportview
|
||||
from frappe.utils import cstr
|
||||
from frappe.utils import cstr, unique
|
||||
|
||||
# this is called by the Link Field
|
||||
@frappe.whitelist()
|
||||
|
|
@ -99,7 +99,7 @@ def get_std_fields_list(meta, key):
|
|||
def build_for_autosuggest(res):
|
||||
results = []
|
||||
for r in res:
|
||||
out = {"value": r[0], "description": ", ".join(list(set(cstr(d) for d in r[1:])))}
|
||||
out = {"value": r[0], "description": ", ".join(unique(cstr(d) for d in r)[1:])}
|
||||
results.append(out)
|
||||
return results
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue