django-helpdeskmig/helpdesk/views/abstract_views.py

40 lines
1.4 KiB
Python
Raw Normal View History

2020-01-08 18:39:41 +01:00
from helpdesk.models import CustomField, KBItem, Queue
class AbstractCreateTicketMixin():
def get_initial(self):
initial_data = {}
request = self.request
try:
2022-07-12 12:34:19 +02:00
initial_data['queue'] = Queue.objects.get(
slug=request.GET.get('queue', None)).id
2020-01-08 18:39:41 +01:00
except Queue.DoesNotExist:
pass
u = request.user
if u.is_authenticated and u.usersettings_helpdesk.use_email_as_submitter and u.email:
initial_data['submitter_email'] = u.email
2020-01-08 18:39:41 +01:00
2022-07-12 12:34:19 +02:00
query_param_fields = ['submitter_email',
'title', 'body', 'queue', 'kbitem']
custom_fields = [
"custom_%s" % f.name for f in CustomField.objects.filter(staff_only=False)]
2020-01-08 18:39:41 +01:00
query_param_fields += custom_fields
for qpf in query_param_fields:
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)
kbitem = self.request.GET.get(
'kbitem',
self.request.POST.get('kbitem', None),
)
if kbitem:
try:
2022-07-12 12:34:19 +02:00
kwargs['kbcategory'] = KBItem.objects.get(
pk=int(kbitem)).category
2020-01-08 18:39:41 +01:00
except (ValueError, KBItem.DoesNotExist):
pass
return kwargs