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

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