Reinstate changes, fixed missing update

This commit is contained in:
Martin Whitehouse 2022-07-25 04:23:03 +02:00
parent 40a243c23b
commit f89f5b91da
No known key found for this signature in database
GPG Key ID: 3FCE1D3E9DEC09C1

View File

@ -989,7 +989,7 @@ mass_update = staff_member_required(mass_update)
# Prepare ticket attributes which will be displayed in the table to choose # Prepare ticket attributes which will be displayed in the table to choose
# which value to keep when merging # which value to keep when merging
ticket_attributes = ( TICKET_ATTRIBUTES = (
('created', _('Created date')), ('created', _('Created date')),
('due_date', _('Due on')), ('due_date', _('Due on')),
('get_status_display', _('Status')), ('get_status_display', _('Status')),
@ -1008,7 +1008,7 @@ def merge_ticket_values(
for ticket in tickets: for ticket in tickets:
ticket.values = {} ticket.values = {}
# Prepare the value for each attributes of this ticket # Prepare the value for each attributes of this ticket
for attribute, __ in ticket_attributes: for attribute, __ in TICKET_ATTRIBUTES:
value = getattr(ticket, attribute, TicketCustomFieldValue.default_value) value = getattr(ticket, attribute, TicketCustomFieldValue.default_value)
# Check if attr is a get_FIELD_display # Check if attr is a get_FIELD_display
if attribute.startswith('get_') and attribute.endswith('_display'): if attribute.startswith('get_') and attribute.endswith('_display'):
@ -1031,37 +1031,14 @@ def merge_ticket_values(
} }
@staff_member_required def redirect_from_chosen_ticket(
def merge_tickets(request): request,
""" chosen_ticket,
An intermediate view to merge up to 3 tickets in one main ticket. tickets,
The user has to first select which ticket will receive the other tickets information and can also choose which custom_fields
data to keep per attributes as well as custom fields. ) -> HttpResponseRedirect:
Follow-ups and ticketCC will be moved to the main ticket and other tickets won't be able to receive new answers.
"""
ticket_select_form = MultipleTicketSelectForm(request.GET or None)
tickets = custom_fields = None
if ticket_select_form.is_valid():
tickets = ticket_select_form.cleaned_data.get('tickets')
custom_fields = CustomField.objects.all()
merge_ticket_values(request, tickets, custom_fields)
if request.method == 'POST':
# Find which ticket has been chosen to be the main one
try:
chosen_ticket = tickets.get(
id=request.POST.get('chosen_ticket'))
except Ticket.DoesNotExist:
ticket_select_form.add_error(
field='tickets',
error=_(
'Please choose a ticket in which the others will be merged into.')
)
else:
# Save ticket fields values # Save ticket fields values
for attribute, __ in ticket_attributes: for attribute, __ in TICKET_ATTRIBUTES:
id_for_attribute = request.POST.get(attribute) id_for_attribute = request.POST.get(attribute)
if id_for_attribute != chosen_ticket.id: if id_for_attribute != chosen_ticket.id:
try: try:
@ -1149,9 +1126,46 @@ def merge_tickets(request):
ticketcc=ticketcc) ticketcc=ticketcc)
return redirect(chosen_ticket) return redirect(chosen_ticket)
@staff_member_required
def merge_tickets(request):
"""
An intermediate view to merge up to 3 tickets in one main ticket.
The user has to first select which ticket will receive the other tickets information and can also choose which
data to keep per attributes as well as custom fields.
Follow-ups and ticketCC will be moved to the main ticket and other tickets won't be able to receive new answers.
"""
ticket_select_form = MultipleTicketSelectForm(request.GET or None)
tickets = custom_fields = None
if ticket_select_form.is_valid():
tickets = ticket_select_form.cleaned_data.get('tickets')
custom_fields = CustomField.objects.all()
merge_ticket_values(request, tickets, custom_fields)
if request.method == 'POST':
# Find which ticket has been chosen to be the main one
try:
chosen_ticket = tickets.get(
id=request.POST.get('chosen_ticket'))
except Ticket.DoesNotExist:
ticket_select_form.add_error(
field='tickets',
error=_(
'Please choose a ticket in which the others will be merged into.')
)
else:
return redirect_from_chosen_ticket(
request,
chosen_ticket,
tickets,
custom_fields
)
return render(request, 'helpdesk/ticket_merge.html', { return render(request, 'helpdesk/ticket_merge.html', {
'tickets': tickets, 'tickets': tickets,
'ticket_attributes': ticket_attributes, 'ticket_attributes': TICKET_ATTRIBUTES,
'custom_fields': custom_fields, 'custom_fields': custom_fields,
'ticket_select_form': ticket_select_form 'ticket_select_form': ticket_select_form
}) })