77 lines
2.5 KiB
Python
77 lines
2.5 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 RestreamList(ListView):
|
|
model = models.Restream
|
|
|
|
|
|
@method_decorator(login_required, name='dispatch')
|
|
@method_decorator(permission_required_or_403('config.view_restream',
|
|
(models.Restream, 'pk', 'pk')),
|
|
name='dispatch')
|
|
class RestreamDetail(DetailView):
|
|
model = models.Restream
|
|
|
|
|
|
@method_decorator(login_required, name='dispatch')
|
|
@method_decorator(permission_required_or_403('config.change_restream',
|
|
(models.Restream, 'pk', 'pk')),
|
|
name='dispatch')
|
|
class RestreamUpdate(UpdateView):
|
|
model = models.Restream
|
|
form_class = forms.RestreamFilteredStreamForm
|
|
template_name_suffix = '_update_form'
|
|
|
|
def get_form_kwargs(self):
|
|
kwargs = super().get_form_kwargs()
|
|
kwargs['user'] = self.request.user
|
|
return kwargs
|
|
|
|
|
|
@method_decorator(login_required, name='dispatch')
|
|
@method_decorator(permission_required_or_403('config.add_restream'),
|
|
name='dispatch')
|
|
class RestreamCreate(CreateView):
|
|
model = models.Restream
|
|
form_class = forms.RestreamFilteredStreamForm
|
|
|
|
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_restream', user, self.object)
|
|
assign_perm('change_restream', user, self.object)
|
|
assign_perm('delete_restream', user, self.object)
|
|
return valid
|
|
|
|
|
|
@method_decorator(login_required, name='dispatch')
|
|
@method_decorator(permission_required_or_403('config.delete_restream',
|
|
(models.Restream, 'pk', 'pk')),
|
|
name='dispatch')
|
|
class RestreamDelete(DeleteView):
|
|
model = models.Restream
|
|
success_url = reverse_lazy('config:restream_list')
|