bulk_import.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. from django import forms
  2. from django.contrib.contenttypes.models import ContentType
  3. from django.contrib.postgres.forms import SimpleArrayField
  4. from django.utils.safestring import mark_safe
  5. from extras.choices import CustomFieldTypeChoices
  6. from extras.models import *
  7. from extras.utils import FeatureQuery
  8. from utilities.forms import CSVChoiceField, CSVContentTypeField, CSVModelForm, CSVMultipleContentTypeField, SlugField
  9. __all__ = (
  10. 'CustomFieldCSVForm',
  11. 'CustomLinkCSVForm',
  12. 'ExportTemplateCSVForm',
  13. 'TagCSVForm',
  14. 'WebhookCSVForm',
  15. )
  16. class CustomFieldCSVForm(CSVModelForm):
  17. content_types = CSVMultipleContentTypeField(
  18. queryset=ContentType.objects.all(),
  19. limit_choices_to=FeatureQuery('custom_fields'),
  20. help_text="One or more assigned object types"
  21. )
  22. type = CSVChoiceField(
  23. choices=CustomFieldTypeChoices,
  24. help_text='Field data type (e.g. text, integer, etc.)'
  25. )
  26. object_type = CSVContentTypeField(
  27. queryset=ContentType.objects.all(),
  28. limit_choices_to=FeatureQuery('custom_fields'),
  29. required=False,
  30. help_text="Object type (for object or multi-object fields)"
  31. )
  32. choices = SimpleArrayField(
  33. base_field=forms.CharField(),
  34. required=False,
  35. help_text='Comma-separated list of field choices'
  36. )
  37. class Meta:
  38. model = CustomField
  39. fields = (
  40. 'name', 'label', 'group_name', 'type', 'content_types', 'object_type', 'required', 'description', 'weight',
  41. 'filter_logic', 'default', 'choices', 'weight', 'validation_minimum', 'validation_maximum',
  42. 'validation_regex', 'ui_visibility',
  43. )
  44. class CustomLinkCSVForm(CSVModelForm):
  45. content_type = CSVContentTypeField(
  46. queryset=ContentType.objects.all(),
  47. limit_choices_to=FeatureQuery('custom_links'),
  48. help_text="Assigned object type"
  49. )
  50. class Meta:
  51. model = CustomLink
  52. fields = (
  53. 'name', 'content_type', 'enabled', 'weight', 'group_name', 'button_class', 'new_window', 'link_text',
  54. 'link_url',
  55. )
  56. class ExportTemplateCSVForm(CSVModelForm):
  57. content_type = CSVContentTypeField(
  58. queryset=ContentType.objects.all(),
  59. limit_choices_to=FeatureQuery('export_templates'),
  60. help_text="Assigned object type"
  61. )
  62. class Meta:
  63. model = ExportTemplate
  64. fields = (
  65. 'name', 'content_type', 'description', 'mime_type', 'file_extension', 'as_attachment', 'template_code',
  66. )
  67. class WebhookCSVForm(CSVModelForm):
  68. content_types = CSVMultipleContentTypeField(
  69. queryset=ContentType.objects.all(),
  70. limit_choices_to=FeatureQuery('webhooks'),
  71. help_text="One or more assigned object types"
  72. )
  73. class Meta:
  74. model = Webhook
  75. fields = (
  76. 'name', 'enabled', 'content_types', 'type_create', 'type_update', 'type_delete', 'payload_url',
  77. 'http_method', 'http_content_type', 'additional_headers', 'body_template', 'secret', 'ssl_verification',
  78. 'ca_file_path'
  79. )
  80. class TagCSVForm(CSVModelForm):
  81. slug = SlugField()
  82. class Meta:
  83. model = Tag
  84. fields = ('name', 'slug', 'color', 'description')
  85. help_texts = {
  86. 'color': mark_safe('RGB color in hexadecimal (e.g. <code>00ff00</code>)'),
  87. }