mirror of
https://gitea.mueller.network/extern/django-helpdesk.git
synced 2024-12-25 08:09:12 +01:00
Add ability to hide fields in public ticket submission form using kwargs
This commit is contained in:
parent
3b5a7fe49a
commit
24b8e45f66
@ -337,34 +337,22 @@ class PublicTicketForm(AbstractTicketForm):
|
||||
help_text=_('We will e-mail you when your ticket is updated.'),
|
||||
)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
def __init__(self, hidden_fields=(), *args, **kwargs):
|
||||
"""
|
||||
Add any (non-staff) custom fields that are defined to the form
|
||||
"""
|
||||
super(PublicTicketForm, self).__init__(*args, **kwargs)
|
||||
if hasattr(settings, 'HELPDESK_PUBLIC_TICKET_QUEUE'):
|
||||
del self.fields['queue']
|
||||
else:
|
||||
self.fields['queue'].choices = [
|
||||
('', '--------')
|
||||
] + [
|
||||
(q.id, q.title) for q in Queue.objects.filter(allow_public_submission=True)
|
||||
]
|
||||
if hasattr(settings, 'HELPDESK_PUBLIC_TICKET_PRIORITY'):
|
||||
self.fields['priority'].widget = forms.HiddenInput()
|
||||
if hasattr(settings, 'HELPDESK_PUBLIC_TICKET_DUE_DATE'):
|
||||
self.fields['due_date'].widget = forms.HiddenInput()
|
||||
field_hide_table = {
|
||||
'queue': 'HELPDESK_PUBLIC_TICKET_QUEUE',
|
||||
'priority': 'HELPDESK_PUBLIC_TICKET_PRIORITY',
|
||||
'due_date': 'HELPDESK_PUBLIC_TICKET_DUE_DATE',
|
||||
}
|
||||
for (field, setting) in field_hide_table.items():
|
||||
if hasattr(settings, setting) or field in hidden_fields:
|
||||
self.fields[field].widget = forms.HiddenInput()
|
||||
|
||||
def _get_queue(self):
|
||||
if getattr(settings, 'HELPDESK_PUBLIC_TICKET_QUEUE', None):
|
||||
# force queue to be the pre-defined one
|
||||
# (only for anon submissions)
|
||||
return Queue.objects.filter(
|
||||
slug=settings.HELPDESK_PUBLIC_TICKET_QUEUE
|
||||
).first()
|
||||
else:
|
||||
# get the queue user entered
|
||||
return Queue.objects.get(id=int(self.cleaned_data['queue']))
|
||||
self.fields['queue'].choices = [('', '--------')] + [
|
||||
(q.id, q.title) for q in Queue.objects.filter(allow_public_submission=True)]
|
||||
|
||||
def save(self):
|
||||
"""
|
||||
|
@ -113,21 +113,6 @@ class AttachmentUnitTests(TestCase):
|
||||
)
|
||||
self.assertEqual(filename, self.file_attrs['filename'])
|
||||
|
||||
<<<<<<< HEAD
|
||||
# TODO: FIXME: what's wrong with this test that we get integrity errors?
|
||||
# @mock.patch('helpdesk.lib.FollowUpAttachment', autospec=True)
|
||||
# def test_autofill(self, mock_att_save, mock_queue_save, mock_ticket_save, mock_follow_up_save):
|
||||
# """ check utf-8 data is parsed correctly """
|
||||
# self.follow_up.pk = 100
|
||||
# self.follow_up.save()
|
||||
# obj = models.FollowUpAttachment.objects.create(
|
||||
# followup=self.follow_up,
|
||||
# file=self.test_file
|
||||
# )
|
||||
# self.assertEqual(obj.filename, self.file_attrs['filename'])
|
||||
# self.assertEqual(obj.size, len(self.file_attrs['content']))
|
||||
# self.assertEqual(obj.mime_type, "text/plain")
|
||||
=======
|
||||
@mock.patch('helpdesk.lib.FollowUpAttachment', autospec=True)
|
||||
def test_autofill(self, mock_att_save, mock_queue_save, mock_ticket_save, mock_follow_up_save):
|
||||
""" check utf-8 data is parsed correctly """
|
||||
@ -138,7 +123,6 @@ class AttachmentUnitTests(TestCase):
|
||||
self.assertEqual(obj.filename, self.file_attrs['filename'])
|
||||
self.assertEqual(obj.size, len(self.file_attrs['content']))
|
||||
self.assertEqual(obj.mime_type, "text/plain")
|
||||
>>>>>>> b899c97... Remove hardcoded pk from test suit
|
||||
|
||||
def test_kbi_attachment(self, mock_att_save, mock_queue_save, mock_ticket_save):
|
||||
""" check utf-8 data is parsed correctly """
|
||||
|
@ -88,6 +88,11 @@ class CreateTicketView(FormView):
|
||||
initial_data[qpf] = request.GET.get(qpf, initial_data.get(qpf, ""))
|
||||
return initial_data
|
||||
|
||||
def get_form_kwargs(self, *args, **kwargs):
|
||||
kwargs = super().get_form_kwargs(*args, **kwargs)
|
||||
kwargs['hidden_fields'] = self.request.GET.get('_hide_fields_', '').split(',')
|
||||
return kwargs
|
||||
|
||||
def form_valid(self, form):
|
||||
request = self.request
|
||||
if text_is_spam(form.cleaned_data['body'], request):
|
||||
|
Loading…
Reference in New Issue
Block a user