示例#1
0
def contenaddimage(request, id):
    if request.method == 'POST':
        lasturn = request.META.get('HTTP_REFERER')
        form = ContenImageForm(request.POST, request.FILES)
        if form.is_valid():
            data = CImages()
            data.title = form.cleaned_data['title']
            data.content_id = id
            data.image = form.cleaned_data['image']
            data.save()
            messages.success(request, 'İçerik başarı ile yüklendi')
            return HttpResponseRedirect(lasturn)
        else:
            messages.warning(request, 'Form hatası:' + str(form.errors))
            return HttpResponseRedirect(lasturn)
    else:
        content = Content.objects.get(id=id)
        images = CImages.objects.filter(content_id=id)
        form = ContenImageForm()
        context = {
            'content': content,
            'images': images,
            'form': form,
        }
        return render(request, 'content_gallery.html', context)
示例#2
0
def contenaddimage(request,id):
    if request.method == 'POST':
        lasturl= request.META.get('HTTP_REFERER')
        form = ContentImageForm(request.POST, request.FILES)
        if form.is_valid():
            data = CImages()
            data.title = form.cleaned_data['title']
            data.content_id = id
            data.image = form.cleaned_data['image']
            data.save()
            return HttpResponseRedirect(lasturl)
        else:
            return HttpResponseRedirect(lasturl)

    else:
        content = Content.objects.get(id=id)
        images=[]
        try:
            images = CImages.objects.filter(content_id=id)
        except:
            pass
        form= ContentImageForm()
        context = {
            'content':content,
            'images':images,
            'form':form,
        }
        return render (request,'content_gallery.html',context)
def contentaddimage(request, id):
    setting = Setting.objects.get(pk=1)
    if request.method == 'POST':
        lasturl = request.META.get('HTTP_REFERER')
        form = ContentImageForm(request.POST, request.FILES)
        if form.is_valid():
            data = CImages()
            data.title = form.cleaned_data['title']
            data.content_id = id
            data.image = form.cleaned_data['image']
            data.save()
            messages.success(request,
                             'Your image has been successfully uploaded')
            return HttpResponseRedirect(lasturl)
        else:
            messages.warning(request, 'Form Error :', +str(form.errors))
            return HttpResponseRedirect(lasturl)
    else:
        content = Content.objects.get(id=id)
        images = CImages.objects.filter(content_id=id)
        form = ContentImageForm()
        context = {
            'content': content,
            'images': images,
            'form': form,
            'setting': setting,
        }
        return render(request, 'content_gallery.html', context)
示例#4
0
def contentaddimage(request, id):
    if request.method == 'POST':
        lasturl = request.META.get('HTTP_REFERER')
        form = CImagesForm(request.POST, request.FILES)
        if form.is_valid():
            data = CImages()
            data.title = form.cleaned_data['title']
            data.image = form.cleaned_data['image']
            data.content_id = id
            data.save()
            messages.success(request, 'Image has been successfully uploaded!')
            return HttpResponseRedirect(lasturl)
        else:
            messages.warning(request, 'Form Error:' + str(form.errors))
            return HttpResponseRedirect(lasturl)
    else:
        content = get_object_or_404(Content, id=id)
        try:
            images = CImages.objects.filter(content_id=id)
        except:
            images = []
        form = CImagesForm()
        context = {
            'content': content,
            'images': images,
            'form': form
        }
        return render(request, 'user_content_gallery.html', context)
示例#5
0
def contenaddimage(request,id):
    if request.method == 'POST':
        lasturl = request.META.get('HTTP_REFERER')
        form = ContentImageForm(request.POST, request.FILES)
        if form.is_valid():
            data = CImages()
            data.title = form.cleaned_data['title']
            data.content_id = id
            data.image = form.cleaned_data['image']
            data.save()   # veritabanına kaydet
            messages.success(request, 'Your image has been successfully uploaded!')
            return HttpResponseRedirect(lasturl)
        else:
            messages.error(request, 'Form Error :' + str(form.errors))
            return HttpResponseRedirect(lasturl)
    else:
        content = Content.objects.get(id=id)
        images = []
        try:
            images = CImages.objects.filter(content_id=id)
        except:
            pass
        form = ContentImageForm()
        return render(request, 'content_gallery.html', {'form': form, 'content': content, 'images': images, })