Add get_time_spent_from_request helper

Extracts further code
This commit is contained in:
Martin Whitehouse 2022-07-25 03:17:10 +02:00
parent 9294eca5d6
commit f815ebbb5c
No known key found for this signature in database
GPG Key ID: 3FCE1D3E9DEC09C1

View File

@ -593,6 +593,14 @@ def get_and_set_ticket_status(
return (old_status_str, old_status) return (old_status_str, old_status)
def get_time_spent_from_request(request: WSGIRequest) -> typing.Optional[timedelta]:
if request.POST.get("time_spent"):
(hours, minutes) = [int(f)
for f in request.POST.get("time_spent").split(":")]
return timedelta(hours=hours, minutes=minutes)
return None
def update_ticket(request, ticket_id, public=False): def update_ticket(request, ticket_id, public=False):
ticket = get_ticket_from_request_with_authorisation(request, ticket_id, public) ticket = get_ticket_from_request_with_authorisation(request, ticket_id, public)
@ -603,12 +611,8 @@ def update_ticket(request, ticket_id, public=False):
public = request.POST.get('public', False) public = request.POST.get('public', False)
owner = int(request.POST.get('owner', -1)) owner = int(request.POST.get('owner', -1))
priority = int(request.POST.get('priority', ticket.priority)) priority = int(request.POST.get('priority', ticket.priority))
if request.POST.get("time_spent"):
(hours, minutes) = [int(f) time_spent = get_time_spent_from_request(request)
for f in request.POST.get("time_spent").split(":")]
time_spent = timedelta(hours=hours, minutes=minutes)
else:
time_spent = None
# NOTE: jQuery's default for dates is mm/dd/yy # NOTE: jQuery's default for dates is mm/dd/yy
# very US-centric but for now that's the only format supported # very US-centric but for now that's the only format supported
# until we clean up code to internationalize a little more # until we clean up code to internationalize a little more
@ -674,9 +678,7 @@ def update_ticket(request, ticket_id, public=False):
old_status_str, old_status = get_and_set_ticket_status(new_status, ticket, f) old_status_str, old_status = get_and_set_ticket_status(new_status, ticket, f)
files = [] files = process_attachments(f, request.FILES.getlist('attachment')) if request.FILES else []
if request.FILES:
files = process_attachments(f, request.FILES.getlist('attachment'))
if title and title != ticket.title: if title and title != ticket.title:
c = TicketChange( c = TicketChange(