Fix bug when using file upload for m3u and not being able to set "Use Default"

This commit is contained in:
SergeantPanda 2025-05-21 14:22:01 -05:00
parent 5cae2e595e
commit 1087568de7
2 changed files with 21 additions and 5 deletions

View file

@ -51,7 +51,15 @@ class M3UAccountViewSet(viewsets.ModelViewSet):
# Add file_path to the request data so it's available during creation
request.data._mutable = True # Allow modification of the request data
request.data['file_path'] = file_path # Include the file path if a file was uploaded
request.data.pop('server_url')
# Handle the user_agent field - convert "null" string to None
if 'user_agent' in request.data and request.data['user_agent'] == 'null':
request.data['user_agent'] = None
# Handle server_url appropriately
if 'server_url' in request.data and not request.data['server_url']:
request.data.pop('server_url')
request.data._mutable = False # Make the request data immutable again
# Now call super().create() to create the instance
@ -82,16 +90,24 @@ class M3UAccountViewSet(viewsets.ModelViewSet):
# Add file_path to the request data so it's available during creation
request.data._mutable = True # Allow modification of the request data
request.data['file_path'] = file_path # Include the file path if a file was uploaded
request.data.pop('server_url')
# Handle the user_agent field - convert "null" string to None
if 'user_agent' in request.data and request.data['user_agent'] == 'null':
request.data['user_agent'] = None
# Handle server_url appropriately
if 'server_url' in request.data and not request.data['server_url']:
request.data.pop('server_url')
request.data._mutable = False # Make the request data immutable again
if instance.file_path and os.path.exists(instance.file_path):
os.remove(instance.file_path)
# Now call super().create() to create the instance
# Now call super().update() to update the instance
response = super().update(request, *args, **kwargs)
# After the instance is created, return the response
# After the instance is updated, return the response
return response
def partial_update(self, request, *args, **kwargs):

View file

@ -307,7 +307,7 @@ const M3U = ({
description="User-Agent header to use when accessing this M3U source"
{...form.getInputProps('user_agent')}
key={form.key('user_agent')}
data={[{ value: '0', label: '(use default)' }].concat(
data={[{ value: '0', label: '(Use Default)' }].concat(
userAgents.map((ua) => ({
label: ua.name,
value: `${ua.id}`,