django-advanced-report-builder 1.2.9__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (360) hide show
  1. advanced_report_builder/.DS_Store +0 -0
  2. advanced_report_builder/.ruff_cache/.gitignore +2 -0
  3. advanced_report_builder/.ruff_cache/0.11.9/16555798982502606642 +0 -0
  4. advanced_report_builder/.ruff_cache/CACHEDIR.TAG +1 -0
  5. advanced_report_builder/__init__.py +0 -0
  6. advanced_report_builder/admin.py +264 -0
  7. advanced_report_builder/apps.py +7 -0
  8. advanced_report_builder/column_types.py +26 -0
  9. advanced_report_builder/columns.py +296 -0
  10. advanced_report_builder/customise.py +2 -0
  11. advanced_report_builder/data_merge/__init__.py +0 -0
  12. advanced_report_builder/data_merge/utils.py +112 -0
  13. advanced_report_builder/data_merge/widget.py +30 -0
  14. advanced_report_builder/duplicate.py +171 -0
  15. advanced_report_builder/exceptions.py +9 -0
  16. advanced_report_builder/field_types.py +466 -0
  17. advanced_report_builder/field_utils.py +401 -0
  18. advanced_report_builder/filter_query.py +862 -0
  19. advanced_report_builder/form_utils.py +12 -0
  20. advanced_report_builder/generate_series.py +14 -0
  21. advanced_report_builder/globals.py +276 -0
  22. advanced_report_builder/includes.py +72 -0
  23. advanced_report_builder/migrations/0001_initial.py +246 -0
  24. advanced_report_builder/migrations/0002_auto_20220209_1657.py +23 -0
  25. advanced_report_builder/migrations/0003_auto_20220215_1219.py +42 -0
  26. advanced_report_builder/migrations/0004_customreport.py +27 -0
  27. advanced_report_builder/migrations/0005_auto_20220303_0958.py +84 -0
  28. advanced_report_builder/migrations/0006_auto_20220310_1147.py +32 -0
  29. advanced_report_builder/migrations/0007_auto_20220322_1939.py +23 -0
  30. advanced_report_builder/migrations/0008_auto_20220404_1144.py +28 -0
  31. advanced_report_builder/migrations/0009_auto_20230428_1554.py +53 -0
  32. advanced_report_builder/migrations/0010_auto_20230428_2033.py +23 -0
  33. advanced_report_builder/migrations/0011_auto_20230620_1449.py +23 -0
  34. advanced_report_builder/migrations/0012_auto_20230718_1642.py +24 -0
  35. advanced_report_builder/migrations/0013_reportqueryorder.py +30 -0
  36. advanced_report_builder/migrations/0014_auto_20240706_2207.py +24 -0
  37. advanced_report_builder/migrations/0015_report_user_created_report_user_updated.py +26 -0
  38. advanced_report_builder/migrations/0016_calendarreport_dashboardreport_options_and_more.py +74 -0
  39. advanced_report_builder/migrations/0017_alter_barchartreport_options_and_more.py +57 -0
  40. advanced_report_builder/migrations/0018_reportquery_target_target_period_type.py +24 -0
  41. advanced_report_builder/migrations/0019_multicellstyle_and_more.py +107 -0
  42. advanced_report_builder/migrations/0020_alter_multicellstyle_font_size.py +18 -0
  43. advanced_report_builder/migrations/0021_multivalueheldquery_and_more.py +36 -0
  44. advanced_report_builder/migrations/0022_dashboardreport_show_options_report_template_style_and_more.py +44 -0
  45. advanced_report_builder/migrations/0023_rename_colour_target_default_colour_and_more.py +41 -0
  46. advanced_report_builder/migrations/0024_alter_target_period_type.py +18 -0
  47. advanced_report_builder/migrations/__init__.py +0 -0
  48. advanced_report_builder/models.py +954 -0
  49. advanced_report_builder/report_builder.py +28 -0
  50. advanced_report_builder/signals.py +3 -0
  51. advanced_report_builder/static/.DS_Store +0 -0
  52. advanced_report_builder/static/advanced_report_builder/.DS_Store +0 -0
  53. advanced_report_builder/static/advanced_report_builder/chart-js/js/chart.esm.js +10553 -0
  54. advanced_report_builder/static/advanced_report_builder/chart-js/js/chart.js +13190 -0
  55. advanced_report_builder/static/advanced_report_builder/chart-js/js/chart.min.js +13 -0
  56. advanced_report_builder/static/advanced_report_builder/chart-js/js/chartjs-adapter-moment.min.js +8 -0
  57. advanced_report_builder/static/advanced_report_builder/chart-js/js/chartjs-plugin-datalabels.min.js +7 -0
  58. advanced_report_builder/static/advanced_report_builder/chart-js/js/chunks/helpers.segment.js +2499 -0
  59. advanced_report_builder/static/advanced_report_builder/chart-js/js/helpers.esm.js +7 -0
  60. advanced_report_builder/static/advanced_report_builder/d3/js/d3.js +20196 -0
  61. advanced_report_builder/static/advanced_report_builder/d3/js/d3.min.js +2 -0
  62. advanced_report_builder/static/advanced_report_builder/d3-funnel/js/d3-funnel.js +6087 -0
  63. advanced_report_builder/static/advanced_report_builder/d3-funnel/js/d3-funnel.min.js +2 -0
  64. advanced_report_builder/static/advanced_report_builder/dashboard/js/dashboard.js +19 -0
  65. advanced_report_builder/static/advanced_report_builder/dot/js/.gitignore +31 -0
  66. advanced_report_builder/static/advanced_report_builder/dot/js/.travis.yml +9 -0
  67. advanced_report_builder/static/advanced_report_builder/dot/js/LICENSE-DOT.txt +24 -0
  68. advanced_report_builder/static/advanced_report_builder/dot/js/README.md +90 -0
  69. advanced_report_builder/static/advanced_report_builder/dot/js/bin/dot-packer +52 -0
  70. advanced_report_builder/static/advanced_report_builder/dot/js/bower.json +21 -0
  71. advanced_report_builder/static/advanced_report_builder/dot/js/doT.js +141 -0
  72. advanced_report_builder/static/advanced_report_builder/dot/js/doT.min.js +8 -0
  73. advanced_report_builder/static/advanced_report_builder/dot/js/doU.js +56 -0
  74. advanced_report_builder/static/advanced_report_builder/dot/js/index.js +143 -0
  75. advanced_report_builder/static/advanced_report_builder/dot/js/package.json +46 -0
  76. advanced_report_builder/static/advanced_report_builder/fullcalendar/.DS_Store +0 -0
  77. advanced_report_builder/static/advanced_report_builder/fullcalendar/LICENSE.txt +20 -0
  78. advanced_report_builder/static/advanced_report_builder/fullcalendar/README.md +10 -0
  79. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/LICENSE.txt +20 -0
  80. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/README.md +8 -0
  81. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/af.js +30 -0
  82. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/ar-dz.js +31 -0
  83. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/ar-kw.js +31 -0
  84. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/ar-ly.js +31 -0
  85. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/ar-ma.js +31 -0
  86. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/ar-sa.js +31 -0
  87. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/ar-tn.js +31 -0
  88. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/ar.js +31 -0
  89. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/bg.js +31 -0
  90. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/bs.js +32 -0
  91. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/ca.js +30 -0
  92. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/cs.js +32 -0
  93. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/da.js +30 -0
  94. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/de.js +33 -0
  95. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/el.js +30 -0
  96. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/en-au.js +17 -0
  97. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/en-gb.js +17 -0
  98. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/en-nz.js +17 -0
  99. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/es-us.js +30 -0
  100. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/es.js +30 -0
  101. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/et.js +32 -0
  102. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/eu.js +30 -0
  103. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/fa.js +33 -0
  104. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/fi.js +30 -0
  105. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/fr-ca.js +27 -0
  106. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/fr-ch.js +31 -0
  107. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/fr.js +31 -0
  108. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/gl.js +30 -0
  109. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/he.js +27 -0
  110. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/hi.js +32 -0
  111. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/hr.js +32 -0
  112. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/hu.js +30 -0
  113. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/id.js +30 -0
  114. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/is.js +30 -0
  115. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/it.js +32 -0
  116. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/ja.js +28 -0
  117. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/ka.js +32 -0
  118. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/kk.js +32 -0
  119. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/ko.js +26 -0
  120. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/lb.js +30 -0
  121. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/lt.js +30 -0
  122. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/lv.js +32 -0
  123. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/mk.js +28 -0
  124. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/ms.js +32 -0
  125. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/nb.js +30 -0
  126. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/nl.js +30 -0
  127. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/nn.js +30 -0
  128. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/pl.js +30 -0
  129. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/pt-br.js +28 -0
  130. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/pt.js +30 -0
  131. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/ro.js +32 -0
  132. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/ru.js +32 -0
  133. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/sk.js +32 -0
  134. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/sl.js +30 -0
  135. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/sq.js +32 -0
  136. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/sr-cyrl.js +32 -0
  137. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/sr.js +32 -0
  138. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/sv.js +30 -0
  139. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/th.js +25 -0
  140. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/tr.js +30 -0
  141. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/uk.js +32 -0
  142. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/vi.js +32 -0
  143. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/zh-cn.js +33 -0
  144. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales/zh-tw.js +26 -0
  145. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales-all.js +1348 -0
  146. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/locales-all.min.js +1 -0
  147. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/main.css +1052 -0
  148. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/main.d.ts +2730 -0
  149. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/main.esm.js +8558 -0
  150. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/main.js +8717 -0
  151. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/main.min.css +1 -0
  152. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/main.min.js +6 -0
  153. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/core/package.json +30 -0
  154. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/daygrid/LICENSE.txt +20 -0
  155. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/daygrid/README.md +8 -0
  156. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/daygrid/main.css +78 -0
  157. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/daygrid/main.d.ts +310 -0
  158. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/daygrid/main.esm.js +1627 -0
  159. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/daygrid/main.js +1641 -0
  160. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/daygrid/main.min.css +1 -0
  161. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/daygrid/main.min.js +6 -0
  162. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/daygrid/package.json +33 -0
  163. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/fullcalendar-yearview/LICENSE +21 -0
  164. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/fullcalendar-yearview/css/main.css +85 -0
  165. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/fullcalendar-yearview/js/main.js +2018 -0
  166. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/google-calendar/LICENSE.txt +20 -0
  167. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/google-calendar/README.md +8 -0
  168. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/google-calendar/main.d.ts +20 -0
  169. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/google-calendar/main.esm.js +162 -0
  170. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/google-calendar/main.js +170 -0
  171. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/google-calendar/main.min.js +6 -0
  172. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/google-calendar/package.json +33 -0
  173. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/interaction/LICENSE.txt +20 -0
  174. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/interaction/README.md +8 -0
  175. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/interaction/main.d.ts +323 -0
  176. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/interaction/main.esm.js +2132 -0
  177. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/interaction/main.js +2143 -0
  178. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/interaction/main.min.js +6 -0
  179. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/interaction/package.json +33 -0
  180. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/list/LICENSE.txt +20 -0
  181. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/list/README.md +8 -0
  182. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/list/main.css +118 -0
  183. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/list/main.d.ts +33 -0
  184. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/list/main.esm.js +335 -0
  185. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/list/main.js +343 -0
  186. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/list/main.min.css +1 -0
  187. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/list/main.min.js +6 -0
  188. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/list/package.json +33 -0
  189. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/luxon/LICENSE.txt +20 -0
  190. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/luxon/README.md +8 -0
  191. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/luxon/main.d.ts +14 -0
  192. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/luxon/main.esm.js +162 -0
  193. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/luxon/main.js +170 -0
  194. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/luxon/main.min.js +6 -0
  195. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/luxon/package.json +34 -0
  196. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/moment/LICENSE.txt +20 -0
  197. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/moment/README.md +8 -0
  198. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/moment/main.d.ts +14 -0
  199. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/moment/main.esm.js +102 -0
  200. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/moment/main.js +110 -0
  201. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/moment/main.min.js +6 -0
  202. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/moment/package.json +34 -0
  203. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/moment-timezone/LICENSE.txt +20 -0
  204. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/moment-timezone/README.md +8 -0
  205. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/moment-timezone/main.d.ts +11 -0
  206. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/moment-timezone/main.esm.js +58 -0
  207. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/moment-timezone/main.js +64 -0
  208. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/moment-timezone/main.min.js +6 -0
  209. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/moment-timezone/package.json +35 -0
  210. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/rrule/LICENSE.txt +20 -0
  211. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/rrule/README.md +8 -0
  212. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/rrule/main.d.ts +9 -0
  213. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/rrule/main.esm.js +121 -0
  214. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/rrule/main.js +128 -0
  215. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/rrule/main.min.js +6 -0
  216. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/rrule/package.json +34 -0
  217. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/timegrid/LICENSE.txt +20 -0
  218. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/timegrid/README.md +8 -0
  219. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/timegrid/main.css +309 -0
  220. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/timegrid/main.d.ts +220 -0
  221. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/timegrid/main.esm.js +1345 -0
  222. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/timegrid/main.js +1357 -0
  223. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/timegrid/main.min.css +1 -0
  224. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/timegrid/main.min.js +6 -0
  225. advanced_report_builder/static/advanced_report_builder/fullcalendar/packages/timegrid/package.json +36 -0
  226. advanced_report_builder/static/advanced_report_builder/fullcalendar/vendor/rrule.js +3782 -0
  227. advanced_report_builder/static/advanced_report_builder/jquery_extendext/js/jQuery.extendext.js +132 -0
  228. advanced_report_builder/static/advanced_report_builder/jquery_extendext/js/jQuery.extendext.min.js +9 -0
  229. advanced_report_builder/static/advanced_report_builder/moment/locales.js +9769 -0
  230. advanced_report_builder/static/advanced_report_builder/moment/locales.min.js +1 -0
  231. advanced_report_builder/static/advanced_report_builder/moment/moment-with-locales.js +14289 -0
  232. advanced_report_builder/static/advanced_report_builder/moment/moment-with-locales.min.js +1 -0
  233. advanced_report_builder/static/advanced_report_builder/moment/moment.min.js +1 -0
  234. advanced_report_builder/static/advanced_report_builder/query_builder/.DS_Store +0 -0
  235. advanced_report_builder/static/advanced_report_builder/query_builder/css/.DS_Store +0 -0
  236. advanced_report_builder/static/advanced_report_builder/query_builder/css/query-builder.dark.css +173 -0
  237. advanced_report_builder/static/advanced_report_builder/query_builder/css/query-builder.dark.min.css +6 -0
  238. advanced_report_builder/static/advanced_report_builder/query_builder/css/query-builder.default.css +173 -0
  239. advanced_report_builder/static/advanced_report_builder/query_builder/css/query-builder.default.min.css +6 -0
  240. advanced_report_builder/static/advanced_report_builder/query_builder/i18n/query-builder.ar.js +80 -0
  241. advanced_report_builder/static/advanced_report_builder/query_builder/i18n/query-builder.az.js +79 -0
  242. advanced_report_builder/static/advanced_report_builder/query_builder/i18n/query-builder.bg.js +79 -0
  243. advanced_report_builder/static/advanced_report_builder/query_builder/i18n/query-builder.cs.js +79 -0
  244. advanced_report_builder/static/advanced_report_builder/query_builder/i18n/query-builder.da.js +56 -0
  245. advanced_report_builder/static/advanced_report_builder/query_builder/i18n/query-builder.de.js +76 -0
  246. advanced_report_builder/static/advanced_report_builder/query_builder/i18n/query-builder.el.js +80 -0
  247. advanced_report_builder/static/advanced_report_builder/query_builder/i18n/query-builder.en.js +83 -0
  248. advanced_report_builder/static/advanced_report_builder/query_builder/i18n/query-builder.es.js +81 -0
  249. advanced_report_builder/static/advanced_report_builder/query_builder/i18n/query-builder.fa-IR.js +79 -0
  250. advanced_report_builder/static/advanced_report_builder/query_builder/i18n/query-builder.fr.js +83 -0
  251. advanced_report_builder/static/advanced_report_builder/query_builder/i18n/query-builder.he.js +81 -0
  252. advanced_report_builder/static/advanced_report_builder/query_builder/i18n/query-builder.it.js +79 -0
  253. advanced_report_builder/static/advanced_report_builder/query_builder/i18n/query-builder.nl.js +76 -0
  254. advanced_report_builder/static/advanced_report_builder/query_builder/i18n/query-builder.no.js +54 -0
  255. advanced_report_builder/static/advanced_report_builder/query_builder/i18n/query-builder.pl.js +80 -0
  256. advanced_report_builder/static/advanced_report_builder/query_builder/i18n/query-builder.pt-BR.js +80 -0
  257. advanced_report_builder/static/advanced_report_builder/query_builder/i18n/query-builder.pt-PT.js +75 -0
  258. advanced_report_builder/static/advanced_report_builder/query_builder/i18n/query-builder.ro.js +54 -0
  259. advanced_report_builder/static/advanced_report_builder/query_builder/i18n/query-builder.ru.js +77 -0
  260. advanced_report_builder/static/advanced_report_builder/query_builder/i18n/query-builder.sq.js +78 -0
  261. advanced_report_builder/static/advanced_report_builder/query_builder/i18n/query-builder.tr.js +82 -0
  262. advanced_report_builder/static/advanced_report_builder/query_builder/i18n/query-builder.ua.js +79 -0
  263. advanced_report_builder/static/advanced_report_builder/query_builder/i18n/query-builder.zh-CN.js +80 -0
  264. advanced_report_builder/static/advanced_report_builder/query_builder/js/.DS_Store +0 -0
  265. advanced_report_builder/static/advanced_report_builder/query_builder/js/plugins/.DS_Store +0 -0
  266. advanced_report_builder/static/advanced_report_builder/query_builder/js/plugins/currency/plugin.js +30 -0
  267. advanced_report_builder/static/advanced_report_builder/query_builder/js/query-builder.js +6200 -0
  268. advanced_report_builder/static/advanced_report_builder/query_builder/js/query-builder.min.js +7 -0
  269. advanced_report_builder/static/advanced_report_builder/query_builder/js/query-builder.standalone.js +6477 -0
  270. advanced_report_builder/static/advanced_report_builder/query_builder/js/query-builder.standalone.min.js +7 -0
  271. advanced_report_builder/static/advanced_report_builder/query_builder/scss/.DS_Store +0 -0
  272. advanced_report_builder/static/advanced_report_builder/query_builder/scss/dark.scss +19 -0
  273. advanced_report_builder/static/advanced_report_builder/query_builder/scss/default.scss +186 -0
  274. advanced_report_builder/static/advanced_report_builder/query_builder/scss/plugins/_bt-checkbox.scss +12 -0
  275. advanced_report_builder/static/advanced_report_builder/query_builder/scss/plugins/_bt-tooltip-errors.scss +9 -0
  276. advanced_report_builder/static/advanced_report_builder/query_builder/scss/plugins/_filter-description.scss +21 -0
  277. advanced_report_builder/static/advanced_report_builder/query_builder/scss/plugins/_invert.scss +5 -0
  278. advanced_report_builder/static/advanced_report_builder/query_builder/scss/plugins/_sortable.scss +28 -0
  279. advanced_report_builder/static/advanced_report_builder/query_builder/scss/plugins/bt-tooltip-errors.scss +9 -0
  280. advanced_report_builder/static/advanced_report_builder/query_builder/scss/plugins/filter-description.scss +21 -0
  281. advanced_report_builder/static/advanced_report_builder/query_builder/scss/plugins/invert.scss +5 -0
  282. advanced_report_builder/static/advanced_report_builder/query_builder/scss/plugins/sortable.scss +27 -0
  283. advanced_report_builder/template_types.py +34 -0
  284. advanced_report_builder/templates/advanced_report_builder/calendar/description_modal.html +12 -0
  285. advanced_report_builder/templates/advanced_report_builder/calendar/middle.html +33 -0
  286. advanced_report_builder/templates/advanced_report_builder/calendar/modal.html +10 -0
  287. advanced_report_builder/templates/advanced_report_builder/calendar/report.html +80 -0
  288. advanced_report_builder/templates/advanced_report_builder/charts/bar/middle.html +122 -0
  289. advanced_report_builder/templates/advanced_report_builder/charts/funnel/middle.html +46 -0
  290. advanced_report_builder/templates/advanced_report_builder/charts/funnel/report.html +34 -0
  291. advanced_report_builder/templates/advanced_report_builder/charts/line/middle.html +119 -0
  292. advanced_report_builder/templates/advanced_report_builder/charts/modal.html +12 -0
  293. advanced_report_builder/templates/advanced_report_builder/charts/modal_field.html +13 -0
  294. advanced_report_builder/templates/advanced_report_builder/charts/pie/middle.html +58 -0
  295. advanced_report_builder/templates/advanced_report_builder/charts/report.html +33 -0
  296. advanced_report_builder/templates/advanced_report_builder/data_merge/data_merge.html +144 -0
  297. advanced_report_builder/templates/advanced_report_builder/datatables/fields/modal.html +13 -0
  298. advanced_report_builder/templates/advanced_report_builder/datatables/fields/single_query_builder.html +87 -0
  299. advanced_report_builder/templates/advanced_report_builder/datatables/modal.html +13 -0
  300. advanced_report_builder/templates/advanced_report_builder/datatables/onclick_menu.html +14 -0
  301. advanced_report_builder/templates/advanced_report_builder/datatables/report.html +37 -0
  302. advanced_report_builder/templates/advanced_report_builder/datatables/select_pivot.html +199 -0
  303. advanced_report_builder/templates/advanced_report_builder/error.html +21 -0
  304. advanced_report_builder/templates/advanced_report_builder/extra_query_modal.html +13 -0
  305. advanced_report_builder/templates/advanced_report_builder/kanban/description_modal.html +12 -0
  306. advanced_report_builder/templates/advanced_report_builder/kanban/middle.html +63 -0
  307. advanced_report_builder/templates/advanced_report_builder/kanban/modal.html +10 -0
  308. advanced_report_builder/templates/advanced_report_builder/kanban/report.html +71 -0
  309. advanced_report_builder/templates/advanced_report_builder/multi_values/held_modal.html +14 -0
  310. advanced_report_builder/templates/advanced_report_builder/multi_values/middle.html +61 -0
  311. advanced_report_builder/templates/advanced_report_builder/multi_values/modal.html +15 -0
  312. advanced_report_builder/templates/advanced_report_builder/multi_values/report.html +19 -0
  313. advanced_report_builder/templates/advanced_report_builder/query_builder.html +88 -0
  314. advanced_report_builder/templates/advanced_report_builder/query_modal.html +12 -0
  315. advanced_report_builder/templates/advanced_report_builder/select_column.html +230 -0
  316. advanced_report_builder/templates/advanced_report_builder/single_values/gauge_middle.html +143 -0
  317. advanced_report_builder/templates/advanced_report_builder/single_values/middle.html +63 -0
  318. advanced_report_builder/templates/advanced_report_builder/single_values/modal.html +13 -0
  319. advanced_report_builder/templates/advanced_report_builder/single_values/report.html +56 -0
  320. advanced_report_builder/toggle.py +9 -0
  321. advanced_report_builder/urls.py +237 -0
  322. advanced_report_builder/utils.py +171 -0
  323. advanced_report_builder/variable_date.py +670 -0
  324. advanced_report_builder/view_types.py +27 -0
  325. advanced_report_builder/views/.DS_Store +0 -0
  326. advanced_report_builder/views/__init__.py +0 -0
  327. advanced_report_builder/views/bar_charts.py +746 -0
  328. advanced_report_builder/views/calendar.py +745 -0
  329. advanced_report_builder/views/charts_base.py +625 -0
  330. advanced_report_builder/views/custom.py +147 -0
  331. advanced_report_builder/views/dashboard.py +357 -0
  332. advanced_report_builder/views/datatables/__init__.py +0 -0
  333. advanced_report_builder/views/datatables/datatables.py +151 -0
  334. advanced_report_builder/views/datatables/modal.py +1151 -0
  335. advanced_report_builder/views/datatables/utils.py +701 -0
  336. advanced_report_builder/views/error_pod.py +50 -0
  337. advanced_report_builder/views/funnel_charts.py +289 -0
  338. advanced_report_builder/views/helpers.py +22 -0
  339. advanced_report_builder/views/kanban.py +868 -0
  340. advanced_report_builder/views/line_charts.py +415 -0
  341. advanced_report_builder/views/modals_base.py +213 -0
  342. advanced_report_builder/views/multi_value.py +1160 -0
  343. advanced_report_builder/views/pie_charts.py +290 -0
  344. advanced_report_builder/views/query_modal/__init__.py +0 -0
  345. advanced_report_builder/views/query_modal/mixin.py +161 -0
  346. advanced_report_builder/views/query_modal/modal.py +274 -0
  347. advanced_report_builder/views/report.py +241 -0
  348. advanced_report_builder/views/report_utils_mixin.py +312 -0
  349. advanced_report_builder/views/reports.py +154 -0
  350. advanced_report_builder/views/single_values.py +792 -0
  351. advanced_report_builder/views/targets/__init__.py +0 -0
  352. advanced_report_builder/views/targets/utils.py +251 -0
  353. advanced_report_builder/views/targets/views.py +139 -0
  354. advanced_report_builder/views/value_base.py +198 -0
  355. advanced_report_builder/widgets.py +5 -0
  356. django_advanced_report_builder-1.2.9.dist-info/METADATA +35 -0
  357. django_advanced_report_builder-1.2.9.dist-info/RECORD +360 -0
  358. django_advanced_report_builder-1.2.9.dist-info/WHEEL +5 -0
  359. django_advanced_report_builder-1.2.9.dist-info/licenses/LICENSE +21 -0
  360. django_advanced_report_builder-1.2.9.dist-info/top_level.txt +1 -0
@@ -0,0 +1,862 @@
1
+ import calendar
2
+ import datetime
3
+ import operator
4
+ from functools import reduce
5
+
6
+ from django.apps import apps
7
+ from django.conf import settings
8
+ from django.db.models import F, Q
9
+ from django.db.models.functions import ExtractWeekDay
10
+ from django.shortcuts import get_object_or_404
11
+
12
+ from advanced_report_builder.exceptions import ReportError
13
+ from advanced_report_builder.field_utils import ReportBuilderFieldUtils
14
+ from advanced_report_builder.models import ReportOption, ReportQuery
15
+ from advanced_report_builder.utils import get_report_builder_class, try_int
16
+ from advanced_report_builder.variable_date import VariableDate
17
+
18
+
19
+ class PeriodData:
20
+ min_date = None
21
+ max_date = None
22
+
23
+ def set_min_max_date(self, date_in):
24
+ dt = (
25
+ datetime.datetime.combine(date_in, datetime.datetime.min.time())
26
+ if isinstance(date_in, datetime.date) and not isinstance(date_in, datetime.datetime)
27
+ else date_in
28
+ )
29
+
30
+ if self.min_date is None or dt < self.min_date:
31
+ self.min_date = dt
32
+
33
+ if self.max_date is None or dt > self.max_date:
34
+ self.max_date = dt
35
+
36
+ def get_day_period(self):
37
+ if not self.min_date or not self.max_date:
38
+ return None
39
+
40
+ min_d = self.min_date.date()
41
+ max_d = self.max_date.date()
42
+
43
+ if min_d == max_d:
44
+ return min_d, max_d
45
+ return None
46
+
47
+ def get_week_period(self):
48
+ if not self.min_date or not self.max_date:
49
+ return None
50
+
51
+ min_d = self.min_date.date()
52
+ max_d = self.max_date.date()
53
+
54
+ if (max_d - min_d).days != 6:
55
+ return None
56
+
57
+ return min_d, max_d
58
+
59
+ def get_month_period(self):
60
+ if not self.min_date or not self.max_date:
61
+ return None
62
+
63
+ # Normalize to date (drop time)
64
+ min_d = self.min_date.date()
65
+ max_d = self.max_date.date()
66
+
67
+ # Check if in the same year and month
68
+ if min_d.year != max_d.year or min_d.month != max_d.month:
69
+ return None
70
+
71
+ # First day of the month
72
+ start_of_month = min_d.replace(day=1)
73
+
74
+ # Last day of the month
75
+ last_day = calendar.monthrange(max_d.year, max_d.month)[1]
76
+ end_of_month = max_d.replace(day=last_day)
77
+
78
+ if min_d == start_of_month and max_d == end_of_month:
79
+ return min_d, max_d
80
+ return None
81
+
82
+ def get_quarter_period(self):
83
+ if not self.min_date or not self.max_date:
84
+ return None
85
+
86
+ min_d = self.min_date.date()
87
+ max_d = self.max_date.date()
88
+
89
+ # Must start on first of a month
90
+ if min_d.day != 1:
91
+ return None
92
+
93
+ # Must end on last day of a month
94
+ last_day = calendar.monthrange(max_d.year, max_d.month)[1]
95
+ if max_d.day != last_day:
96
+ return None
97
+
98
+ # Calculate number of months spanned (inclusive)
99
+ months = (max_d.year - min_d.year) * 12 + (max_d.month - min_d.month) + 1
100
+
101
+ if months != 3:
102
+ return None
103
+
104
+ return min_d, max_d
105
+
106
+ def get_year_period(self):
107
+ if not self.min_date or not self.max_date:
108
+ return None
109
+
110
+ min_d = self.min_date.date()
111
+ max_d = self.max_date.date()
112
+
113
+ # Must start on first day of a month
114
+ if min_d.day != 1:
115
+ return None
116
+
117
+ # Must end on last day of a month
118
+ last_day = calendar.monthrange(max_d.year, max_d.month)[1]
119
+ if max_d.day != last_day:
120
+ return None
121
+
122
+ # Must span exactly 12 months
123
+ months = (max_d.year - min_d.year) * 12 + (max_d.month - min_d.month) + 1
124
+ if months != 12:
125
+ return None
126
+
127
+ return min_d, max_d
128
+
129
+
130
+ class FilterQueryMixin:
131
+ def __init__(self, *args, **kwargs):
132
+ self.report = None
133
+ self.dashboard_report = None
134
+ self.enable_edit = None
135
+ self.slug = None
136
+ self.base_model = None
137
+ self.period_data = PeriodData()
138
+ self._held_report_query = None
139
+ self._report_options_data = None
140
+ super().__init__(*args, **kwargs)
141
+
142
+ def process_query_filters(self, query, search_filter_data, extra_filter_data=None, extra_filter=None):
143
+ annotations = {}
144
+ result = self.process_filters(
145
+ search_filter_data=search_filter_data,
146
+ annotations=annotations,
147
+ extra_filter_data=extra_filter_data,
148
+ extra_filter=extra_filter,
149
+ )
150
+ if annotations:
151
+ query = query.annotate(**annotations)
152
+ if result:
153
+ return query.filter(result)
154
+ return query
155
+
156
+ def process_filters(
157
+ self, search_filter_data, extra_filter_data=None, annotations=None, extra_filter=None, prefix_field_name=None
158
+ ):
159
+ if not search_filter_data and not extra_filter_data:
160
+ return []
161
+
162
+ query_list = []
163
+ extra_query_list = []
164
+ reduce_by = operator.and_
165
+ if search_filter_data:
166
+ query_list = self._process_group(
167
+ query_data=search_filter_data, prefix_field_name=prefix_field_name, annotations=annotations
168
+ )
169
+ reduce_by = self._format_group_conditions(display_condition=search_filter_data['condition'])
170
+ if extra_filter_data:
171
+ extra_query_list = self._process_group(
172
+ query_data=extra_filter_data, prefix_field_name=prefix_field_name, annotations=annotations
173
+ )
174
+
175
+ if len(query_list) == 0:
176
+ query_list = extra_query_list
177
+ elif len(query_list) > 0 and len(extra_query_list) > 0:
178
+ query_list[0] = extra_query_list[0] & query_list[0]
179
+
180
+ if extra_filter:
181
+ query_list.append(extra_filter)
182
+
183
+ if query_list:
184
+ return reduce(reduce_by, query_list)
185
+ return []
186
+
187
+ @staticmethod
188
+ def _get_operator(display_operator):
189
+ """
190
+ Converts the display operators into operators for the Q object.
191
+ :param display_operator:
192
+ :return:
193
+ """
194
+
195
+ operators_dict = {
196
+ 'equal': '',
197
+ 'not_equal': '', # Not equals is now done by inverting the individual Q object. (for dates).
198
+ 'less': '__lt',
199
+ 'less_or_equal': '__lte',
200
+ 'greater': '__gt',
201
+ 'greater_or_equal': '__gte',
202
+ 'contains': '__icontains',
203
+ 'not_contains': '__icontains',
204
+ 'begins_with': '__istartswith',
205
+ 'not_begins_with': '__istartswith',
206
+ 'ends_with': '__iendswith',
207
+ 'not_ends_with': '__iendswith',
208
+ 'in': '__in',
209
+ 'not_in': '__in',
210
+ 'is_null': '__isnull',
211
+ 'is_not_null': '__isnull',
212
+ }
213
+
214
+ query_operator = operators_dict.get(display_operator)
215
+ return query_operator
216
+
217
+ @staticmethod
218
+ def _format_group_conditions(display_condition):
219
+ """
220
+ Converts the display condition from the javascript into a condition for the Q object.
221
+ :param display_condition:
222
+ :return:
223
+ """
224
+ reduce_by = operator.and_ if display_condition == 'AND' else operator.or_
225
+
226
+ return reduce_by
227
+
228
+ def _process_group(self, query_data, prefix_field_name, annotations):
229
+ query_list = []
230
+
231
+ for rule in query_data['rules']:
232
+ if condition := rule.get('condition'):
233
+ reduce_by = self._format_group_conditions(display_condition=condition)
234
+ sub_query_list = self._process_group(
235
+ query_data=rule, prefix_field_name=prefix_field_name, annotations=annotations
236
+ )
237
+ if sub_query_list:
238
+ query_list.append(reduce(reduce_by, sub_query_list))
239
+ continue
240
+
241
+ field = rule['field']
242
+ if prefix_field_name is not None:
243
+ field = prefix_field_name + '__' + field
244
+ _id = rule['id']
245
+ display_operator = rule['operator']
246
+ query_string = field + self._get_operator(display_operator)
247
+ data_type = rule['type']
248
+ value = rule.get('value', '')
249
+ if display_operator == 'is_null':
250
+ value = True
251
+ elif display_operator == 'is_not_null':
252
+ value = False
253
+
254
+ if _id.endswith('__field_vs_field'):
255
+ self.field_vs_field(
256
+ value=value, query_list=query_list, display_operator=display_operator, query_string=query_string
257
+ )
258
+ elif data_type == 'string' and _id.endswith('__variable_date'):
259
+ self.get_variable_date(
260
+ value=value,
261
+ query_list=query_list,
262
+ display_operator=display_operator,
263
+ field=field,
264
+ query_string=query_string,
265
+ )
266
+ elif data_type == 'string' and _id.endswith('__variable_year'):
267
+ self.get_variable_year(
268
+ value=value,
269
+ query_list=query_list,
270
+ display_operator=display_operator,
271
+ field=field,
272
+ query_string=query_string,
273
+ )
274
+ elif data_type == 'string' and _id.endswith('__financial_variable_year'):
275
+ self.get_variable_financial_year(
276
+ value=value,
277
+ query_list=query_list,
278
+ display_operator=display_operator,
279
+ field=field,
280
+ query_string=query_string,
281
+ )
282
+ elif data_type == 'string' and _id.endswith('__variable_month'):
283
+ self.get_variable_month(
284
+ value=value,
285
+ query_list=query_list,
286
+ display_operator=display_operator,
287
+ field=field,
288
+ query_string=query_string,
289
+ )
290
+ elif data_type == 'string' and _id.endswith('__variable_quarter'):
291
+ self.get_variable_quarter(
292
+ value=value,
293
+ query_list=query_list,
294
+ display_operator=display_operator,
295
+ field=field,
296
+ query_string=query_string,
297
+ )
298
+ elif data_type == 'string' and _id.endswith('__variable_day'):
299
+ self.get_variable_day(
300
+ value=value,
301
+ query_list=query_list,
302
+ display_operator=display_operator,
303
+ field=field,
304
+ annotations=annotations,
305
+ )
306
+ elif data_type == 'string' and _id.endswith('__week_number'):
307
+ self.get_week_number(
308
+ value=value,
309
+ query_list=query_list,
310
+ display_operator=display_operator,
311
+ field=field,
312
+ query_string=query_string,
313
+ )
314
+ elif data_type == 'string' and _id.endswith('__financial_week_number'):
315
+ fy_start = self.get_financial_year(rules=query_data['rules'])
316
+ self.get_financial_week_number(
317
+ value=value,
318
+ query_list=query_list,
319
+ display_operator=display_operator,
320
+ field=field,
321
+ query_string=query_string,
322
+ fy_start=fy_start,
323
+ )
324
+
325
+ elif data_type == 'string' and _id.endswith('__logged_in_user'):
326
+ self.get_logged_in_user(
327
+ value=value,
328
+ query_list=query_list,
329
+ display_operator=display_operator,
330
+ query_string=query_string,
331
+ )
332
+ else:
333
+ # 'Normal' Query.
334
+ if display_operator in [
335
+ 'not_equal',
336
+ 'not_in',
337
+ 'not_contains',
338
+ 'not_begins_with',
339
+ 'not_ends_with',
340
+ ]:
341
+ query_list.append(~Q((query_string, value)))
342
+ else:
343
+ query_list.append(Q((query_string, value)))
344
+
345
+ return query_list
346
+
347
+ def get_financial_year(self, rules):
348
+ for rule in rules:
349
+ if 'condition' in rule:
350
+ continue
351
+
352
+ if rule['operator'] != 'equal':
353
+ continue
354
+
355
+ data_type = rule['type']
356
+ value = rule.get('value')
357
+ _id = rule['id']
358
+
359
+ # 1) Variable Date → Financial Year
360
+ if data_type == 'string' and _id.endswith('__variable_date'):
361
+ _, range_type = str(value).split(':')
362
+ range_type = int(range_type)
363
+
364
+ if range_type in (
365
+ VariableDate.RANGE_TYPE_LAST_FINANCIAL_YEAR,
366
+ VariableDate.RANGE_TYPE_THIS_FINANCIAL_YEAR,
367
+ VariableDate.RANGE_TYPE_NEXT_FINANCIAL_YEAR,
368
+ ):
369
+ variable_date = VariableDate()
370
+ dates = variable_date.get_variable_dates(
371
+ range_type=range_type,
372
+ financial_year_start_month=self.get_financial_month(),
373
+ )
374
+ return dates[0]
375
+
376
+ # 2) Explicit Financial Year (value IS the year)
377
+ elif data_type == 'string' and _id.endswith('__financial_variable_year'):
378
+ _, year = str(value).split(':')
379
+ year = int(year)
380
+ start_month = self.get_financial_month()
381
+ return datetime.date(year, start_month, 1)
382
+
383
+ return None
384
+
385
+ @staticmethod
386
+ def field_vs_field(value, query_list, display_operator, query_string):
387
+ if display_operator == 'not_equal':
388
+ query_list.append(~Q(**{query_string: F(value)}))
389
+ else:
390
+ query_list.append(Q(**{query_string: F(value)}))
391
+
392
+ def set_min_max_date(self, date_in):
393
+ self.period_data.set_min_max_date(date_in)
394
+
395
+ def get_variable_date(self, value, query_list, display_operator, field, query_string):
396
+ if display_operator in ['is_null', 'is_not_null']:
397
+ query_list.append(Q((query_string, value)))
398
+ else:
399
+ _, range_type = value.split(':')
400
+ variable_date = VariableDate()
401
+ value = variable_date.get_variable_dates(
402
+ range_type=int(range_type), financial_year_start_month=self.get_financial_month()
403
+ )
404
+
405
+ if display_operator in ['less', 'greater_or_equal']:
406
+ query_list.append(Q((query_string, value[0])))
407
+ if display_operator == 'less':
408
+ self.set_min_max_date(date_in=value[0])
409
+ else:
410
+ self.set_min_max_date(date_in=value[0])
411
+ self.set_min_max_date(date_in=value[1])
412
+
413
+ elif display_operator in ['greater', 'less_or_equal']:
414
+ query_list.append(Q((query_string, value[1])))
415
+ if display_operator == 'greater':
416
+ self.set_min_max_date(date_in=value[1])
417
+ else:
418
+ self.set_min_max_date(date_in=value[0])
419
+ self.set_min_max_date(date_in=value[1])
420
+ elif display_operator in ['not_equal', 'not_in']:
421
+ query_list.append(~((Q((field + '__gte', value[0]))) & (Q((field + '__lte', value[1])))))
422
+ else:
423
+ query_list.append((Q((field + '__gte', value[0]))) & (Q((field + '__lte', value[1]))))
424
+ self.set_min_max_date(date_in=value[0])
425
+ self.set_min_max_date(date_in=value[1])
426
+
427
+ def get_variable_year(self, value, query_list, display_operator, field, query_string):
428
+ if display_operator in ['is_null', 'is_not_null']:
429
+ query_list.append(Q((query_string, value)))
430
+ else:
431
+ _, year = value.split(':')
432
+ year = int(year)
433
+ start_date = datetime.date(year, 1, 1)
434
+ end_date = datetime.date(year, 12, 31)
435
+
436
+ if display_operator in [
437
+ 'less',
438
+ 'less_or_equal',
439
+ 'greater',
440
+ 'greater_or_equal',
441
+ ]:
442
+ query_string_parts = query_string.split('__')
443
+ query_list.append(Q((f'{field}__year__{query_string_parts[-1]}', year)))
444
+
445
+ if display_operator == 'greater':
446
+ self.set_min_max_date(date_in=end_date)
447
+ elif display_operator == 'less':
448
+ self.set_min_max_date(date_in=start_date)
449
+ else:
450
+ self.set_min_max_date(date_in=start_date)
451
+ self.set_min_max_date(date_in=end_date)
452
+
453
+ elif display_operator in ['not_equal', 'not_in']:
454
+ query_list.append(~Q((query_string + '__year', year)))
455
+ else:
456
+ query_list.append(Q((query_string + '__year', year)))
457
+ self.set_min_max_date(date_in=start_date)
458
+ self.set_min_max_date(date_in=end_date)
459
+
460
+ def get_variable_financial_year(
461
+ self,
462
+ value,
463
+ query_list,
464
+ display_operator,
465
+ field,
466
+ query_string,
467
+ ):
468
+ if display_operator in ['is_null', 'is_not_null']:
469
+ query_list.append(Q((query_string, value)))
470
+ return
471
+
472
+ _, year = value.split(':')
473
+ year = int(year)
474
+
475
+ start_month = self.get_financial_month()
476
+
477
+ start_date = datetime.date(year, start_month, 1)
478
+ end_date = datetime.date(year + 1, start_month, 1) - datetime.timedelta(days=1)
479
+
480
+ if display_operator in [
481
+ 'less',
482
+ 'less_or_equal',
483
+ 'greater',
484
+ 'greater_or_equal',
485
+ ]:
486
+ if display_operator == 'less':
487
+ query_list.append(Q(**{f'{field}__lt': start_date}))
488
+ self.set_min_max_date(date_in=start_date)
489
+
490
+ elif display_operator == 'less_or_equal':
491
+ query_list.append(Q(**{f'{field}__lte': end_date}))
492
+ self.set_min_max_date(date_in=end_date)
493
+
494
+ elif display_operator == 'greater':
495
+ query_list.append(Q(**{f'{field}__gt': end_date}))
496
+ self.set_min_max_date(date_in=end_date)
497
+
498
+ elif display_operator == 'greater_or_equal':
499
+ query_list.append(Q(**{f'{field}__gte': start_date}))
500
+ self.set_min_max_date(date_in=start_date)
501
+
502
+ elif display_operator in ['not_equal', 'not_in']:
503
+ query_list.append(~(Q(**{f'{field}__gte': start_date}) & Q(**{f'{field}__lte': end_date})))
504
+
505
+ else: # equal / in
506
+ query_list.append(Q(**{f'{field}__gte': start_date}) & Q(**{f'{field}__lte': end_date}))
507
+ self.set_min_max_date(date_in=start_date)
508
+ self.set_min_max_date(date_in=end_date)
509
+
510
+ @staticmethod
511
+ def get_variable_month(value, query_list, display_operator, field, query_string):
512
+ if display_operator in ['is_null', 'is_not_null']:
513
+ query_list.append(Q((query_string, value)))
514
+ else:
515
+ _, month = value.split(':')
516
+ month = int(month)
517
+ if display_operator in ['not_equal', 'not_in']:
518
+ query_list.append(~Q((field + '__month', month)))
519
+ else:
520
+ query_list.append(Q((field + '__month', month)))
521
+
522
+ def get_variable_quarter(self, value, query_list, display_operator, field, query_string):
523
+ if display_operator in ['is_null', 'is_not_null']:
524
+ query_list.append(Q((query_string, value)))
525
+ else:
526
+ quarter_type, quarter = value.split(':')
527
+ quarter = int(quarter)
528
+ if quarter_type == '#quarter':
529
+ start_month = (quarter - 1) * 3
530
+ end_month = start_month + 3
531
+ if display_operator == 'not_equal':
532
+ query_list.append(
533
+ ~((Q((field + '__month__gt', start_month))) & (Q((field + '__month__lte', end_month))))
534
+ )
535
+ else:
536
+ query_list.append(
537
+ (Q((field + '__month__gt', start_month))) & (Q((field + '__month__lte', end_month)))
538
+ )
539
+ else:
540
+ start_month = self.get_financial_month() - 1
541
+ end_month = start_month + 3
542
+ months = [divmod(x, 12)[1] + 1 for x in range(start_month, end_month)]
543
+
544
+ if display_operator == 'not_equal':
545
+ query_list.append(
546
+ ~(
547
+ (Q((field + '__month', months[0])))
548
+ | (Q((field + '__month', months[1])))
549
+ | (Q((field + '__month', months[2])))
550
+ )
551
+ )
552
+ else:
553
+ query_list.append(
554
+ (Q((field + '__month', months[0])))
555
+ | (Q((field + '__month', months[1])))
556
+ | (Q((field + '__month', months[2])))
557
+ )
558
+
559
+ @staticmethod
560
+ def get_variable_day(value, query_list, display_operator, field, annotations):
561
+ if annotations is None:
562
+ # maybe create a warning. As this won't work with sub queries
563
+ return
564
+
565
+ annotate_name = f'{field}_weekday'
566
+ annotations[annotate_name] = ExtractWeekDay(field)
567
+ if display_operator == 'not_equal':
568
+ query_list.append(~Q(**{f'{annotate_name}': value}))
569
+ else:
570
+ query_list.append(Q(**{f'{annotate_name}': value}))
571
+
572
+ @staticmethod
573
+ def get_week_number(value, query_list, display_operator, field, query_string):
574
+ if display_operator in ['is_null', 'is_not_null']:
575
+ query_list.append(Q((query_string, value)))
576
+ return
577
+
578
+ week = int(value)
579
+
580
+ operator_map = {
581
+ 'equal': '',
582
+ 'not_equal': '',
583
+ 'less': '__lt',
584
+ 'less_or_equal': '__lte',
585
+ 'greater': '__gt',
586
+ 'greater_or_equal': '__gte',
587
+ }
588
+
589
+ lookup = operator_map.get(display_operator)
590
+ if lookup is None:
591
+ return
592
+
593
+ key = f'{field}__week{lookup}'
594
+ q = Q(**{key: week})
595
+
596
+ if display_operator == 'not_equal':
597
+ query_list.append(~q)
598
+ else:
599
+ query_list.append(q)
600
+
601
+ @staticmethod
602
+ def get_financial_week_number(
603
+ value,
604
+ query_list,
605
+ display_operator,
606
+ field,
607
+ query_string,
608
+ *,
609
+ fy_start,
610
+ ):
611
+ """
612
+ Applies a Financial Week Number filter.
613
+
614
+ Financial weeks are calculated relative to the financial year start date.
615
+ Week 1 begins at fy_start and each week spans 7 days.
616
+ """
617
+
618
+ if display_operator in ['is_null', 'is_not_null']:
619
+ query_list.append(Q((query_string, value)))
620
+ return
621
+
622
+ if fy_start is None:
623
+ raise ReportError(
624
+ 'Financial Week Number requires a Financial Year '
625
+ '(select a Financial Year or use a Financial Year date range).'
626
+ )
627
+
628
+ week = int(value)
629
+
630
+ if not 1 <= week <= 53:
631
+ raise ReportError('Financial Week Number must be between 1 and 53')
632
+
633
+ week_start = fy_start + datetime.timedelta(days=(week - 1) * 7)
634
+ week_end = week_start + datetime.timedelta(days=7)
635
+
636
+ if display_operator == 'equal':
637
+ query_list.append(Q(**{f'{field}__gte': week_start}) & Q(**{f'{field}__lt': week_end}))
638
+
639
+ elif display_operator == 'not_equal':
640
+ query_list.append(~(Q(**{f'{field}__gte': week_start}) & Q(**{f'{field}__lt': week_end})))
641
+
642
+ elif display_operator == 'less':
643
+ query_list.append(Q(**{f'{field}__lt': week_start}))
644
+
645
+ elif display_operator == 'less_or_equal':
646
+ query_list.append(Q(**{f'{field}__lt': week_end}))
647
+
648
+ elif display_operator == 'greater':
649
+ query_list.append(Q(**{f'{field}__gte': week_end}))
650
+
651
+ elif display_operator == 'greater_or_equal':
652
+ query_list.append(Q(**{f'{field}__gte': week_start}))
653
+
654
+ def get_logged_in_user(self, value, query_list, display_operator, query_string):
655
+ # noinspection PyUnresolvedReferences
656
+ current_user = self.request.user
657
+ value = value == '1'
658
+ if (display_operator == 'equal' and value) or (display_operator == 'not_equal' and not value):
659
+ query_list.append(Q((query_string, current_user)))
660
+ else:
661
+ query_list.append(~Q((query_string, current_user)))
662
+
663
+ def get_report_query(self, report):
664
+ if self._held_report_query is not None:
665
+ return self._held_report_query
666
+
667
+ dashboard_report = self.dashboard_report
668
+ if dashboard_report is not None:
669
+ slug_key = self.slug.get(f'query{report.pk}_{dashboard_report.pk}')
670
+ else:
671
+ slug_key = self.slug.get(f'query{report.pk}')
672
+ if slug_key:
673
+ report_query = get_object_or_404(ReportQuery, id=slug_key)
674
+ if report_query.report_id != report.pk:
675
+ return None
676
+ else:
677
+ if dashboard_report is not None and dashboard_report.report_query is not None:
678
+ report_query = dashboard_report.report_query
679
+ else:
680
+ report_query = report.reportquery_set.first()
681
+ self._held_report_query = report_query
682
+ return self._held_report_query
683
+
684
+ @staticmethod
685
+ def apply_order_by(query, report_query, base_model, report_type):
686
+ order_by = []
687
+ utils = ReportBuilderFieldUtils()
688
+ report_builder_class = get_report_builder_class(model=base_model, report_type=report_type)
689
+ for report_query_order in report_query.reportqueryorder_set.all():
690
+ field_name = report_query_order.order_by_field
691
+ field_name = utils.get_field_details(
692
+ base_model=base_model,
693
+ field=field_name,
694
+ report_builder_class=report_builder_class,
695
+ )[3]
696
+ if report_query_order.order_by_ascending:
697
+ order_by.append(field_name)
698
+ else:
699
+ order_by.append(f'-{field_name}')
700
+ if len(order_by) > 0:
701
+ query = query.order_by(*order_by)
702
+ return query
703
+
704
+ def get_title(self):
705
+ if self.dashboard_report and self.dashboard_report.name_override:
706
+ return self.dashboard_report.name_override
707
+ else:
708
+ title = self.report.name
709
+ extra_title_parts = []
710
+ report_queries_count = self.report.reportquery_set.all().count()
711
+ if report_queries_count > 1:
712
+ version_name = self.get_report_query(report=self.report).name
713
+ extra_title_parts.append(version_name)
714
+ report_options_data = self.get_report_options_data()
715
+ report_options = report_options_data['report_options']
716
+ report_options_dict = report_options_data['report_options_dict']
717
+
718
+ for report_option in report_options:
719
+ base_model = report_option.content_type.model_class()
720
+ report_cls = get_report_builder_class(
721
+ model=base_model, class_name=report_option.report_builder_class_name
722
+ )
723
+
724
+ _obj = base_model.objects.filter(pk=report_options_dict.get(report_option.pk)).first()
725
+ if _obj is not None:
726
+ method = getattr(_obj, report_cls.option_label, None)
727
+ label = method() if callable(method) else _obj.__str__()
728
+ extra_title_parts.append(label)
729
+
730
+ if extra_title_parts:
731
+ extra_title_parts = ' - '.join(extra_title_parts)
732
+ title = f'{title} ({extra_title_parts})'
733
+
734
+ return title
735
+
736
+ def get_report_option_query(self):
737
+ report_options_data = self.get_report_options_data()
738
+ report_options = report_options_data['report_options']
739
+ report_options_dict = report_options_data['report_options_dict']
740
+ # build query
741
+ query = Q()
742
+
743
+ for report_option in report_options:
744
+ value = report_options_dict.get(report_option.id)
745
+ if value:
746
+ query &= Q(**{f'{report_option.field}_id': value})
747
+
748
+ return query
749
+
750
+ def get_report_options_data(self):
751
+ if self._report_options_data is None:
752
+ report_options_dict = {}
753
+ dashboard_report = self.dashboard_report
754
+ dashboard_report_id = dashboard_report.id if dashboard_report else None
755
+
756
+ # dashboard-level overrides (primary)
757
+ if dashboard_report and dashboard_report.options:
758
+ for k, v in dashboard_report.options.items():
759
+ if not k.startswith('option'):
760
+ continue
761
+ try:
762
+ key = int(k[len('option') :])
763
+ except ValueError:
764
+ continue
765
+ report_options_dict[key] = try_int(v)
766
+
767
+ if self.slug is not None:
768
+ # options from slug
769
+ for k, v in self.slug.items():
770
+ if not k.startswith('option'):
771
+ continue
772
+ key = k[len('option') :]
773
+ if isinstance(key, str) and '_' in key:
774
+ key, option_database_board_id = key.split('_', 1)
775
+ if dashboard_report_id != try_int(option_database_board_id):
776
+ continue
777
+ key = try_int(key)
778
+ report_options_dict[key] = try_int(v)
779
+
780
+ report_options = ReportOption.objects.filter(report=self.report, id__in=report_options_dict.keys())
781
+ self._report_options_data = {'report_options': report_options, 'report_options_dict': report_options_dict}
782
+
783
+ return self._report_options_data
784
+
785
+ def _get_report_builder_class(self, base_model, field_str, report_builder_class, previous_base_model=None):
786
+ if '__' in field_str:
787
+ field_parts = field_str.split('__')
788
+ include_str = field_parts[0]
789
+ new_field_str = '__'.join(field_parts[1:])
790
+
791
+ include = report_builder_class.includes.get(include_str)
792
+
793
+ if include is not None:
794
+ app_label, model, report_builder_fields_str = include['model'].split('.')
795
+ new_model = apps.get_model(app_label, model)
796
+
797
+ new_report_builder_class = get_report_builder_class(
798
+ model=new_model, class_name=report_builder_fields_str
799
+ )
800
+
801
+ if new_model != previous_base_model:
802
+ result = self._get_report_builder_class(
803
+ base_model=new_model,
804
+ field_str=new_field_str,
805
+ report_builder_class=new_report_builder_class,
806
+ previous_base_model=base_model,
807
+ )
808
+ if result:
809
+ return result
810
+ else:
811
+ include = report_builder_class.includes.get(field_str)
812
+ if include is not None:
813
+ app_label, model, report_builder_fields_str = include['model'].split('.')
814
+ new_model = apps.get_model(app_label, model)
815
+ new_report_builder_class = get_report_builder_class(
816
+ model=new_model, class_name=report_builder_fields_str
817
+ )
818
+
819
+ return new_report_builder_class
820
+ return None
821
+
822
+ def _get_pivot_details(
823
+ self,
824
+ base_model,
825
+ pivot_str,
826
+ report_builder_class,
827
+ previous_base_model=None,
828
+ include_str='',
829
+ ):
830
+ if pivot_str in report_builder_class.pivot_fields:
831
+ pivot_data = report_builder_class.pivot_fields[pivot_str]
832
+ full_field_id = pivot_data['field'] if include_str == '' else '__'.join((include_str, pivot_data['field']))
833
+
834
+ return {'id': full_field_id, 'details': pivot_data}
835
+
836
+ if '__' in pivot_str:
837
+ pivot_parts = pivot_str.split('__')
838
+ include_str = pivot_parts[0]
839
+ new_pivot_str = '__'.join(pivot_parts[1:])
840
+
841
+ include = report_builder_class.includes.get(include_str)
842
+ if include is not None:
843
+ app_label, model, report_builder_fields_str = include['model'].split('.')
844
+ new_model = apps.get_model(app_label, model)
845
+ new_report_builder_class = get_report_builder_class(
846
+ model=new_model, class_name=report_builder_fields_str
847
+ )
848
+ if new_model != previous_base_model:
849
+ result = self._get_pivot_details(
850
+ base_model=new_model,
851
+ pivot_str=new_pivot_str,
852
+ report_builder_class=new_report_builder_class,
853
+ previous_base_model=base_model,
854
+ include_str=include_str,
855
+ )
856
+ if result:
857
+ return result
858
+ return None
859
+
860
+ def get_financial_month(self):
861
+ month = getattr(settings, 'FINANCIAL_YEAR_START_MONTH', 1)
862
+ return month if 1 <= month <= 12 else 1