瀏覽代碼

saving channel settings works

Double-Vee 3 年之前
父節點
當前提交
86241f3d78
共有 2 個文件被更改,包括 24 次插入8 次删除
  1. 11 0
      webgui/config/templates/config/channel_settings.html
  2. 13 8
      webgui/config/views.py

+ 11 - 0
webgui/config/templates/config/channel_settings.html

@@ -2,6 +2,17 @@
 {% load static %}
 {% load semanticui %}
 {% block content %}
+    {% if updated %}
+        <div class="ui icon success message">
+            <i class="save icon"></i>
+            <div class="content">
+                <div class="header">
+                    Changes saved.
+                </div>
+                <p>You may close the page or continue making changes.</p>
+            </div>
+        </div>
+    {% endif %}
     <form class= "ui form" method="post">
         {% csrf_token %}
         {% render_form form %}

+ 13 - 8
webgui/config/views.py

@@ -1,21 +1,26 @@
-from django.shortcuts import render
-
-# Create your views here.
+from django.shortcuts import render, get_object_or_404
 from webgui.settings import APPLICATION_NAME
-
 from .models import ChannelSettings
 from .forms import ChannelSettingsForm
 
 def channel_settings(request, channel_id):
-	initial_data = {
-		"interact": ChannelSettings.objects.get(channel=channel_id).interact
-	}
+	settings = get_object_or_404(ChannelSettings, channel=channel_id)
+
+	updated = False
+	if request.method == 'POST':
+		form = ChannelSettingsForm(request.POST, instance=settings)
+		if form.is_valid():
+			form.save()
+			updated = True
+	else:
+		form = ChannelSettingsForm(instance=settings)
 	
 	context = {
 		'title': 'Channel settings',
 		'icon': 'screwdriver',
 		'description': 'Modify channel settings for ' + APPLICATION_NAME,
 		'keywords': 'settigns, channel',
-		'form': ChannelSettingsForm(initial=initial_data),
+		'form': form,
+		'updated': updated,
 	}
 	return render(request, 'config/channel_settings.html', context)