2020-04-29 21:09:04 +02:00
|
|
|
from django.urls import reverse_lazy
|
|
|
|
from django.contrib.auth.decorators import login_required
|
2020-05-31 20:25:39 +02:00
|
|
|
from django.views.decorators.csrf import ensure_csrf_cookie
|
2020-04-29 21:09:04 +02:00
|
|
|
from django.utils.decorators import method_decorator
|
2020-05-01 14:10:03 +02:00
|
|
|
from django.views.generic import ListView, DetailView, CreateView, DeleteView, UpdateView
|
2020-05-01 12:38:57 +02:00
|
|
|
from guardian.decorators import permission_required_or_403
|
|
|
|
from guardian.shortcuts import assign_perm
|
2020-04-15 20:29:59 +02:00
|
|
|
|
2020-04-29 21:09:04 +02:00
|
|
|
from . import models
|
2020-05-01 12:38:57 +02:00
|
|
|
from . import forms
|
2020-04-29 21:09:04 +02:00
|
|
|
|
|
|
|
|
|
|
|
@method_decorator(login_required, name='dispatch')
|
2020-05-01 12:38:57 +02:00
|
|
|
@method_decorator(permission_required_or_403('restream.add_restreamconfig'),
|
|
|
|
name='dispatch')
|
2020-05-31 20:25:39 +02:00
|
|
|
@method_decorator(ensure_csrf_cookie, name='dispatch')
|
2020-04-29 21:09:04 +02:00
|
|
|
class RestreamConfigList(ListView):
|
|
|
|
model = models.RestreamConfig
|
|
|
|
|
|
|
|
|
|
|
|
@method_decorator(login_required, name='dispatch')
|
2020-05-01 12:38:57 +02:00
|
|
|
@method_decorator(permission_required_or_403('restream.view_restreamconfig',
|
|
|
|
(models.RestreamConfig, 'pk', 'pk')),
|
|
|
|
name='dispatch')
|
2020-04-29 21:09:04 +02:00
|
|
|
class RestreamConfigDetail(DetailView):
|
|
|
|
model = models.RestreamConfig
|
|
|
|
|
|
|
|
|
2020-05-01 14:10:03 +02:00
|
|
|
@method_decorator(login_required, name='dispatch')
|
|
|
|
@method_decorator(permission_required_or_403('restream.change_restreamconfig',
|
|
|
|
(models.RestreamConfig, 'pk', 'pk')),
|
|
|
|
name='dispatch')
|
|
|
|
class RestreamConfigChange(UpdateView):
|
|
|
|
model = models.RestreamConfig
|
|
|
|
form_class = forms.RestreamConfigFilteredStreamForm
|
|
|
|
template_name_suffix = '_update_form'
|
|
|
|
|
|
|
|
def get_form_kwargs(self):
|
|
|
|
kwargs = super().get_form_kwargs()
|
|
|
|
kwargs['user'] = self.request.user
|
|
|
|
return kwargs
|
|
|
|
|
|
|
|
|
2020-04-29 21:09:04 +02:00
|
|
|
@method_decorator(login_required, name='dispatch')
|
2020-05-01 12:38:57 +02:00
|
|
|
@method_decorator(permission_required_or_403('restream.add_restreamconfig'),
|
|
|
|
name='dispatch')
|
2020-04-29 21:09:04 +02:00
|
|
|
class RestreamConfigCreate(CreateView):
|
|
|
|
model = models.RestreamConfig
|
2020-05-01 12:38:57 +02:00
|
|
|
form_class = forms.RestreamConfigFilteredStreamForm
|
|
|
|
|
|
|
|
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_restreamconfig', user, self.object)
|
|
|
|
assign_perm('change_restreamconfig', user, self.object)
|
|
|
|
assign_perm('delete_restreamconfig', user, self.object)
|
|
|
|
return valid
|
2020-04-29 21:09:04 +02:00
|
|
|
|
|
|
|
|
|
|
|
@method_decorator(login_required, name='dispatch')
|
2020-05-01 12:38:57 +02:00
|
|
|
@method_decorator(permission_required_or_403('restream.delete_restreamconfig',
|
|
|
|
(models.RestreamConfig, 'pk', 'pk')),
|
|
|
|
name='dispatch')
|
2020-04-29 21:09:04 +02:00
|
|
|
class RestreamConfigDelete(DeleteView):
|
|
|
|
model = models.RestreamConfig
|
|
|
|
success_url = reverse_lazy('restream:restreamconfig_list')
|