diff --git a/helpdesk/forms.py b/helpdesk/forms.py index 8a6781d2..0c6ac3d3 100644 --- a/helpdesk/forms.py +++ b/helpdesk/forms.py @@ -26,7 +26,9 @@ from helpdesk.models import ( TicketCC, TicketCustomFieldValue, TicketDependency, - UserSettings + UserSettings, + Checklist, + ChecklistTemplate ) from helpdesk.settings import ( CUSTOMFIELD_DATE_FORMAT, @@ -602,3 +604,26 @@ class MultipleTicketSelectForm(forms.Form): raise ValidationError( _('All selected tickets must share the same queue in order to be merged.')) 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')) diff --git a/helpdesk/models.py b/helpdesk/models.py index ec3f68f4..d090529d 100644 --- a/helpdesk/models.py +++ b/helpdesk/models.py @@ -2028,6 +2028,12 @@ class ChecklistTemplate(models.Model): def __str__(self): 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): ticket = models.ForeignKey( diff --git a/helpdesk/templates/helpdesk/ticket_desc_table.html b/helpdesk/templates/helpdesk/ticket_desc_table.html index 8aa85c04..36eba139 100644 --- a/helpdesk/templates/helpdesk/ticket_desc_table.html +++ b/helpdesk/templates/helpdesk/ticket_desc_table.html @@ -219,7 +219,13 @@