Dispatcharr/apps/channels/views.py
Dispatcharr 9da7adda92 Pre Alpha v4
Added login page
Added login/logout buttons
Added m3u settings
Added stream profiles to channels and streams
Added ability to add individual stream outside of m3u file
Added ability to add youtube live links as a stream source
Deleted migrations
Deleted pycache folders
Changed HDHR to get ip dynamically
2025-02-22 20:43:55 -06:00

41 lines
No EOL
1.3 KiB
Python

from django.views import View
from django.http import JsonResponse
from django.utils.decorators import method_decorator
from django.contrib.auth.decorators import login_required
from django.views.decorators.csrf import csrf_exempt
from django.shortcuts import render
from .models import Stream
@method_decorator(csrf_exempt, name='dispatch')
@method_decorator(login_required, name='dispatch')
class StreamDashboardView(View):
"""
Example “dashboard” style view for Streams
"""
def get(self, request, *args, **kwargs):
streams = Stream.objects.values(
'id', 'name', 'url', 'custom_url',
'group_name', 'current_viewers'
)
return JsonResponse({'data': list(streams)}, safe=False)
def post(self, request, *args, **kwargs):
"""
Creates a new Stream from JSON data
"""
import json
try:
data = json.loads(request.body)
new_stream = Stream.objects.create(**data)
return JsonResponse({
'id': new_stream.id,
'message': 'Stream created successfully!'
}, status=201)
except Exception as e:
return JsonResponse({'error': str(e)}, status=400)
@login_required
def channels_dashboard_view(request):
return render(request, 'channels/channels.html')