mirror of
https://gitea.mueller.network/extern/django-helpdesk.git
synced 2024-11-25 09:23:39 +01:00
Show a form to create a new checklist, with the possibility to use a preset template
This commit is contained in:
parent
8be55fb7f2
commit
b8d06a0fb1
@ -26,7 +26,9 @@ from helpdesk.models import (
|
|||||||
TicketCC,
|
TicketCC,
|
||||||
TicketCustomFieldValue,
|
TicketCustomFieldValue,
|
||||||
TicketDependency,
|
TicketDependency,
|
||||||
UserSettings
|
UserSettings,
|
||||||
|
Checklist,
|
||||||
|
ChecklistTemplate
|
||||||
)
|
)
|
||||||
from helpdesk.settings import (
|
from helpdesk.settings import (
|
||||||
CUSTOMFIELD_DATE_FORMAT,
|
CUSTOMFIELD_DATE_FORMAT,
|
||||||
@ -602,3 +604,26 @@ class MultipleTicketSelectForm(forms.Form):
|
|||||||
raise ValidationError(
|
raise ValidationError(
|
||||||
_('All selected tickets must share the same queue in order to be merged.'))
|
_('All selected tickets must share the same queue in order to be merged.'))
|
||||||
return tickets
|
return tickets
|
||||||
|
|
||||||
|
|
||||||
|
class ChecklistForm(forms.ModelForm):
|
||||||
|
checklist_template = forms.ModelChoiceField(
|
||||||
|
label=_("Template"),
|
||||||
|
queryset=ChecklistTemplate.objects.all(),
|
||||||
|
widget=forms.Select(attrs={'class': 'form-wontrol'}),
|
||||||
|
required=False,
|
||||||
|
)
|
||||||
|
name = forms.CharField(
|
||||||
|
widget=forms.TextInput(attrs={'class': 'form-wontrol'}),
|
||||||
|
required=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Checklist
|
||||||
|
fields = ('name',)
|
||||||
|
|
||||||
|
def clean(self):
|
||||||
|
if not self.cleaned_data.get('checklist_template') and not self.cleaned_data.get('name'):
|
||||||
|
raise ValidationError(_('Please choose at least a name or a template for the new checklist'))
|
||||||
|
if self.cleaned_data.get('checklist_template') and self.cleaned_data.get('name'):
|
||||||
|
raise ValidationError(_('Please choose either a name or a template for the new checklist'))
|
||||||
|
@ -2028,6 +2028,12 @@ class ChecklistTemplate(models.Model):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
def create_checklist_for_ticket(self, ticket):
|
||||||
|
checklist = ticket.checklists.create(name=self.name)
|
||||||
|
for task in self.task_list:
|
||||||
|
checklist.tasks.create(description=task)
|
||||||
|
return checklist
|
||||||
|
|
||||||
|
|
||||||
class Checklist(models.Model):
|
class Checklist(models.Model):
|
||||||
ticket = models.ForeignKey(
|
ticket = models.ForeignKey(
|
||||||
|
@ -219,7 +219,13 @@
|
|||||||
<h4>Add a checklist</h4>
|
<h4>Add a checklist</h4>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
TODO
|
<form method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
{{ checklist_form.as_p }}
|
||||||
|
<button type="submit" class="btn btn-primary">
|
||||||
|
{% trans "Add" %}
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -48,7 +48,8 @@ from helpdesk.forms import (
|
|||||||
TicketCCUserForm,
|
TicketCCUserForm,
|
||||||
TicketDependencyForm,
|
TicketDependencyForm,
|
||||||
TicketForm,
|
TicketForm,
|
||||||
UserSettingsForm
|
UserSettingsForm,
|
||||||
|
ChecklistForm
|
||||||
)
|
)
|
||||||
from helpdesk.lib import process_attachments, queue_template_context, safe_template_context
|
from helpdesk.lib import process_attachments, queue_template_context, safe_template_context
|
||||||
from helpdesk.models import (
|
from helpdesk.models import (
|
||||||
@ -406,6 +407,17 @@ def view_ticket(request, ticket_id):
|
|||||||
else:
|
else:
|
||||||
submitter_userprofile_url = None
|
submitter_userprofile_url = None
|
||||||
|
|
||||||
|
checklist_form = ChecklistForm(request.POST or None)
|
||||||
|
if checklist_form.is_valid():
|
||||||
|
checklist_template = checklist_form.cleaned_data.get('checklist_template')
|
||||||
|
if checklist_template:
|
||||||
|
checklist_template.create_checklist_for_ticket(ticket)
|
||||||
|
else:
|
||||||
|
checklist = checklist_form.save(commit=False)
|
||||||
|
checklist.ticket = ticket
|
||||||
|
checklist.save()
|
||||||
|
return redirect(ticket)
|
||||||
|
|
||||||
return render(request, 'helpdesk/ticket.html', {
|
return render(request, 'helpdesk/ticket.html', {
|
||||||
'ticket': ticket,
|
'ticket': ticket,
|
||||||
'submitter_userprofile_url': submitter_userprofile_url,
|
'submitter_userprofile_url': submitter_userprofile_url,
|
||||||
@ -416,6 +428,7 @@ def view_ticket(request, ticket_id):
|
|||||||
Q(queues=ticket.queue) | Q(queues__isnull=True)),
|
Q(queues=ticket.queue) | Q(queues__isnull=True)),
|
||||||
'ticketcc_string': ticketcc_string,
|
'ticketcc_string': ticketcc_string,
|
||||||
'SHOW_SUBSCRIBE': show_subscribe,
|
'SHOW_SUBSCRIBE': show_subscribe,
|
||||||
|
'checklist_form': checklist_form,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user