Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

13 лет назад
11 лет назад
11 лет назад
12 лет назад
12 лет назад
12 лет назад
12 лет назад
12 лет назад
13 лет назад
13 лет назад
13 лет назад
13 лет назад
13 лет назад
13 лет назад
13 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. # Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
  2. # MIT License. See license.txt
  3. from __future__ import unicode_literals
  4. import webnotes
  5. import json
  6. import copy
  7. @webnotes.whitelist()
  8. def get_data(doctypes, last_modified):
  9. from startup.report_data_map import data_map
  10. import datetime
  11. out = {}
  12. doctypes = json.loads(doctypes)
  13. last_modified = json.loads(last_modified)
  14. start = datetime.datetime.now()
  15. for d in doctypes:
  16. args = copy.deepcopy(data_map[d])
  17. dt = d.find("[") != -1 and d[:d.find("[")] or d
  18. out[dt] = {}
  19. if args.get("from"):
  20. modified_table = "item."
  21. else:
  22. modified_table = ""
  23. conditions = order_by = ""
  24. table = args.get("from") or ("`tab%s`" % dt)
  25. if d in last_modified:
  26. if not args.get("conditions"):
  27. args['conditions'] = []
  28. args['conditions'].append(modified_table + "modified > '" + last_modified[d] + "'")
  29. out[dt]["modified_names"] = webnotes.conn.sql_list("""select %sname from %s
  30. where %smodified > %s""" % (modified_table, table, modified_table, "%s"), last_modified[d])
  31. if args.get("force_index"):
  32. conditions = " force index (%s) " % args["force_index"]
  33. if args.get("conditions"):
  34. conditions += " where " + " and ".join(args["conditions"])
  35. if args.get("order_by"):
  36. order_by = " order by " + args["order_by"]
  37. out[dt]["data"] = [list(t) for t in webnotes.conn.sql("""select %s from %s %s %s""" \
  38. % (",".join(args["columns"]), table, conditions, order_by))]
  39. # last modified
  40. modified_table = table
  41. if "," in table:
  42. modified_table = " ".join(table.split(",")[0].split(" ")[:-1])
  43. tmp = webnotes.conn.sql("""select `modified`
  44. from %s order by modified desc limit 1""" % modified_table)
  45. out[dt]["last_modified"] = tmp and tmp[0][0] or ""
  46. out[dt]["columns"] = map(lambda c: c.split(" as ")[-1], args["columns"])
  47. if args.get("links"):
  48. out[dt]["links"] = args["links"]
  49. for d in out:
  50. unused_links = []
  51. # only compress full dumps (not partial)
  52. if out[d].get("links") and (d not in last_modified):
  53. for link_key in out[d]["links"]:
  54. link = out[d]["links"][link_key]
  55. if link[0] in out and (link[0] not in last_modified):
  56. # make a map of link ids
  57. # to index
  58. link_map = {}
  59. doctype_data = out[link[0]]
  60. col_idx = doctype_data["columns"].index(link[1])
  61. for row_idx in xrange(len(doctype_data["data"])):
  62. row = doctype_data["data"][row_idx]
  63. link_map[row[col_idx]] = row_idx
  64. for row in out[d]["data"]:
  65. col_idx = out[d]["columns"].index(link_key)
  66. # replace by id
  67. if row[col_idx]:
  68. row[col_idx] = link_map.get(row[col_idx])
  69. else:
  70. unused_links.append(link_key)
  71. for link in unused_links:
  72. del out[d]["links"][link]
  73. return out