diff --git a/helpdesk/forms.py b/helpdesk/forms.py index 0c6ac3d3..b9a00ee3 100644 --- a/helpdesk/forms.py +++ b/helpdesk/forms.py @@ -607,23 +607,34 @@ class MultipleTicketSelectForm(forms.Form): 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, + widget=forms.TextInput(attrs={'class': 'form-control'}), + required=True, ) class Meta: model = Checklist fields = ('name',) + +class CreateChecklistForm(ChecklistForm): + checklist_template = forms.ModelChoiceField( + label=_("Template"), + queryset=ChecklistTemplate.objects.all(), + widget=forms.Select(attrs={'class': 'form-control'}), + required=False, + ) + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.fields['name'].required = False + 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')) + + +class FormControlDeleteFormSet(forms.BaseInlineFormSet): + deletion_widget = forms.CheckboxInput(attrs={'class': 'form-control'}) diff --git a/helpdesk/migrations/0038_checklist_checklisttemplate_checklisttask.py b/helpdesk/migrations/0038_checklist_checklisttemplate_checklisttask.py index 3bfd0156..a3c80616 100644 --- a/helpdesk/migrations/0038_checklist_checklisttemplate_checklisttask.py +++ b/helpdesk/migrations/0038_checklist_checklisttemplate_checklisttask.py @@ -1,4 +1,4 @@ -# Generated by Django 4.2 on 2023-04-22 20:50 +# Generated by Django 4.2 on 2023-04-28 21:23 from django.db import migrations, models import django.db.models.deletion @@ -42,11 +42,13 @@ class Migration(migrations.Migration): ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('description', models.CharField(max_length=250, verbose_name='Description')), ('completion_date', models.DateTimeField(blank=True, null=True, verbose_name='Completion Date')), + ('position', models.PositiveSmallIntegerField(db_index=True, verbose_name='Position')), ('checklist', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='tasks', to='helpdesk.checklist', verbose_name='Checklist')), ], options={ 'verbose_name': 'Checklist Task', 'verbose_name_plural': 'Checklist Tasks', + 'ordering': ('position',), }, ), ] diff --git a/helpdesk/models.py b/helpdesk/models.py index d090529d..7f9e2072 100644 --- a/helpdesk/models.py +++ b/helpdesk/models.py @@ -2030,8 +2030,8 @@ class ChecklistTemplate(models.Model): 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) + for position, task in enumerate(self.task_list): + checklist.tasks.create(description=task, position=position) return checklist @@ -2079,12 +2079,17 @@ class ChecklistTask(models.Model): null=True, blank=True ) + position = models.PositiveSmallIntegerField( + verbose_name=_('Position'), + db_index=True + ) objects = ChecklistTaskQuerySet.as_manager() class Meta: verbose_name = _('Checklist Task') verbose_name_plural = _('Checklist Tasks') + ordering = ('position',) def __str__(self): return self.description diff --git a/helpdesk/templates/helpdesk/checklist_confirm_delete.html b/helpdesk/templates/helpdesk/checklist_confirm_delete.html new file mode 100644 index 00000000..1e5a697f --- /dev/null +++ b/helpdesk/templates/helpdesk/checklist_confirm_delete.html @@ -0,0 +1,45 @@ +{% extends "helpdesk/base.html" %} + +{% load i18n %} + +{% block helpdesk_title %}{% trans "Delete Checklist" %}{% endblock %} + +{% block helpdesk_breadcrumb %} +
+ {{ form.non_field_errors }} +
+ {% endif %} + +