From 8ec9c2807ccefa006afa9626b394eb18e1e8fbd4 Mon Sep 17 00:00:00 2001 From: Jan Koppe Date: Fri, 1 May 2020 14:10:03 +0200 Subject: [PATCH] add stream & restreamconfig changeviews --- .../restream/restreamconfig_detail.html | 19 ++++++++++++++- .../restream/restreamconfig_update_form.html | 24 +++++++++++++++++++ restream/urls.py | 1 + restream/views.py | 17 ++++++++++++- rtmp/templates/rtmp/stream_detail.html | 19 ++++++++++++++- rtmp/templates/rtmp/stream_update_form.html | 24 +++++++++++++++++++ rtmp/urls.py | 1 + rtmp/views.py | 13 +++++++++- 8 files changed, 114 insertions(+), 4 deletions(-) create mode 100644 restream/templates/restream/restreamconfig_update_form.html create mode 100644 rtmp/templates/rtmp/stream_update_form.html diff --git a/restream/templates/restream/restreamconfig_detail.html b/restream/templates/restream/restreamconfig_detail.html index 3f8e33b..12d8815 100644 --- a/restream/templates/restream/restreamconfig_detail.html +++ b/restream/templates/restream/restreamconfig_detail.html @@ -2,8 +2,25 @@ {% load i18n %} {% load bootstrap4 %} {% load font_awesome %} +{% load guardian_tags %} + +{% get_obj_perms user for object as "obj_perms" %} + {% block 'content' %} -
{% trans "restreamconfig_configuration_details_header" %}
+
+
+
{% trans "restreamconfig_configuration_details_header" %}
+
+ {% get_obj_perms user for object as "obj_perms" %} +
+ {% if "change_restreamconfig" in obj_perms %} + {% fa 'pencil' %} {% trans 'change' %} + {% endif %} + {% if "delete_restreamconfig" in obj_perms %} + {% fa 'trash' %} {% trans 'delete' %} + {% endif %} +
+

diff --git a/restream/templates/restream/restreamconfig_update_form.html b/restream/templates/restream/restreamconfig_update_form.html new file mode 100644 index 0000000..d64c0ac --- /dev/null +++ b/restream/templates/restream/restreamconfig_update_form.html @@ -0,0 +1,24 @@ +{% extends 'base.html' %} +{% load i18n %} +{% load bootstrap4 %} +{% block 'content' %} +
{% trans "update_restreamconfig_configuration_header" %}
+
+
+
+
+ {% csrf_token %} + {% bootstrap_form form %} + {% buttons %} + + {% endbuttons %} + +
+
+
+ {% trans "update_restreamconfig_configuration_text_html" %} +
+
+{% endblock %} diff --git a/restream/urls.py b/restream/urls.py index f815887..26c9b16 100644 --- a/restream/urls.py +++ b/restream/urls.py @@ -6,6 +6,7 @@ app_name = 'restream' urlpatterns = [ path('restreamconfig/', views.RestreamConfigList.as_view(), name='restreamconfig_list'), path('restreamconfig//', views.RestreamConfigDetail.as_view(), name='restreamconfig_detail'), + path('restreamconfig//change', views.RestreamConfigChange.as_view(), name='restreamconfig_change'), path('restreamconfig//delete', views.RestreamConfigDelete.as_view(), name='restreamconfig_delete'), path('restreamconfig/create', views.RestreamConfigCreate.as_view(), name='restreamconfig_create'), ] diff --git a/restream/views.py b/restream/views.py index 1026dc4..62d519c 100644 --- a/restream/views.py +++ b/restream/views.py @@ -1,7 +1,7 @@ from django.urls import reverse_lazy from django.contrib.auth.decorators import login_required from django.utils.decorators import method_decorator -from django.views.generic import ListView, DetailView, CreateView, DeleteView +from django.views.generic import ListView, DetailView, CreateView, DeleteView, UpdateView from guardian.decorators import permission_required_or_403 from guardian.shortcuts import assign_perm @@ -24,6 +24,21 @@ class RestreamConfigDetail(DetailView): model = models.RestreamConfig +@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 + + @method_decorator(login_required, name='dispatch') @method_decorator(permission_required_or_403('restream.add_restreamconfig'), name='dispatch') diff --git a/rtmp/templates/rtmp/stream_detail.html b/rtmp/templates/rtmp/stream_detail.html index d3c0ad4..1ed2f32 100644 --- a/rtmp/templates/rtmp/stream_detail.html +++ b/rtmp/templates/rtmp/stream_detail.html @@ -2,8 +2,25 @@ {% load i18n %} {% load bootstrap4 %} {% load font_awesome %} +{% load guardian_tags %} + +{% get_obj_perms user for object as "obj_perms" %} + {% block 'content' %} -
{% trans "stream_configuration_details_header" %}
+
+
+
{% trans "stream_configuration_details_header" %}
+
+ {% get_obj_perms user for object as "obj_perms" %} +
+ {% if "change_stream" in obj_perms %} + {% fa 'pencil' %} {% trans 'change' %} + {% endif %} + {% if "delete_stream" in obj_perms %} + {% fa 'trash' %} {% trans 'delete' %} + {% endif %} +
+

diff --git a/rtmp/templates/rtmp/stream_update_form.html b/rtmp/templates/rtmp/stream_update_form.html new file mode 100644 index 0000000..1cb6ccb --- /dev/null +++ b/rtmp/templates/rtmp/stream_update_form.html @@ -0,0 +1,24 @@ +{% extends 'base.html' %} +{% load i18n %} +{% load bootstrap4 %} +{% block 'content' %} +
{% trans "update_stream_configuration_header" %}
+
+
+
+
+ {% csrf_token %} + {% bootstrap_form form %} + {% buttons %} + + {% endbuttons %} + +
+
+
+ {% trans "update_stream_configuration_text_html" %} +
+
+{% endblock %} diff --git a/rtmp/urls.py b/rtmp/urls.py index 5bd69c2..7e971d4 100644 --- a/rtmp/urls.py +++ b/rtmp/urls.py @@ -7,6 +7,7 @@ urlpatterns = [ path('callback/srs', views.callback_srs, name='callback_srs'), path('streams/', views.StreamList.as_view(), name='stream_list'), path('streams//', views.StreamDetail.as_view(), name='stream_detail'), + path('streams//change', views.StreamChange.as_view(), name='stream_change'), path('streams//delete', views.StreamDelete.as_view(), name='stream_delete'), path('streams/create', views.StreamCreate.as_view(), name='stream_create'), ] diff --git a/rtmp/views.py b/rtmp/views.py index ae589a8..3673cc2 100644 --- a/rtmp/views.py +++ b/rtmp/views.py @@ -8,7 +8,7 @@ from django.contrib.auth.decorators import login_required from django.contrib.admin.utils import NestedObjects from django.utils.decorators import method_decorator from django.views.decorators.csrf import csrf_exempt -from django.views.generic import ListView, DetailView, CreateView, DeleteView +from django.views.generic import ListView, DetailView, CreateView, DeleteView, UpdateView from guardian.decorators import permission_required_or_403 from guardian.shortcuts import assign_perm @@ -64,6 +64,17 @@ class StreamDetail(DetailView): model = models.Stream +@method_decorator(login_required, name='dispatch') +@method_decorator(permission_required_or_403('rtmp.change_stream', + (models.Stream, 'pk', 'pk')), + name='dispatch') +class StreamChange(UpdateView): + model = models.Stream + fields = ['application', 'name'] + template_name_suffix = '_update_form' + + + @method_decorator(login_required, name='dispatch') @method_decorator(permission_required_or_403('rtmp.add_stream'), name='dispatch')