2008-08-19 10:50:38 +02:00
|
|
|
"""
|
2011-01-26 00:08:41 +01:00
|
|
|
django-helpdesk - A Django powered ticket tracker for small enterprise.
|
2007-12-27 01:29:17 +01:00
|
|
|
|
2008-02-06 05:36:07 +01:00
|
|
|
(c) Copyright 2008 Jutda. All Rights Reserved. See LICENSE for details.
|
2007-12-27 01:29:17 +01:00
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
forms.py - Definitions of newforms-based forms for creating and maintaining
|
2008-02-06 05:36:07 +01:00
|
|
|
tickets.
|
2007-12-27 01:29:17 +01:00
|
|
|
"""
|
2016-10-21 17:14:12 +02:00
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2016-11-21 03:12:19 +01:00
|
|
|
from django.core.exceptions import ObjectDoesNotExist
|
2008-08-12 01:24:18 +02:00
|
|
|
from django import forms
|
2017-12-28 15:11:34 +01:00
|
|
|
from django.forms import widgets
|
2009-01-22 09:08:22 +01:00
|
|
|
from django.conf import settings
|
2016-10-18 15:37:57 +02:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
2016-10-21 17:14:12 +02:00
|
|
|
from django.contrib.auth import get_user_model
|
2016-11-21 03:12:19 +01:00
|
|
|
from django.utils import timezone
|
2007-12-27 01:29:17 +01:00
|
|
|
|
2018-10-31 16:24:57 +01:00
|
|
|
from helpdesk.lib import safe_template_context, process_attachments
|
2019-03-07 21:58:04 +01:00
|
|
|
from helpdesk.models import (Ticket, Queue, FollowUp, IgnoreEmail, TicketCC,
|
2020-01-07 13:33:06 +01:00
|
|
|
CustomField, TicketCustomFieldValue, TicketDependency, UserSettings, KBItem)
|
2012-01-17 22:40:44 +01:00
|
|
|
from helpdesk import settings as helpdesk_settings
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2016-10-21 17:14:12 +02:00
|
|
|
User = get_user_model()
|
|
|
|
|
2016-10-30 20:53:18 +01:00
|
|
|
CUSTOMFIELD_TO_FIELD_DICT = {
|
|
|
|
# Store the immediate equivalences here
|
|
|
|
'boolean': forms.BooleanField,
|
|
|
|
'date': forms.DateField,
|
|
|
|
'time': forms.TimeField,
|
|
|
|
'datetime': forms.DateTimeField,
|
|
|
|
'email': forms.EmailField,
|
|
|
|
'url': forms.URLField,
|
|
|
|
'ipaddress': forms.GenericIPAddressField,
|
|
|
|
'slug': forms.SlugField,
|
|
|
|
}
|
|
|
|
|
2016-10-21 17:14:12 +02:00
|
|
|
|
2014-06-05 01:45:07 +02:00
|
|
|
class CustomFieldMixin(object):
|
|
|
|
"""
|
|
|
|
Mixin that provides a method to turn CustomFields into an actual field
|
|
|
|
"""
|
2016-10-23 22:09:17 +02:00
|
|
|
|
2014-06-05 01:45:07 +02:00
|
|
|
def customfield_to_field(self, field, instanceargs):
|
2016-10-30 20:53:18 +01:00
|
|
|
# if-elif branches start with special cases
|
2014-06-05 01:45:07 +02:00
|
|
|
if field.data_type == 'varchar':
|
|
|
|
fieldclass = forms.CharField
|
|
|
|
instanceargs['max_length'] = field.max_length
|
|
|
|
elif field.data_type == 'text':
|
|
|
|
fieldclass = forms.CharField
|
|
|
|
instanceargs['widget'] = forms.Textarea
|
|
|
|
instanceargs['max_length'] = field.max_length
|
|
|
|
elif field.data_type == 'integer':
|
|
|
|
fieldclass = forms.IntegerField
|
|
|
|
elif field.data_type == 'decimal':
|
|
|
|
fieldclass = forms.DecimalField
|
|
|
|
instanceargs['decimal_places'] = field.decimal_places
|
|
|
|
instanceargs['max_digits'] = field.max_length
|
|
|
|
elif field.data_type == 'list':
|
|
|
|
fieldclass = forms.ChoiceField
|
|
|
|
choices = field.choices_as_array
|
|
|
|
if field.empty_selection_list:
|
2016-10-21 17:14:12 +02:00
|
|
|
choices.insert(0, ('', '---------'))
|
2014-06-05 01:45:07 +02:00
|
|
|
instanceargs['choices'] = choices
|
2016-10-30 08:38:49 +01:00
|
|
|
else:
|
2016-10-30 20:53:18 +01:00
|
|
|
# Try to use the immediate equivalences dictionary
|
|
|
|
try:
|
|
|
|
fieldclass = CUSTOMFIELD_TO_FIELD_DICT[field.data_type]
|
|
|
|
except KeyError:
|
|
|
|
# The data_type was not found anywhere
|
|
|
|
raise NameError("Unrecognized data_type %s" % field.data_type)
|
2014-06-05 01:45:07 +02:00
|
|
|
|
|
|
|
self.fields['custom_%s' % field.name] = fieldclass(**instanceargs)
|
|
|
|
|
2016-10-21 17:14:12 +02:00
|
|
|
|
2014-06-05 01:45:07 +02:00
|
|
|
class EditTicketForm(CustomFieldMixin, forms.ModelForm):
|
2016-10-23 22:09:17 +02:00
|
|
|
|
2009-06-03 13:43:46 +02:00
|
|
|
class Meta:
|
|
|
|
model = Ticket
|
|
|
|
exclude = ('created', 'modified', 'status', 'on_hold', 'resolution', 'last_escalation', 'assigned_to')
|
2016-09-12 08:11:55 +02:00
|
|
|
|
2011-05-09 23:54:44 +02:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
"""
|
|
|
|
Add any custom fields that are defined to the form
|
|
|
|
"""
|
|
|
|
super(EditTicketForm, self).__init__(*args, **kwargs)
|
|
|
|
|
|
|
|
for field in CustomField.objects.all():
|
|
|
|
try:
|
|
|
|
current_value = TicketCustomFieldValue.objects.get(ticket=self.instance, field=field)
|
|
|
|
initial_value = current_value.value
|
|
|
|
except TicketCustomFieldValue.DoesNotExist:
|
|
|
|
initial_value = None
|
|
|
|
instanceargs = {
|
2016-10-23 22:09:17 +02:00
|
|
|
'label': field.label,
|
|
|
|
'help_text': field.help_text,
|
|
|
|
'required': field.required,
|
|
|
|
'initial': initial_value,
|
|
|
|
}
|
2014-06-05 01:45:07 +02:00
|
|
|
|
|
|
|
self.customfield_to_field(field, instanceargs)
|
2011-05-09 23:54:44 +02:00
|
|
|
|
|
|
|
def save(self, *args, **kwargs):
|
2016-09-12 08:11:55 +02:00
|
|
|
|
2011-05-09 23:54:44 +02:00
|
|
|
for field, value in self.cleaned_data.items():
|
|
|
|
if field.startswith('custom_'):
|
2014-10-25 21:53:56 +02:00
|
|
|
field_name = field.replace('custom_', '', 1)
|
2011-05-09 23:54:44 +02:00
|
|
|
customfield = CustomField.objects.get(name=field_name)
|
|
|
|
try:
|
|
|
|
cfv = TicketCustomFieldValue.objects.get(ticket=self.instance, field=customfield)
|
2016-10-21 17:14:12 +02:00
|
|
|
except ObjectDoesNotExist:
|
2011-05-09 23:54:44 +02:00
|
|
|
cfv = TicketCustomFieldValue(ticket=self.instance, field=customfield)
|
|
|
|
cfv.value = value
|
|
|
|
cfv.save()
|
2016-09-12 08:11:55 +02:00
|
|
|
|
2011-05-09 23:54:44 +02:00
|
|
|
return super(EditTicketForm, self).save(*args, **kwargs)
|
|
|
|
|
2009-06-03 13:43:46 +02:00
|
|
|
|
2011-01-29 07:02:03 +01:00
|
|
|
class EditFollowUpForm(forms.ModelForm):
|
2016-10-23 22:09:17 +02:00
|
|
|
|
2011-01-29 07:02:03 +01:00
|
|
|
class Meta:
|
|
|
|
model = FollowUp
|
|
|
|
exclude = ('date', 'user',)
|
|
|
|
|
2016-10-21 17:14:12 +02:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
"""Filter not openned tickets here."""
|
|
|
|
super(EditFollowUpForm, self).__init__(*args, **kwargs)
|
|
|
|
self.fields["ticket"].queryset = Ticket.objects.filter(status__in=(Ticket.OPEN_STATUS, Ticket.REOPENED_STATUS))
|
|
|
|
|
|
|
|
|
2016-10-30 08:39:06 +01:00
|
|
|
class AbstractTicketForm(CustomFieldMixin, forms.Form):
|
|
|
|
"""
|
|
|
|
Contain all the common code and fields between "TicketForm" and
|
|
|
|
"PublicTicketForm". This Form is not intended to be used directly.
|
|
|
|
"""
|
2008-08-19 10:50:38 +02:00
|
|
|
queue = forms.ChoiceField(
|
2016-10-29 10:08:57 +02:00
|
|
|
widget=forms.Select(attrs={'class': 'form-control'}),
|
2008-08-19 10:50:38 +02:00
|
|
|
label=_('Queue'),
|
|
|
|
required=True,
|
|
|
|
choices=()
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
|
|
|
title = forms.CharField(
|
|
|
|
max_length=100,
|
|
|
|
required=True,
|
2016-10-29 10:08:57 +02:00
|
|
|
widget=forms.TextInput(attrs={'class': 'form-control'}),
|
2008-08-19 10:50:38 +02:00
|
|
|
label=_('Summary of the problem'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
|
|
|
body = forms.CharField(
|
2016-10-31 06:38:49 +01:00
|
|
|
widget=forms.Textarea(attrs={'class': 'form-control'}),
|
2016-10-30 08:39:06 +01:00
|
|
|
label=_('Description of your issue'),
|
2008-08-19 10:50:38 +02:00
|
|
|
required=True,
|
2016-10-30 08:39:06 +01:00
|
|
|
help_text=_('Please be as descriptive as possible and include all details'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
|
|
|
priority = forms.ChoiceField(
|
2016-10-29 10:08:57 +02:00
|
|
|
widget=forms.Select(attrs={'class': 'form-control'}),
|
2008-08-19 10:50:38 +02:00
|
|
|
choices=Ticket.PRIORITY_CHOICES,
|
2016-10-30 08:39:06 +01:00
|
|
|
required=True,
|
2008-08-19 10:50:38 +02:00
|
|
|
initial='3',
|
|
|
|
label=_('Priority'),
|
2016-10-30 08:39:06 +01:00
|
|
|
help_text=_("Please select a priority carefully. If unsure, leave it as '3'."),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2012-01-20 21:48:38 +01:00
|
|
|
due_date = forms.DateTimeField(
|
2016-10-29 10:08:57 +02:00
|
|
|
widget=forms.TextInput(attrs={'class': 'form-control'}),
|
2012-01-20 21:48:38 +01:00
|
|
|
required=False,
|
2019-05-22 11:20:01 +02:00
|
|
|
input_formats=['%d/%m/%Y', '%m/%d/%Y', "%d.%m.%Y", ],
|
2012-01-20 21:48:38 +01:00
|
|
|
label=_('Due on'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2012-01-20 21:48:38 +01:00
|
|
|
|
2009-01-22 09:08:22 +01:00
|
|
|
attachment = forms.FileField(
|
2018-09-02 10:36:16 +02:00
|
|
|
widget=forms.FileInput(attrs={'class': 'form-control-file'}),
|
2009-01-22 09:08:22 +01:00
|
|
|
required=False,
|
|
|
|
label=_('Attach File'),
|
|
|
|
help_text=_('You can attach a file such as a document or screenshot to this ticket.'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2009-01-22 09:08:22 +01:00
|
|
|
|
2020-01-08 18:39:41 +01:00
|
|
|
def __init__(self, kbcategory=None, *args, **kwargs):
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
if kbcategory:
|
2020-01-08 20:38:08 +01:00
|
|
|
self.fields['kbitem'] = forms.ChoiceField(
|
2020-01-08 18:39:41 +01:00
|
|
|
widget=forms.Select(attrs={'class': 'form-control'}),
|
|
|
|
required=False,
|
2020-02-25 14:25:52 +01:00
|
|
|
label=_('Knowledge Base Item'),
|
2020-02-27 11:54:04 +01:00
|
|
|
choices=[(kbi.pk, kbi.title) for kbi in KBItem.objects.filter(category=kbcategory.pk, enabled=True)],
|
2020-01-08 18:39:41 +01:00
|
|
|
)
|
|
|
|
|
2016-10-30 08:39:06 +01:00
|
|
|
def _add_form_custom_fields(self, staff_only_filter=None):
|
|
|
|
if staff_only_filter is None:
|
|
|
|
queryset = CustomField.objects.all()
|
|
|
|
else:
|
|
|
|
queryset = CustomField.objects.filter(staff_only=staff_only_filter)
|
|
|
|
|
|
|
|
for field in queryset:
|
2020-01-08 20:38:08 +01:00
|
|
|
instanceargs = {
|
|
|
|
'label': field.label,
|
|
|
|
'help_text': field.help_text,
|
|
|
|
'required': field.required,
|
|
|
|
}
|
2014-06-05 01:45:07 +02:00
|
|
|
|
|
|
|
self.customfield_to_field(field, instanceargs)
|
2011-02-02 12:22:46 +01:00
|
|
|
|
2020-01-07 13:47:36 +01:00
|
|
|
def _get_queue(self):
|
|
|
|
# this procedure is re-defined for anon submission form
|
|
|
|
return Queue.objects.get(id=int(self.cleaned_data['queue']))
|
|
|
|
|
2016-10-30 08:39:06 +01:00
|
|
|
def _create_ticket(self):
|
2020-01-07 13:33:06 +01:00
|
|
|
queue = Queue.objects.get(id=int(self.cleaned_data['queue']))
|
|
|
|
kbitem = None
|
|
|
|
if 'kbitem' in self.cleaned_data:
|
|
|
|
kbitem = KBItem.objects.get(id=int(self.cleaned_data['kbitem']))
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2016-10-30 20:43:05 +01:00
|
|
|
ticket = Ticket(title=self.cleaned_data['title'],
|
|
|
|
submitter_email=self.cleaned_data['submitter_email'],
|
|
|
|
created=timezone.now(),
|
|
|
|
status=Ticket.OPEN_STATUS,
|
|
|
|
queue=queue,
|
|
|
|
description=self.cleaned_data['body'],
|
|
|
|
priority=self.cleaned_data['priority'],
|
|
|
|
due_date=self.cleaned_data['due_date'],
|
2020-01-07 13:33:06 +01:00
|
|
|
kbitem=kbitem,
|
2016-10-30 20:43:05 +01:00
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2016-10-30 20:43:05 +01:00
|
|
|
return ticket, queue
|
2016-09-12 08:11:55 +02:00
|
|
|
|
2016-10-30 08:39:06 +01:00
|
|
|
def _create_custom_fields(self, ticket):
|
2011-02-02 12:22:46 +01:00
|
|
|
for field, value in self.cleaned_data.items():
|
|
|
|
if field.startswith('custom_'):
|
2014-10-25 21:53:56 +02:00
|
|
|
field_name = field.replace('custom_', '', 1)
|
2016-10-30 08:39:06 +01:00
|
|
|
custom_field = CustomField.objects.get(name=field_name)
|
|
|
|
cfv = TicketCustomFieldValue(ticket=ticket,
|
|
|
|
field=custom_field,
|
2016-10-21 17:14:12 +02:00
|
|
|
value=value)
|
2011-02-02 12:22:46 +01:00
|
|
|
cfv.save()
|
2007-12-27 01:29:17 +01:00
|
|
|
|
2016-10-30 08:39:06 +01:00
|
|
|
def _create_follow_up(self, ticket, title, user=None):
|
2016-10-30 20:43:05 +01:00
|
|
|
followup = FollowUp(ticket=ticket,
|
|
|
|
title=title,
|
|
|
|
date=timezone.now(),
|
|
|
|
public=True,
|
|
|
|
comment=self.cleaned_data['body'],
|
|
|
|
)
|
2016-10-30 08:39:06 +01:00
|
|
|
if user:
|
2016-10-30 20:43:05 +01:00
|
|
|
followup.user = user
|
|
|
|
return followup
|
2007-12-28 04:29:45 +01:00
|
|
|
|
2016-10-30 08:39:06 +01:00
|
|
|
def _attach_files_to_follow_up(self, followup):
|
2016-11-10 17:23:16 +01:00
|
|
|
files = self.cleaned_data['attachment']
|
|
|
|
if files:
|
|
|
|
files = process_attachments(followup, [files])
|
|
|
|
return files
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2016-10-30 08:39:06 +01:00
|
|
|
@staticmethod
|
|
|
|
def _send_messages(ticket, queue, followup, files, user=None):
|
|
|
|
context = safe_template_context(ticket)
|
|
|
|
context['comment'] = followup.comment
|
2016-09-12 08:11:55 +02:00
|
|
|
|
2018-10-31 16:24:57 +01:00
|
|
|
roles = {'submitter': ('newticket_submitter', context),
|
|
|
|
'new_ticket_cc': ('newticket_cc', context),
|
|
|
|
'ticket_cc': ('newticket_cc', context)}
|
|
|
|
if ticket.assigned_to and ticket.assigned_to.usersettings_helpdesk.email_on_ticket_assign:
|
|
|
|
roles['assigned_to'] = ('assigned_owner', context)
|
|
|
|
ticket.send(
|
|
|
|
roles,
|
|
|
|
fail_silently=True,
|
|
|
|
files=files,
|
|
|
|
)
|
2008-01-21 02:02:12 +01:00
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2016-10-30 08:39:06 +01:00
|
|
|
class TicketForm(AbstractTicketForm):
|
|
|
|
"""
|
|
|
|
Ticket Form creation for registered users.
|
|
|
|
"""
|
2008-08-19 10:50:38 +02:00
|
|
|
submitter_email = forms.EmailField(
|
2012-01-20 21:48:38 +01:00
|
|
|
required=False,
|
2016-10-30 08:39:06 +01:00
|
|
|
label=_('Submitter E-Mail Address'),
|
2018-09-02 10:36:16 +02:00
|
|
|
widget=forms.TextInput(attrs={'class': 'form-control', 'type': 'email'}),
|
2016-10-30 08:39:06 +01:00
|
|
|
help_text=_('This e-mail address will receive copies of all public '
|
|
|
|
'updates to this ticket.'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2016-10-30 08:39:06 +01:00
|
|
|
assigned_to = forms.ChoiceField(
|
2018-09-07 19:05:16 +02:00
|
|
|
widget=forms.Select(attrs={'class': 'form-control'}) if not helpdesk_settings.HELPDESK_CREATE_TICKET_HIDE_ASSIGNED_TO else forms.HiddenInput(),
|
2009-01-22 09:08:22 +01:00
|
|
|
required=False,
|
2016-10-30 08:39:06 +01:00
|
|
|
label=_('Case owner'),
|
|
|
|
help_text=_('If you select an owner other than yourself, they\'ll be '
|
|
|
|
'e-mailed details of this ticket immediately.'),
|
2018-09-07 19:05:16 +02:00
|
|
|
|
|
|
|
choices=()
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2009-01-22 09:08:22 +01:00
|
|
|
|
2011-02-02 12:22:46 +01:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
"""
|
2016-10-30 08:39:06 +01:00
|
|
|
Add any custom fields that are defined to the form.
|
2011-02-02 12:22:46 +01:00
|
|
|
"""
|
2019-02-05 14:38:41 +01:00
|
|
|
queue_choices = kwargs.pop("queue_choices")
|
|
|
|
|
2018-09-07 19:05:16 +02:00
|
|
|
super().__init__(*args, **kwargs)
|
2019-02-05 14:38:41 +01:00
|
|
|
|
|
|
|
self.fields['queue'].choices = queue_choices
|
2018-09-07 19:05:16 +02:00
|
|
|
if helpdesk_settings.HELPDESK_STAFF_ONLY_TICKET_OWNERS:
|
|
|
|
assignable_users = User.objects.filter(is_active=True, is_staff=True).order_by(User.USERNAME_FIELD)
|
|
|
|
else:
|
|
|
|
assignable_users = User.objects.filter(is_active=True).order_by(User.USERNAME_FIELD)
|
|
|
|
self.fields['assigned_to'].choices = [('', '--------')] + [(u.id, u.get_username()) for u in assignable_users]
|
2016-10-30 08:39:06 +01:00
|
|
|
self._add_form_custom_fields()
|
2011-02-02 12:22:46 +01:00
|
|
|
|
2016-10-30 08:39:06 +01:00
|
|
|
def save(self, user=None):
|
2008-01-16 01:26:24 +01:00
|
|
|
"""
|
|
|
|
Writes and returns a Ticket() object
|
|
|
|
"""
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2016-10-30 20:43:05 +01:00
|
|
|
ticket, queue = self._create_ticket()
|
2016-10-30 08:39:06 +01:00
|
|
|
if self.cleaned_data['assigned_to']:
|
|
|
|
try:
|
|
|
|
u = User.objects.get(id=self.cleaned_data['assigned_to'])
|
2016-10-30 20:43:05 +01:00
|
|
|
ticket.assigned_to = u
|
2016-10-30 08:39:06 +01:00
|
|
|
except User.DoesNotExist:
|
2016-10-30 20:43:05 +01:00
|
|
|
ticket.assigned_to = None
|
|
|
|
ticket.save()
|
2016-09-12 08:11:55 +02:00
|
|
|
|
2016-10-30 20:43:05 +01:00
|
|
|
self._create_custom_fields(ticket)
|
2009-01-22 09:08:22 +01:00
|
|
|
|
2016-10-30 08:39:06 +01:00
|
|
|
if self.cleaned_data['assigned_to']:
|
|
|
|
title = _('Ticket Opened & Assigned to %(name)s') % {
|
2016-10-30 20:43:05 +01:00
|
|
|
'name': ticket.get_assigned_to or _("<invalid user>")
|
2016-10-30 08:39:06 +01:00
|
|
|
}
|
|
|
|
else:
|
|
|
|
title = _('Ticket Opened')
|
2016-10-30 20:43:05 +01:00
|
|
|
followup = self._create_follow_up(ticket, title=title, user=user)
|
|
|
|
followup.save()
|
2008-01-16 01:26:24 +01:00
|
|
|
|
2016-10-30 20:43:05 +01:00
|
|
|
files = self._attach_files_to_follow_up(followup)
|
|
|
|
self._send_messages(ticket=ticket,
|
|
|
|
queue=queue,
|
|
|
|
followup=followup,
|
|
|
|
files=files,
|
|
|
|
user=user)
|
|
|
|
return ticket
|
2009-08-11 11:02:48 +02:00
|
|
|
|
2016-02-17 09:40:08 +01:00
|
|
|
|
2016-10-30 08:39:06 +01:00
|
|
|
class PublicTicketForm(AbstractTicketForm):
|
|
|
|
"""
|
|
|
|
Ticket Form creation for all users (public-facing).
|
|
|
|
"""
|
|
|
|
submitter_email = forms.EmailField(
|
2018-09-02 10:36:16 +02:00
|
|
|
widget=forms.TextInput(attrs={'class': 'form-control', 'type': 'email'}),
|
2016-10-30 08:39:06 +01:00
|
|
|
required=True,
|
|
|
|
label=_('Your E-Mail Address'),
|
|
|
|
help_text=_('We will e-mail you when your ticket is updated.'),
|
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2020-01-08 18:39:41 +01:00
|
|
|
def __init__(self, hidden_fields=(), readonly_fields=(), *args, **kwargs):
|
2016-10-30 08:39:06 +01:00
|
|
|
"""
|
|
|
|
Add any (non-staff) custom fields that are defined to the form
|
|
|
|
"""
|
|
|
|
super(PublicTicketForm, self).__init__(*args, **kwargs)
|
2019-12-12 16:41:55 +01:00
|
|
|
self._add_form_custom_fields(False)
|
|
|
|
|
2019-12-06 15:44:20 +01:00
|
|
|
field_hide_table = {
|
|
|
|
'queue': 'HELPDESK_PUBLIC_TICKET_QUEUE',
|
|
|
|
'priority': 'HELPDESK_PUBLIC_TICKET_PRIORITY',
|
|
|
|
'due_date': 'HELPDESK_PUBLIC_TICKET_DUE_DATE',
|
|
|
|
}
|
2019-12-12 17:22:57 +01:00
|
|
|
|
2020-01-06 14:13:31 +01:00
|
|
|
for field in self.fields.keys():
|
|
|
|
setting = field_hide_table.get(field, None)
|
2019-12-12 17:22:57 +01:00
|
|
|
if (setting and hasattr(settings, setting)) or field in hidden_fields:
|
2019-12-06 15:44:20 +01:00
|
|
|
self.fields[field].widget = forms.HiddenInput()
|
2020-01-06 14:25:37 +01:00
|
|
|
if field in readonly_fields:
|
|
|
|
self.fields[field].disabled = True
|
2019-12-06 15:44:20 +01:00
|
|
|
|
|
|
|
self.fields['queue'].choices = [('', '--------')] + [
|
|
|
|
(q.id, q.title) for q in Queue.objects.filter(allow_public_submission=True)]
|
2008-01-21 02:02:12 +01:00
|
|
|
|
2016-10-30 08:39:06 +01:00
|
|
|
def save(self):
|
|
|
|
"""
|
|
|
|
Writes and returns a Ticket() object
|
|
|
|
"""
|
2016-10-30 20:43:05 +01:00
|
|
|
ticket, queue = self._create_ticket()
|
|
|
|
if queue.default_owner and not ticket.assigned_to:
|
|
|
|
ticket.assigned_to = queue.default_owner
|
|
|
|
ticket.save()
|
|
|
|
|
|
|
|
self._create_custom_fields(ticket)
|
|
|
|
|
|
|
|
followup = self._create_follow_up(ticket, title=_('Ticket Opened Via Web'))
|
|
|
|
followup.save()
|
|
|
|
|
|
|
|
files = self._attach_files_to_follow_up(followup)
|
|
|
|
self._send_messages(ticket=ticket,
|
|
|
|
queue=queue,
|
|
|
|
followup=followup,
|
|
|
|
files=files)
|
|
|
|
return ticket
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2008-09-09 10:32:01 +02:00
|
|
|
|
2018-10-05 14:54:22 +02:00
|
|
|
class UserSettingsForm(forms.ModelForm):
|
2009-07-22 10:19:46 +02:00
|
|
|
|
2018-10-05 14:54:22 +02:00
|
|
|
class Meta:
|
|
|
|
model = UserSettings
|
|
|
|
exclude = ['user', 'settings_pickled']
|
2009-08-06 10:56:02 +02:00
|
|
|
|
|
|
|
|
2008-10-25 00:52:34 +02:00
|
|
|
class EmailIgnoreForm(forms.ModelForm):
|
2016-10-23 22:09:17 +02:00
|
|
|
|
2008-10-25 00:52:34 +02:00
|
|
|
class Meta:
|
|
|
|
model = IgnoreEmail
|
2014-09-11 09:37:51 +02:00
|
|
|
exclude = []
|
2009-09-09 10:47:48 +02:00
|
|
|
|
2016-10-21 17:14:12 +02:00
|
|
|
|
2009-09-09 10:47:48 +02:00
|
|
|
class TicketCCForm(forms.ModelForm):
|
2016-09-12 08:11:55 +02:00
|
|
|
''' Adds either an email address or helpdesk user as a CC on a Ticket. Used for processing POST requests. '''
|
2016-10-23 22:09:17 +02:00
|
|
|
|
2016-10-21 17:14:12 +02:00
|
|
|
class Meta:
|
|
|
|
model = TicketCC
|
|
|
|
exclude = ('ticket',)
|
|
|
|
|
2011-02-06 18:49:07 +01:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super(TicketCCForm, self).__init__(*args, **kwargs)
|
2012-01-17 22:40:44 +01:00
|
|
|
if helpdesk_settings.HELPDESK_STAFF_ONLY_TICKET_CC:
|
2014-10-22 07:18:04 +02:00
|
|
|
users = User.objects.filter(is_active=True, is_staff=True).order_by(User.USERNAME_FIELD)
|
2012-01-17 22:40:44 +01:00
|
|
|
else:
|
2014-10-22 07:18:04 +02:00
|
|
|
users = User.objects.filter(is_active=True).order_by(User.USERNAME_FIELD)
|
2016-09-12 08:11:55 +02:00
|
|
|
self.fields['user'].queryset = users
|
2011-02-06 18:49:07 +01:00
|
|
|
|
2016-10-29 10:27:29 +02:00
|
|
|
|
2016-09-12 08:11:55 +02:00
|
|
|
class TicketCCUserForm(forms.ModelForm):
|
|
|
|
''' Adds a helpdesk user as a CC on a Ticket '''
|
2016-10-29 10:08:57 +02:00
|
|
|
|
2016-09-12 08:11:55 +02:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super(TicketCCUserForm, self).__init__(*args, **kwargs)
|
|
|
|
if helpdesk_settings.HELPDESK_STAFF_ONLY_TICKET_CC:
|
|
|
|
users = User.objects.filter(is_active=True, is_staff=True).order_by(User.USERNAME_FIELD)
|
|
|
|
else:
|
|
|
|
users = User.objects.filter(is_active=True).order_by(User.USERNAME_FIELD)
|
|
|
|
self.fields['user'].queryset = users
|
2016-10-29 10:20:16 +02:00
|
|
|
|
2016-09-12 08:11:55 +02:00
|
|
|
class Meta:
|
|
|
|
model = TicketCC
|
2016-10-29 10:08:57 +02:00
|
|
|
exclude = ('ticket', 'email',)
|
2016-09-12 08:11:55 +02:00
|
|
|
|
2016-10-29 10:27:29 +02:00
|
|
|
|
2016-09-12 08:11:55 +02:00
|
|
|
class TicketCCEmailForm(forms.ModelForm):
|
|
|
|
''' Adds an email address as a CC on a Ticket '''
|
2016-10-29 10:08:57 +02:00
|
|
|
|
2016-09-12 08:11:55 +02:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super(TicketCCEmailForm, self).__init__(*args, **kwargs)
|
2016-10-29 10:20:16 +02:00
|
|
|
|
2016-09-12 08:11:55 +02:00
|
|
|
class Meta:
|
|
|
|
model = TicketCC
|
2016-10-29 10:08:57 +02:00
|
|
|
exclude = ('ticket', 'user',)
|
2016-09-12 08:11:55 +02:00
|
|
|
|
2016-10-29 10:27:29 +02:00
|
|
|
|
2011-05-10 11:27:11 +02:00
|
|
|
class TicketDependencyForm(forms.ModelForm):
|
2016-10-29 10:08:57 +02:00
|
|
|
''' Adds a different ticket as a dependency for this Ticket '''
|
2016-10-23 22:09:17 +02:00
|
|
|
|
2011-05-10 11:27:11 +02:00
|
|
|
class Meta:
|
|
|
|
model = TicketDependency
|
|
|
|
exclude = ('ticket',)
|