def addcontent(request):
    if request.method == 'POST':
        form = ContentForm(request.POST, request.FILES)
        if form.is_valid():
            current_user = request.user
            data = Content()
            data.user_id = current_user.id
            data.title = form.cleaned_data['title']
            data.keywords = form.cleaned_data['keywords']
            data.description = form.cleaned_data['description']
            data.image = form.cleaned_data['image']
            data.type = form.cleaned_data['type']
            data.slug = form.cleaned_data['slug']
            data.detail = form.cleaned_data['detail']
            data.status = 'False'
            data.save()   # veritabanına kaydet
            messages.success(request, 'Your content insterted successfully!')
            return HttpResponseRedirect('/user/contents')
        else:
            messages.error(request, 'Content Form Error :' + str(form.errors))
            return HttpResponseRedirect('/user/addcontent')
    else:
        category = Category.objects.all()
        menu = Menu.objects.all()
        form = ContentForm()
        return render(request, 'user_addcontent.html', {'form': form, 'category': category, 'menu': menu, })
Exemple #2
0
def addcontent(request):
    if request.method == 'POST':
        form = ContentForm(request.POST, request.FILES)
        if form.is_valid():
            current_user = request.user
            data = Content()
            data.user_id = current_user.id
            data.title = form.cleaned_data['title']
            data.price = form.cleaned_data['price']
            data.keywords = form.cleaned_data['keywords']
            data.description = form.cleaned_data['description']
            data.image = form.cleaned_data['image']
            data.type = form.cleaned_data['type']
            data.slug = form.cleaned_data['slug']
            data.detail = form.cleaned_data['detail']
            data.status = 'False'
            data.save()
            messages.success(request, "İçerik başarı ile eklendi")
            return HttpResponseRedirect('/user/contents')
        else:
            messages.success(request, 'İçerik form hatası' + str(form.errors))
            return HttpResponseRedirect('/user/addcontent')
    else:
        category = Category.objects.all()
        menu = Menu.objects.all()
        form = ContentForm()
        context = {
            'category': category,
            'form': form,
            'menu': menu,
        }
        return render(request, 'user_addcontent.html', context)
Exemple #3
0
def addcontent(request):
    if request.method == "POST":
        form = ContentForm(request.POST, request.FILES)
        if form.is_valid():
            data = Content()
            data.user_id = request.user.id
            data.title = form.cleaned_data['title']
            data.keywords = form.cleaned_data['keywords']
            data.description = form.cleaned_data['description']
            data.image = form.cleaned_data['image']
            data.kind = form.cleaned_data['kind']
            data.slug = form.cleaned_data['slug']
            data.detail = form.cleaned_data['detail']
            data.status = "False"
            data.save()
            messages.success(request, 'Content added!')
            return HttpResponseRedirect('/user/contents')
        else:
            messages.warning(request, 'Content Form Error:' + str(form.errors))
            return HttpResponseRedirect('/user/addcontent')
    else:
        setting = Setting.objects.first()
        category = Category.objects.filter(status=True)
        menu = Menu.objects.filter(status=True)
        form = ContentForm()
        context = {
            'setting': setting,
            'category': category,
            'menu': menu,
            'page': 'Add Content',
            'form': form
        }
        return render(request, 'user_addcontent.html', context)
def addcontent(request):
    if request.method == 'POST':
        form = ContentForm(request.POST, request.FILES)  # fileupload varsa request.FILES yapmazsak formumuz çalışmaz
        if form.is_valid():
            current_user = request.user
            data = Content()  # model ile bağlantı kur
            data.user_id = current_user.id
            data.title = form.cleaned_data['title']
            data.keywords = form.cleaned_data['keywords']
            data.description = form.cleaned_data['description']
            data.image = form.cleaned_data['image']
            data.type = form.cleaned_data['type']
            data.slug = form.cleaned_data['slug']
            data.detail = form.cleaned_data['detail']
            data.status = 'False'
            data.save()  # veritabanına kaydet
            messages.success(request, 'İçeriğiniz başarılı bir şekilde eklendi !')
            return HttpResponseRedirect("/user/contents")
        else:
            messages.error(request, 'İçerik Form Hatası : ' + str(
                form.errors))  # bunu buraya yazabilmemiz için stringe çevirmemiz lazım on yüzden str yazıyoruz
            return HttpResponseRedirect('/user/addcontent')
    else:
        menu = Menu.objects.all()
        form = ContentForm()  # content form ile ilişki kuruyorum
        context = {
            'form': form,
            'menu': menu
        }
        return render(request, 'user_addcontent.html', context)
def addcontent(request):
    if request.method == 'POST':
        form = ContentForm(request.POST, request.FILES)
        if form.is_valid():
            current_user = request.user
            data = Content()
            data.user_id = current_user.id
            data.title = form.cleaned_data['title']
            data.keywords = form.cleaned_data['keywords']
            data.description = form.cleaned_data['description']
            data.thumbnail = form.cleaned_data['thumbnail']
            data.type = form.cleaned_data['type']
            data.slug = form.cleaned_data['slug']
            data.detail = form.cleaned_data['detail']
            data.status = 'False'
            data.save()
            messages.success(request, 'İçeriğin başarıyla eklendi.')
            return HttpResponseRedirect('/user/contents')
        else:
            messages.warning(request, 'Content Form Hata:' + str(form.errors))
            return HttpResponseRedirect('/user/addcontent')
    else:
        setting = Settings.objects.get(pk=1)
        category = Category.objects.all()
        form = ContentForm()
        context = {
            'setting': setting,
            'category': category,
            'form': form,
        }
        return render(request, 'user_addcontent.html', context)
Exemple #6
0
def add_content(request):
    if request.method == 'POST':
        form = ContentForm(request.POST, request.FILES)
        if form.is_valid():
            current_user = request.user
            data = Content()
            data.user_id = current_user.id
            data.category = form.cleaned_data['category']
            data.title = form.cleaned_data['title']
            data.keywords = form.cleaned_data['keywords']
            data.description = form.cleaned_data['description']
            data.image = form.cleaned_data['image']
            data.slug = form.cleaned_data['slug']
            data.detail = form.cleaned_data['detail']
            data.status = 'False'
            data.save()
            messages.success(request, 'Your trip has been added.')
            return HttpResponseRedirect('/user/contents')
        else:
            messages.error(request, 'Content Form Error: ', + str(form.errors))
            return HttpResponseRedirect('/user/add_content')
    else:
        form = ContentForm()
        context = {
            'form': form
        }
        return render(request, 'add_content.html', context)
def contentedit(request, id):
    setting = Setting.objects.get(pk=1)
    content = Content.objects.get(id=id)
    current_user = request.user
    profile = UserProfile.objects.get(user_id=current_user.id)
    if request.method == 'POST':
        form = ContentForm(request.POST, request.FILES, instance=content)
        if form.is_valid():
            form.save()
            messages.success(request, 'Your Content Updated Succesfully')
            return HttpResponseRedirect('/user/contents')
        else:
            messages.success(request,
                             'Content Form Error : ' + str(form.errors))
            return HttpResponseRedirect('/user/contentedit/' + str(id))
    else:
        category = Categories.objects.all()
        menu = Menu.objects.all()
        form = ContentForm(instance=content)
        context = {
            'category': category,
            'menu': menu,
            'form': form,
            'profile': profile,
            'setting': setting,
        }
        return render(request, 'user_addcontent.html', context)
Exemple #8
0
def contentedit(request, id):
    content = get_object_or_404(Content, id=id, user_id=request.user.id)
    if request.method == 'POST':
        form = ContentForm(request.POST, request.FILES, instance=content)
        if form.is_valid():
            form.save()
            messages.success(request, 'Content updated successfuly!')
            return HttpResponseRedirect('/user/contents')
        else:
            messages.warning(request, 'Content Form Error: '+str(form.errors))
            return HttpResponseRedirect('/user/contentedit/id')
    else:
        setting = Setting.objects.first()
        category = Category.objects.filter(status=True)
        menu = Menu.objects.filter(status=True)
        contents = Content.objects.filter(user_id=request.user.id)
        form = ContentForm(instance=content)
        context = {
            'setting': setting,
            'category': category,
            'menu': menu,
            'contents': contents,
            'form': form,
            'page': 'Edit Content'
        }
        return render(request, 'user_addcontent.html', context)
def addcontent(request):
    setting = Setting.objects.get(pk=1)
    current_user = request.user
    profile = UserProfile.objects.get(user_id=current_user.id)
    if request.method == 'POST':
        form = ContentForm(request.POST, request.FILES)
        if form.is_valid():
            current_user = request.user
            data = Content()
            data.user_id = current_user.id
            data.title = form.cleaned_data['title']
            data.keywords = form.cleaned_data['keywords']
            data.description = form.cleaned_data['description']
            data.image = form.cleaned_data['image']
            data.type = form.cleaned_data['type']
            data.slug = form.cleaned_data['slug']
            data.detail = form.cleaned_data['detail']
            data.status = 'False'
            data.save()
            messages.success(request, 'Your Content Inserted Succesfully')
            return HttpResponseRedirect('/user/contents')
        else:
            messages.success(request,
                             'Content Form Error : ' + str(form.errors))
            return HttpResponseRedirect('/user/addcontent')
    else:
        category = Categories.objects.all()
        menu = Menu.objects.all()
        form = ContentForm()
        context = {
            'category': category,
            'menu': menu,
            'form': form,
            'profile': profile,
            'setting': setting,
        }
        return render(request, 'user_addcontent.html', context)
def contentedit(request,id):
    content = Content.objects.get(id=id)
    if request.method == 'POST':
        form = ContentForm(request.POST, request.FILES, instance=content)
        if form.is_valid():
            form.save()
            messages.success(request, 'Your content updated successfully!')
            return HttpResponseRedirect('/user/contents')
        else:
            messages.error(request, 'Content Form Error :' + str(form.errors))
            return HttpResponseRedirect('/user/contentedit./'+str(id))
    else:
        category = Category.objects.all()
        menu = Menu.objects.all()
        form = ContentForm(instance=content)
        return render(request, 'user_addcontent.html', {'form': form, 'category': category, 'menu': menu, })
Exemple #11
0
def edit_content(request, id):
    content = Content.objects.get(id=id)
    if request.method == 'POST':
        form = ContentForm(request.POST, request.FILES, instance=content)
        if form.is_valid():
            form.save()
            messages.success(request, 'Your trip has been updated.')
            return HttpResponseRedirect('/user/contents')
        else:
            messages.error(request, 'Content Form Error: ', + str(form.errors))
            return HttpResponseRedirect('/user/edit_content/' + str(id))
    else:
        form = ContentForm(instance=content)
        context = {
            'form': form
        }
        return render(request, 'add_content.html', context)
Exemple #12
0
def contentedit(request,id):
    content = Content.objects.get(id=id)
    if request.method == 'POST':
        form = ContentForm(request.POST, request.FILES, instance=content)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/user/contents')
        else:
            return HttpResponseRedirect('/user/contentedit/'+str(id))
    else:
        category = Category.objects.all()
        menu = Menu.objects.all()
        form = ContentForm(instance=content)
        context = {
            'menu':menu,
            'category':category,
            'form':form,
        }
        return render(request,'user_addcontent.html', context)
def contentedit(request,id):
    content = Content.objects.get(id=id) #mevcut içeriğin id'sini gönderiyorum
    if request.method == 'POST':
        form = ContentForm(request.POST, request.FILES, instance=content)  # fileupload varsa request.FILES yapmazsak formumuz çalışmaz
        if form.is_valid():
            form.save()  # veritabanına kaydet
            messages.success(request, 'İçeriğiniz başarılı bir şekilde güncellendi !')
            return HttpResponseRedirect("/user/contents")  #hata yoksa listeye gönder
        else:
            messages.error(request, 'İçerik Form Hatası : ' + str(form.errors))  # bunu buraya yazabilmemiz için stringe çevirmemiz lazım on yüzden str yazıyoruz
            return HttpResponseRedirect('/user/contentedit/' + str(id)) #id'yi tekrar oluşturmam lazım
    else:
        menu = Menu.objects.all()
        form = ContentForm(instance=content)  # content form ile ilişki kuruyorum, sorgulanan contentle formu dolduruyorum
        context = {
            'form': form,
            'menu': menu
        }
        return render(request, 'user_addcontent.html', context)
Exemple #14
0
def contentedit(request, id):
    content = Content.objects.get(id=id)
    if request.method == 'POST':
        form = ContentForm(request.POST, request.FILES, instance=content)
        if form.is_valid():
            form.save()
            messages.success(request, "İçerik başarı ile düzenlendi")
            return HttpResponseRedirect('/user/contents')
        else:
            messages.success(request, 'İçerik form hatası' + str(form.errors))
            return HttpResponseRedirect('/user/contentedit' + str(id))
    else:
        category = Category.objects.all()
        menu = Menu.objects.all()
        form = ContentForm(instance=content)
        context = {
            'category': category,
            'form': form,
            'menu': menu,
        }
        return render(request, 'user_addcontent.html', context)
def contentedit(request, id):
    content = Content.objects.get(id=id)
    if request.method == 'POST':
        form = ContentForm(request.POST, request.FILES, instance=content)
        if form.is_valid():
            form.save()
            messages.success(request, 'İçeriğiniz başarıyla güncellendi.')
            return HttpResponseRedirect('/user/contents')
        else:
            messages.warning(request, 'Content Form Hata:' + str(form.errors))
            return HttpResponseRedirect('/user/contentedit' + str(id))
    else:
        setting = Settings.objects.get(pk=1)
        category = Category.objects.all()
        form = ContentForm(instance=content)
        context = {
            'setting': setting,
            'category': category,
            'form': form,
        }
        return render(request, 'user_addcontent.html', context)
Exemple #16
0
def contentedit(request, id):
    content = Content.objects.get(id=id)
    if request.method == 'POST':
        form = ContentForm(request.POST, request.FILES, instance=content)
        if form.is_valid():
            form.save()
            messages.success(
                request, "Notunuz Başarı ile Güncellenmiştir,Teşekkür Ederiz.")
            return HttpResponseRedirect('/user/contents')
        else:
            messages.warning(request, 'Content Form Error:' + str(form.errors))
            return HttpResponseRedirect('/user/contentedit/' + str(id))
    else:
        category = Category.objects.all()
        form = ContentForm(instance=content)
        menu = Menu.objects.all()
        context = {
            'menu': menu,
            'category': category,
            'form': form,
        }
        return render(request, 'user_addcontent.html', context)