0001_initial.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. from django.conf import settings
  2. import django.contrib.postgres.fields
  3. import django.core.validators
  4. from django.db import migrations, models
  5. import django.db.models.deletion
  6. import extras.fields
  7. import extras.models.customfields
  8. import extras.models.mixins
  9. import extras.utils
  10. import re
  11. import taggit.managers
  12. import utilities.fields
  13. import utilities.json
  14. import utilities.validators
  15. import uuid
  16. class Migration(migrations.Migration):
  17. initial = True
  18. dependencies = [
  19. ('core', '0001_initial'),
  20. migrations.swappable_dependency(settings.AUTH_USER_MODEL),
  21. ('contenttypes', '0002_remove_content_type_name'),
  22. ]
  23. operations = [
  24. migrations.CreateModel(
  25. name='Report',
  26. fields=[
  27. ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
  28. ],
  29. options={
  30. 'managed': False,
  31. },
  32. ),
  33. migrations.CreateModel(
  34. name='Script',
  35. fields=[
  36. ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
  37. ],
  38. options={
  39. 'managed': False,
  40. },
  41. ),
  42. migrations.CreateModel(
  43. name='Bookmark',
  44. fields=[
  45. ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
  46. ('created', models.DateTimeField(auto_now_add=True)),
  47. ('object_id', models.PositiveBigIntegerField()),
  48. ],
  49. options={
  50. 'verbose_name': 'bookmark',
  51. 'verbose_name_plural': 'bookmarks',
  52. 'ordering': ('created', 'pk'),
  53. },
  54. ),
  55. migrations.CreateModel(
  56. name='Branch',
  57. fields=[
  58. ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
  59. ('created', models.DateTimeField(auto_now_add=True, null=True)),
  60. ('last_updated', models.DateTimeField(auto_now=True, null=True)),
  61. ('name', models.CharField(max_length=100, unique=True)),
  62. ('description', models.CharField(blank=True, max_length=200)),
  63. ],
  64. options={
  65. 'verbose_name': 'branch',
  66. 'verbose_name_plural': 'branches',
  67. 'ordering': ('name',),
  68. },
  69. ),
  70. migrations.CreateModel(
  71. name='CachedValue',
  72. fields=[
  73. ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
  74. ('timestamp', models.DateTimeField(auto_now_add=True)),
  75. ('object_id', models.PositiveBigIntegerField()),
  76. ('field', models.CharField(max_length=200)),
  77. ('type', models.CharField(max_length=30)),
  78. ('value', extras.fields.CachedValueField()),
  79. ('weight', models.PositiveSmallIntegerField(default=1000)),
  80. ],
  81. options={
  82. 'verbose_name': 'cached value',
  83. 'verbose_name_plural': 'cached values',
  84. 'ordering': ('weight', 'object_type', 'object_id'),
  85. },
  86. ),
  87. migrations.CreateModel(
  88. name='ConfigContext',
  89. fields=[
  90. ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
  91. ('created', models.DateTimeField(auto_now_add=True, null=True)),
  92. ('last_updated', models.DateTimeField(auto_now=True, null=True)),
  93. ('data_path', models.CharField(blank=True, editable=False, max_length=1000)),
  94. ('auto_sync_enabled', models.BooleanField(default=False)),
  95. ('data_synced', models.DateTimeField(blank=True, editable=False, null=True)),
  96. ('name', models.CharField(max_length=100, unique=True)),
  97. ('weight', models.PositiveSmallIntegerField(default=1000)),
  98. ('description', models.CharField(blank=True, max_length=200)),
  99. ('is_active', models.BooleanField(default=True)),
  100. ('data', models.JSONField()),
  101. ],
  102. options={
  103. 'verbose_name': 'config context',
  104. 'verbose_name_plural': 'config contexts',
  105. 'ordering': ['weight', 'name'],
  106. },
  107. ),
  108. migrations.CreateModel(
  109. name='ConfigRevision',
  110. fields=[
  111. ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
  112. ('created', models.DateTimeField(auto_now_add=True)),
  113. ('comment', models.CharField(blank=True, max_length=200)),
  114. ('data', models.JSONField(blank=True, null=True)),
  115. ],
  116. options={
  117. 'verbose_name': 'config revision',
  118. 'verbose_name_plural': 'config revisions',
  119. 'ordering': ['-created'],
  120. },
  121. ),
  122. migrations.CreateModel(
  123. name='CustomFieldChoiceSet',
  124. fields=[
  125. ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
  126. ('created', models.DateTimeField(auto_now_add=True, null=True)),
  127. ('last_updated', models.DateTimeField(auto_now=True, null=True)),
  128. ('name', models.CharField(max_length=100, unique=True)),
  129. ('description', models.CharField(blank=True, max_length=200)),
  130. ('base_choices', models.CharField(blank=True, max_length=50)),
  131. ('extra_choices', django.contrib.postgres.fields.ArrayField(base_field=django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=100), size=2), blank=True, null=True, size=None)),
  132. ('order_alphabetically', models.BooleanField(default=False)),
  133. ],
  134. options={
  135. 'verbose_name': 'custom field choice set',
  136. 'verbose_name_plural': 'custom field choice sets',
  137. 'ordering': ('name',),
  138. },
  139. ),
  140. migrations.CreateModel(
  141. name='Tag',
  142. fields=[
  143. ('name', models.CharField(max_length=100, unique=True)),
  144. ('slug', models.SlugField(allow_unicode=True, max_length=100, unique=True)),
  145. ('created', models.DateTimeField(auto_now_add=True, null=True)),
  146. ('last_updated', models.DateTimeField(auto_now=True, null=True)),
  147. ('id', models.BigAutoField(primary_key=True, serialize=False)),
  148. ('color', utilities.fields.ColorField(default='9e9e9e', max_length=6)),
  149. ('description', models.CharField(blank=True, max_length=200)),
  150. ('object_types', models.ManyToManyField(blank=True, related_name='+', to='contenttypes.contenttype')),
  151. ],
  152. options={
  153. 'verbose_name': 'tag',
  154. 'verbose_name_plural': 'tags',
  155. 'ordering': ['name'],
  156. },
  157. ),
  158. migrations.CreateModel(
  159. name='TaggedItem',
  160. fields=[
  161. ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
  162. ('object_id', models.IntegerField(db_index=True)),
  163. ('content_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='%(app_label)s_%(class)s_tagged_items', to='contenttypes.contenttype')),
  164. ('tag', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='%(app_label)s_%(class)s_items', to='extras.tag')),
  165. ],
  166. options={
  167. 'verbose_name': 'tagged item',
  168. 'verbose_name_plural': 'tagged items',
  169. },
  170. ),
  171. migrations.CreateModel(
  172. name='ReportModule',
  173. fields=[
  174. ],
  175. options={
  176. 'verbose_name': 'report module',
  177. 'verbose_name_plural': 'report modules',
  178. 'proxy': True,
  179. 'indexes': [],
  180. 'constraints': [],
  181. },
  182. bases=(extras.models.mixins.PythonModuleMixin, 'core.managedfile', models.Model),
  183. ),
  184. migrations.CreateModel(
  185. name='ScriptModule',
  186. fields=[
  187. ],
  188. options={
  189. 'verbose_name': 'script module',
  190. 'verbose_name_plural': 'script modules',
  191. 'proxy': True,
  192. 'indexes': [],
  193. 'constraints': [],
  194. },
  195. bases=(extras.models.mixins.PythonModuleMixin, 'core.managedfile', models.Model),
  196. ),
  197. migrations.CreateModel(
  198. name='Webhook',
  199. fields=[
  200. ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
  201. ('created', models.DateTimeField(auto_now_add=True, null=True)),
  202. ('last_updated', models.DateTimeField(auto_now=True, null=True)),
  203. ('custom_field_data', models.JSONField(blank=True, default=dict, encoder=utilities.json.CustomFieldJSONEncoder)),
  204. ('name', models.CharField(max_length=150, unique=True)),
  205. ('type_create', models.BooleanField(default=False)),
  206. ('type_update', models.BooleanField(default=False)),
  207. ('type_delete', models.BooleanField(default=False)),
  208. ('type_job_start', models.BooleanField(default=False)),
  209. ('type_job_end', models.BooleanField(default=False)),
  210. ('payload_url', models.CharField(max_length=500)),
  211. ('enabled', models.BooleanField(default=True)),
  212. ('http_method', models.CharField(default='POST', max_length=30)),
  213. ('http_content_type', models.CharField(default='application/json', max_length=100)),
  214. ('additional_headers', models.TextField(blank=True)),
  215. ('body_template', models.TextField(blank=True)),
  216. ('secret', models.CharField(blank=True, max_length=255)),
  217. ('conditions', models.JSONField(blank=True, null=True)),
  218. ('ssl_verification', models.BooleanField(default=True)),
  219. ('ca_file_path', models.CharField(blank=True, max_length=4096, null=True)),
  220. ('content_types', models.ManyToManyField(related_name='webhooks', to='contenttypes.contenttype')),
  221. ('tags', taggit.managers.TaggableManager(through='extras.TaggedItem', to='extras.Tag')),
  222. ],
  223. options={
  224. 'verbose_name': 'webhook',
  225. 'verbose_name_plural': 'webhooks',
  226. 'ordering': ('name',),
  227. },
  228. ),
  229. migrations.CreateModel(
  230. name='StagedChange',
  231. fields=[
  232. ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
  233. ('created', models.DateTimeField(auto_now_add=True, null=True)),
  234. ('last_updated', models.DateTimeField(auto_now=True, null=True)),
  235. ('action', models.CharField(max_length=20)),
  236. ('object_id', models.PositiveBigIntegerField(blank=True, null=True)),
  237. ('data', models.JSONField(blank=True, null=True)),
  238. ('branch', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='staged_changes', to='extras.branch')),
  239. ('object_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='+', to='contenttypes.contenttype')),
  240. ],
  241. options={
  242. 'verbose_name': 'staged change',
  243. 'verbose_name_plural': 'staged changes',
  244. 'ordering': ('pk',),
  245. },
  246. ),
  247. migrations.CreateModel(
  248. name='SavedFilter',
  249. fields=[
  250. ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
  251. ('created', models.DateTimeField(auto_now_add=True, null=True)),
  252. ('last_updated', models.DateTimeField(auto_now=True, null=True)),
  253. ('name', models.CharField(max_length=100, unique=True)),
  254. ('slug', models.SlugField(max_length=100, unique=True)),
  255. ('description', models.CharField(blank=True, max_length=200)),
  256. ('weight', models.PositiveSmallIntegerField(default=100)),
  257. ('enabled', models.BooleanField(default=True)),
  258. ('shared', models.BooleanField(default=True)),
  259. ('parameters', models.JSONField()),
  260. ('content_types', models.ManyToManyField(related_name='saved_filters', to='contenttypes.contenttype')),
  261. ('user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)),
  262. ],
  263. options={
  264. 'verbose_name': 'saved filter',
  265. 'verbose_name_plural': 'saved filters',
  266. 'ordering': ('weight', 'name'),
  267. },
  268. ),
  269. migrations.CreateModel(
  270. name='ObjectChange',
  271. fields=[
  272. ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
  273. ('time', models.DateTimeField(auto_now_add=True, db_index=True)),
  274. ('user_name', models.CharField(editable=False, max_length=150)),
  275. ('request_id', models.UUIDField(db_index=True, editable=False)),
  276. ('action', models.CharField(max_length=50)),
  277. ('changed_object_id', models.PositiveBigIntegerField()),
  278. ('related_object_id', models.PositiveBigIntegerField(blank=True, null=True)),
  279. ('object_repr', models.CharField(editable=False, max_length=200)),
  280. ('prechange_data', models.JSONField(blank=True, editable=False, null=True)),
  281. ('postchange_data', models.JSONField(blank=True, editable=False, null=True)),
  282. ('changed_object_type', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='+', to='contenttypes.contenttype')),
  283. ('related_object_type', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='+', to='contenttypes.contenttype')),
  284. ('user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='changes', to=settings.AUTH_USER_MODEL)),
  285. ],
  286. options={
  287. 'verbose_name': 'object change',
  288. 'verbose_name_plural': 'object changes',
  289. 'ordering': ['-time'],
  290. },
  291. ),
  292. migrations.CreateModel(
  293. name='JournalEntry',
  294. fields=[
  295. ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
  296. ('created', models.DateTimeField(auto_now_add=True, null=True)),
  297. ('last_updated', models.DateTimeField(auto_now=True, null=True)),
  298. ('custom_field_data', models.JSONField(blank=True, default=dict, encoder=utilities.json.CustomFieldJSONEncoder)),
  299. ('assigned_object_id', models.PositiveBigIntegerField()),
  300. ('kind', models.CharField(default='info', max_length=30)),
  301. ('comments', models.TextField()),
  302. ('assigned_object_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='contenttypes.contenttype')),
  303. ('created_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)),
  304. ('tags', taggit.managers.TaggableManager(through='extras.TaggedItem', to='extras.Tag')),
  305. ],
  306. options={
  307. 'verbose_name': 'journal entry',
  308. 'verbose_name_plural': 'journal entries',
  309. 'ordering': ('-created',),
  310. },
  311. ),
  312. migrations.CreateModel(
  313. name='ImageAttachment',
  314. fields=[
  315. ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
  316. ('created', models.DateTimeField(auto_now_add=True, null=True)),
  317. ('last_updated', models.DateTimeField(auto_now=True, null=True)),
  318. ('object_id', models.PositiveBigIntegerField()),
  319. ('image', models.ImageField(height_field='image_height', upload_to=extras.utils.image_upload, width_field='image_width')),
  320. ('image_height', models.PositiveSmallIntegerField()),
  321. ('image_width', models.PositiveSmallIntegerField()),
  322. ('name', models.CharField(blank=True, max_length=50)),
  323. ('content_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='contenttypes.contenttype')),
  324. ],
  325. options={
  326. 'verbose_name': 'image attachment',
  327. 'verbose_name_plural': 'image attachments',
  328. 'ordering': ('name', 'pk'),
  329. },
  330. ),
  331. migrations.CreateModel(
  332. name='ExportTemplate',
  333. fields=[
  334. ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
  335. ('created', models.DateTimeField(auto_now_add=True, null=True)),
  336. ('last_updated', models.DateTimeField(auto_now=True, null=True)),
  337. ('data_path', models.CharField(blank=True, editable=False, max_length=1000)),
  338. ('auto_sync_enabled', models.BooleanField(default=False)),
  339. ('data_synced', models.DateTimeField(blank=True, editable=False, null=True)),
  340. ('name', models.CharField(max_length=100)),
  341. ('description', models.CharField(blank=True, max_length=200)),
  342. ('template_code', models.TextField()),
  343. ('mime_type', models.CharField(blank=True, max_length=50)),
  344. ('file_extension', models.CharField(blank=True, max_length=15)),
  345. ('as_attachment', models.BooleanField(default=True)),
  346. ('content_types', models.ManyToManyField(related_name='export_templates', to='contenttypes.contenttype')),
  347. ('data_file', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='core.datafile')),
  348. ('data_source', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='+', to='core.datasource')),
  349. ],
  350. options={
  351. 'verbose_name': 'export template',
  352. 'verbose_name_plural': 'export templates',
  353. 'ordering': ('name',),
  354. },
  355. ),
  356. migrations.CreateModel(
  357. name='Dashboard',
  358. fields=[
  359. ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
  360. ('layout', models.JSONField(default=list)),
  361. ('config', models.JSONField(default=dict)),
  362. ('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='dashboard', to=settings.AUTH_USER_MODEL)),
  363. ],
  364. options={
  365. 'verbose_name': 'dashboard',
  366. 'verbose_name_plural': 'dashboards',
  367. },
  368. ),
  369. migrations.CreateModel(
  370. name='CustomLink',
  371. fields=[
  372. ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
  373. ('created', models.DateTimeField(auto_now_add=True, null=True)),
  374. ('last_updated', models.DateTimeField(auto_now=True, null=True)),
  375. ('name', models.CharField(max_length=100, unique=True)),
  376. ('enabled', models.BooleanField(default=True)),
  377. ('link_text', models.TextField()),
  378. ('link_url', models.TextField()),
  379. ('weight', models.PositiveSmallIntegerField(default=100)),
  380. ('group_name', models.CharField(blank=True, max_length=50)),
  381. ('button_class', models.CharField(default='outline-dark', max_length=30)),
  382. ('new_window', models.BooleanField(default=False)),
  383. ('content_types', models.ManyToManyField(related_name='custom_links', to='contenttypes.contenttype')),
  384. ],
  385. options={
  386. 'verbose_name': 'custom link',
  387. 'verbose_name_plural': 'custom links',
  388. 'ordering': ['group_name', 'weight', 'name'],
  389. },
  390. ),
  391. migrations.CreateModel(
  392. name='CustomField',
  393. fields=[
  394. ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
  395. ('created', models.DateTimeField(auto_now_add=True, null=True)),
  396. ('last_updated', models.DateTimeField(auto_now=True, null=True)),
  397. ('type', models.CharField(default='text', max_length=50)),
  398. ('name', models.CharField(max_length=50, unique=True, validators=[django.core.validators.RegexValidator(flags=re.RegexFlag['IGNORECASE'], message='Only alphanumeric characters and underscores are allowed.', regex='^[a-z0-9_]+$'), django.core.validators.RegexValidator(flags=re.RegexFlag['IGNORECASE'], inverse_match=True, message='Double underscores are not permitted in custom field names.', regex='__')])),
  399. ('label', models.CharField(blank=True, max_length=50)),
  400. ('group_name', models.CharField(blank=True, max_length=50)),
  401. ('description', models.CharField(blank=True, max_length=200)),
  402. ('required', models.BooleanField(default=False)),
  403. ('search_weight', models.PositiveSmallIntegerField(default=1000)),
  404. ('filter_logic', models.CharField(default='loose', max_length=50)),
  405. ('default', models.JSONField(blank=True, null=True)),
  406. ('weight', models.PositiveSmallIntegerField(default=100)),
  407. ('validation_minimum', models.IntegerField(blank=True, null=True)),
  408. ('validation_maximum', models.IntegerField(blank=True, null=True)),
  409. ('validation_regex', models.CharField(blank=True, max_length=500, validators=[utilities.validators.validate_regex])),
  410. ('ui_visibility', models.CharField(default='read-write', max_length=50)),
  411. ('is_cloneable', models.BooleanField(default=False)),
  412. ('choice_set', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='choices_for', to='extras.customfieldchoiceset')),
  413. ('content_types', models.ManyToManyField(related_name='custom_fields', to='contenttypes.contenttype')),
  414. ('object_type', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='contenttypes.contenttype')),
  415. ],
  416. options={
  417. 'verbose_name': 'custom field',
  418. 'verbose_name_plural': 'custom fields',
  419. 'ordering': ['group_name', 'weight', 'name'],
  420. },
  421. managers=[
  422. ('objects', extras.models.customfields.CustomFieldManager()),
  423. ],
  424. ),
  425. migrations.CreateModel(
  426. name='ConfigTemplate',
  427. fields=[
  428. ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
  429. ('created', models.DateTimeField(auto_now_add=True, null=True)),
  430. ('last_updated', models.DateTimeField(auto_now=True, null=True)),
  431. ('data_path', models.CharField(blank=True, editable=False, max_length=1000)),
  432. ('auto_sync_enabled', models.BooleanField(default=False)),
  433. ('data_synced', models.DateTimeField(blank=True, editable=False, null=True)),
  434. ('name', models.CharField(max_length=100)),
  435. ('description', models.CharField(blank=True, max_length=200)),
  436. ('template_code', models.TextField()),
  437. ('environment_params', models.JSONField(blank=True, default=dict, null=True)),
  438. ('data_file', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='core.datafile')),
  439. ('data_source', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='+', to='core.datasource')),
  440. ('tags', taggit.managers.TaggableManager(through='extras.TaggedItem', to='extras.Tag')),
  441. ],
  442. options={
  443. 'verbose_name': 'config template',
  444. 'verbose_name_plural': 'config templates',
  445. 'ordering': ('name',),
  446. },
  447. ),
  448. ]