87 lines
2.9 KiB
Python
87 lines
2.9 KiB
Python
import logging
|
|
|
|
from django.urls import reverse_lazy
|
|
from django.contrib.auth.decorators import login_required
|
|
from django.utils.decorators import method_decorator
|
|
from django.views.decorators.csrf import ensure_csrf_cookie
|
|
from django.views.generic import ListView, DetailView, CreateView, DeleteView, UpdateView
|
|
from guardian.decorators import permission_required_or_403
|
|
from guardian.shortcuts import assign_perm
|
|
|
|
from config import models, forms
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
@method_decorator(login_required, name='dispatch')
|
|
@method_decorator(permission_required_or_403('config.add_restream'),
|
|
name='dispatch')
|
|
@method_decorator(ensure_csrf_cookie, name='dispatch')
|
|
class TranscodingProfileList(ListView):
|
|
model = models.TranscodingProfile
|
|
|
|
|
|
@method_decorator(login_required, name='dispatch')
|
|
@method_decorator(permission_required_or_403('config.view_transcodingprofile',
|
|
(models.TranscodingProfile, 'pk', 'pk')),
|
|
name='dispatch')
|
|
class TranscodingProfileDetail(DetailView):
|
|
model = models.TranscodingProfile
|
|
|
|
|
|
@method_decorator(login_required, name='dispatch')
|
|
@method_decorator(permission_required_or_403('config.change_transcodingprofile',
|
|
(models.TranscodingProfile, 'pk', 'pk')),
|
|
name='dispatch')
|
|
class TranscodingProfileUpdate(UpdateView):
|
|
model = models.TranscodingProfile
|
|
template_name_suffix = '_update_form'
|
|
|
|
fields = [
|
|
'name',
|
|
'video_map_stream',
|
|
'video_codec',
|
|
'video_bitrate',
|
|
'video_frame_rate',
|
|
'video_resolution',
|
|
'video_gop_size',
|
|
'video_pixel_format',
|
|
'audio_map_stream',
|
|
'audio_codec',
|
|
'audio_bitrate',
|
|
'audio_sample_rate',
|
|
'audio_channels',
|
|
|
|
]
|
|
|
|
|
|
@method_decorator(login_required, name='dispatch')
|
|
@method_decorator(permission_required_or_403('config.add_transcodingprofile'),
|
|
name='dispatch')
|
|
class TranscodingProfileCreate(CreateView):
|
|
model = models.TranscodingProfile
|
|
|
|
def get_form_kwargs(self):
|
|
kwargs = super().get_form_kwargs()
|
|
kwargs['user'] = self.request.user
|
|
return kwargs
|
|
|
|
def form_valid(self, form):
|
|
valid = super().form_valid(form)
|
|
if valid:
|
|
user = self.request.user
|
|
assign_perm('view_transcodingprofile', user, self.object)
|
|
assign_perm('change_transcodingprofile', user, self.object)
|
|
assign_perm('delete_transcodingprofile', user, self.object)
|
|
return valid
|
|
|
|
|
|
@method_decorator(login_required, name='dispatch')
|
|
@method_decorator(permission_required_or_403('config.delete_transcodingprofile',
|
|
(models.TranscodingProfile, 'pk', 'pk')),
|
|
name='dispatch')
|
|
class TranscodingProfileDelete(DeleteView):
|
|
model = models.TranscodingProfile
|
|
success_url = reverse_lazy('config:transcodingprofile_list')
|