bulk_import.py 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. choices = SimpleArrayField(
  27. base_field=forms.CharField(),
  28. required=False,
  29. help_text='Comma-separated list of field choices'
  30. )
  31. class Meta:
  32. model = CustomField
  33. fields = (
  34. 'name', 'label', 'type', 'content_types', 'required', 'description', 'weight', 'filter_logic', 'default',
  35. 'choices', 'weight', 'validation_minimum', 'validation_maximum', 'validation_regex',
  36. )
  37. class CustomLinkCSVForm(CSVModelForm):
  38. content_type = CSVContentTypeField(
  39. queryset=ContentType.objects.all(),
  40. limit_choices_to=FeatureQuery('custom_links'),
  41. help_text="Assigned object type"
  42. )
  43. class Meta:
  44. model = CustomLink
  45. fields = (
  46. 'name', 'content_type', 'enabled', 'weight', 'group_name', 'button_class', 'new_window', 'link_text',
  47. 'link_url',
  48. )
  49. class ExportTemplateCSVForm(CSVModelForm):
  50. content_type = CSVContentTypeField(
  51. queryset=ContentType.objects.all(),
  52. limit_choices_to=FeatureQuery('export_templates'),
  53. help_text="Assigned object type"
  54. )
  55. class Meta:
  56. model = ExportTemplate
  57. fields = (
  58. 'name', 'content_type', 'description', 'mime_type', 'file_extension', 'as_attachment', 'template_code',
  59. )
  60. class WebhookCSVForm(CSVModelForm):
  61. content_types = CSVMultipleContentTypeField(
  62. queryset=ContentType.objects.all(),
  63. limit_choices_to=FeatureQuery('webhooks'),
  64. help_text="One or more assigned object types"
  65. )
  66. class Meta:
  67. model = Webhook
  68. fields = (
  69. 'name', 'enabled', 'content_types', 'type_create', 'type_update', 'type_delete', 'payload_url',
  70. 'http_method', 'http_content_type', 'additional_headers', 'body_template', 'secret', 'ssl_verification',
  71. 'ca_file_path'
  72. )
  73. class TagCSVForm(CSVModelForm):
  74. slug = SlugField()
  75. class Meta:
  76. model = Tag
  77. fields = ('name', 'slug', 'color', 'description')
  78. help_texts = {
  79. 'color': mark_safe('RGB color in hexadecimal (e.g. <code>00ff00</code>)'),
  80. }