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):
	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': form,
		'updated': updated,
	}
	return render(request, 'config/channel_settings.html', context)