Files
LXC-Dispatcharr-modificado-…/apps/m3u/views.py
T
root f56b088643
Base Image Build / prepare (push) Has been cancelled
Build and Push Multi-Arch Docker Image / build-and-push (push) Has been cancelled
Frontend Tests / test (push) Has been cancelled
Base Image Build / docker (amd64, ubuntu-24.04) (push) Has been cancelled
Base Image Build / docker (arm64, ubuntu-24.04-arm) (push) Has been cancelled
Base Image Build / create-manifest (push) Has been cancelled
Proyecto LCX Dispatcharr multicuenta
2026-05-09 21:24:50 +02:00

36 lines
1.3 KiB
Python

from django.shortcuts import render
from django.views import View
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.http import JsonResponse
from apps.m3u.models import M3UAccount
import json
@method_decorator(csrf_exempt, name='dispatch')
@method_decorator(login_required, name='dispatch')
class M3UDashboardView(View):
def get(self, request, *args, **kwargs):
"""
Handles GET requests for the M3U dashboard.
Renders the m3u.html template with M3U account data.
"""
m3u_accounts = M3UAccount.objects.all()
return render(request, 'm3u/m3u.html', {'m3u_accounts': m3u_accounts})
def post(self, request, *args, **kwargs):
"""
Handles POST requests to create a new M3U account.
Expects JSON data in the request body.
"""
try:
data = json.loads(request.body)
new_account = M3UAccount.objects.create(**data)
return JsonResponse({
'id': new_account.id,
'message': 'M3U account created successfully!'
}, status=201)
except Exception as e:
return JsonResponse({'error': str(e)}, status=400)