seitime-frappe/frappe/model/__init__.py
Rushabh Mehta 86ceb21005 [feature] Global Search (again) (#2710)
* [start] global search frappe/erpnext#6674

* [fix] setup before running test

* [start] global search frappe/erpnext#6674

* Display result as rudimentary list, rebuild old doctypes

* Media view, child tables, delete document updates, searchable fields

* More results UI

* Code clean up

* remove msgprint from document.py to resolve merge conflict

* Modularization stage 1, get show more to work with it

* Dedicated modal Search bar works, some clean up needed

* Can't data-dismiss on links, Bootstrap issue, use hashchange

* Accomodate missing field content syndrome

* Search in boolean mode, make GS default in awesome bar, fix double modal bug and cleanup

* Add in Meta

* Add in customize form

* Modularise Global Search

* Search object

* Commonify Search UI: Stage I

* II: save list state, UI, default condensed view, refactor

* Fix SQL bug, Refactor awesome bar, Fix unicode bug, add nav results

* Refactor using separate search objects, some async issues

* Fix async flow

* Fix preceding more list bug

* UI additions

* another async fix, back link

* Help: Stage I

* Help: Stage II

* Background jobs, fix route options bug

* Fix GS syncing on install

* Add GS options in awesome bar: test

* Input now remembers search type state

* More UI updates

* Add description for GS results in awesome bar

* Fix help modal bug

* Fix: not commit during install

* Test cases, some fixes

* Update in_test flag in enqueue

* Disable GS sync when not install_db

* Add flag check

* Disable field in child tables

* Cleanups

* Create table fix

* Fix redis exception, remove commit enqueue, add gs in migrate

* Fix tests

* Single enqueue

* cleanups

* Fix tests

* Fix event test

* Fix duplication, search as first option

* Add show name in global search

* fix event tests and desk.less

* Fix communication.json

* [fixes] wip

* [fix] tests

* [minor] for tests

* [minor] for tests

* [minor] for tests

* [minor] for tests
2017-02-13 14:50:54 +05:30

72 lines
2.2 KiB
Python

# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt
# model __init__.py
from __future__ import unicode_literals
import frappe
import json
no_value_fields = ('Section Break', 'Column Break', 'HTML', 'Table', 'Button', 'Image',
'Fold', 'Heading')
display_fieldtypes = ('Section Break', 'Column Break', 'HTML', 'Button', 'Image', 'Fold', 'Heading')
default_fields = ('doctype','name','owner','creation','modified','modified_by',
'parent','parentfield','parenttype','idx','docstatus')
optional_fields = ("_user_tags", "_comments", "_assign", "_liked_by", "_seen")
def rename(doctype, old, new, debug=False):
import frappe.model.rename_doc
frappe.model.rename_doc.rename_doc(doctype, old, new, debug)
def copytables(srctype, src, srcfield, tartype, tar, tarfield, srcfields, tarfields=[]):
if not tarfields:
tarfields = srcfields
l = []
data = src.get(srcfield)
for d in data:
newrow = tar.append(tarfield)
newrow.idx = d.idx
for i in range(len(srcfields)):
newrow.set(tarfields[i], d.get(srcfields[i]))
l.append(newrow)
return l
def db_exists(dt, dn):
return frappe.db.exists(dt, dn)
def delete_fields(args_dict, delete=0):
"""
Delete a field.
* Deletes record from `tabDocField`
* If not single doctype: Drops column from table
* If single, deletes record from `tabSingles`
args_dict = { dt: [field names] }
"""
import frappe.utils
for dt in args_dict.keys():
fields = args_dict[dt]
if not fields: continue
frappe.db.sql("""\
DELETE FROM `tabDocField`
WHERE parent=%s AND fieldname IN (%s)
""" % ('%s', ", ".join(['"' + f + '"' for f in fields])), dt)
# Delete the data / column only if delete is specified
if not delete: continue
if frappe.db.get_value("DocType", dt, "issingle"):
frappe.db.sql("""\
DELETE FROM `tabSingles`
WHERE doctype=%s AND field IN (%s)
""" % ('%s', ", ".join(['"' + f + '"' for f in fields])), dt)
else:
existing_fields = frappe.db.sql("desc `tab%s`" % dt)
existing_fields = existing_fields and [e[0] for e in existing_fields] or []
query = "ALTER TABLE `tab%s` " % dt + \
", ".join(["DROP COLUMN `%s`" % f for f in fields if f in existing_fields])
frappe.db.commit()
frappe.db.sql(query)