def channel_edit(request, id): """ :param request: :param id: :return: """ val = get_object_or_404(Channel, id=id) form = ChannelForm(request.POST or None, request.FILES or None, instance=val) if request.method == 'POST': if form.is_valid(): form.save() msg_ok = _(u'Kanal güncelleme başarılı') return HttpResponseRedirect(reverse('channel_list')) else: msg_err = _(u'Dikkat! Lütfen hataları düzeltiniz!') return render(request, "back/add.html", locals())
def channel_add(request): """ :param request: :return: """ channel_add = True msg_ok = "" msg_err = "" if request.method == 'POST': form = ChannelForm(request.POST) if form.is_valid(): f = form.save(commit=False) f.owner = request.user f.api_key = (uuid.uuid4().hex)[:20] + (uuid.uuid4().hex)[:20] x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR') if x_forwarded_for: f.remote_address = x_forwarded_for.split(',')[-1].strip() else: f.remote_address = request.META.get('REMOTE_ADDR') + "&" + request.META.get( 'HTTP_USER_AGENT') + "&" + request.META.get('SERVER_PROTOCOL') f.save() msg_ok = _(u'Kanal ekleme başarılı') else: msg_err = _(u'Dikkat! Lütfen hataları düzeltiniz!') form = ChannelForm() return render(request, "back/add.html", locals())
def new_channel(request): if request.method == 'POST': form = ChannelForm(request.POST) if form.is_valid(): channel = form.save(commit=False) channel.channel_admin = request.user channel.save() return render(request, 'channels/channelsuccess.html') # return HttpResponse('Channel Successfully Created!') else: form = ChannelForm() return render(request, 'channels/create_channel.html', {'form': form})