Ejemplo n.º 1
0
def edit_post(request, post_id=None):
    item = get_object_or_404(Post, id=post_id)
    form = PostForm(request.POST or None, instance=item)
    if form.is_valid():
        form.save()
        return redirect('/')
    return render(request, 'blog/post_form.html', {'form': form})
Ejemplo n.º 2
0
def post_create(request):
    if request.method == "POST":
        form = PostForm(request.POST)
        if form.is_valid() :
            form.save()
            return redirect('home:main')
        else :
            return HttpResponse("404")
    else :
        form = PostForm()
        return render(request, "home/post_create.html", {'form': form})
Ejemplo n.º 3
0
def post_update(request, slug_url):
    post = get_object_or_404(Post, slug=slug_url)
    if request.method == "POST":
        form = PostForm(request.POST, request.FILES, instance=post)
        if form.is_valid():
            form.save()
            return redirect(post)
        else :
            return HttpResponse("404")
    else :
        form = PostForm(instance=post)
        return render(request, "home/post_create.html", {'form': form})
Ejemplo n.º 4
0
def post_new(request):
    form = PostForm()
    context = {}
    context['category'] = Category.objects.all()

    if request.method == "POST":
        form = PostForm(request.POST)
        context['form'] = form
        if form.is_valid():
            post = form.save(commit=False)
            post.user = request.user
            # post.created = timezone.now()
            form.save()
            return redirect('/')
    return render(request, 'post_edit.html', context)
Ejemplo n.º 5
0
def post(request):
	
	companies = Company.objects.get(id__exact=4)
	posts=Post.objects.get(Industry_id__exact=3)
	
	if request.method == 'POST':
		form = PostForm(request.POST, request.FILES or None)
		print(form.errors)
		if form.is_valid():
			
			form.save()
			return redirect('home')
	else:
		form = PostForm()

	context = {'form' : form,'posts':posts,'companies':companies}
	return render(request,'home/contactform.html',context)
Ejemplo n.º 6
0
def add_post(request):
    if request.method == "POST":
        form = PostForm(request.POST)
        if form.is_valid():
            post_item = form.save(commit=False)
            post_item.save()
            return redirect('/')
    else:
        form = PostForm()
    return render(request, 'blog/post_form.html', {'form': form})
Ejemplo n.º 7
0
def classes_create(request):
    form = PostForm(request.POST or None, request.FILES or None)

    if form.is_valid():
        create = form.save(commit=False)
        create.save()

        return redirect('home:class')

    args = {'form': form}

    return render(request, 'home/class_create.html', args)
Ejemplo n.º 8
0
def CreatePost(request):
    if request.method == 'POST':
        form = PostForm(request.POST)
        if form.is_valid():
            instance = form.save(commit=False)
            instance.author_name = request.user
            instance.save()
            messages.success(request, "Posted Successfully Article")
            return redirect('home:post_detail', instance.id)
    else:
        form = PostForm()
    context = {'form': form}
    return render(request, 'home/create_post.html', context)
Ejemplo n.º 9
0
    def post(self, request):
        form = PostForm(request.POST)
        if form.is_valid():
            post = form.save(commit=False)
            post.user = request.user
            post.save()

            text = form.cleaned_data['text']
            form = PostForm()
            return redirect('home')

        args = {'form': form, 'text': text}
        return render(request, self.template_name, args)
Ejemplo n.º 10
0
def post_edit(request, pk):

    post = get_object_or_404(forumPost, pk=pk)
    if request.method == "POST":
        form = PostForm(request.POST, instance=post)
        if form.is_valid():
            post = form.save(commit=False)
            post.author = request.user
            post.is_edited = True
            post.publish()
            return thread_view(request, pk)
    else:
        form = PostForm(instance=post)
    return render(request, 'home/post_edit.html', {'form': form})
Ejemplo n.º 11
0
    def post(self, request, pk):
        post = get_object_or_404(Post, pk=pk)
        form = PostForm(request.POST, instance=post)
        if form.is_valid():
            post = form.save(commit=False)
            post.user = request.user
            post.save()

            text = form.cleaned_data['text']
            form = PostForm(instance=post)
            return redirect('home')

        args = {'form': form, 'text': text}
        return render(request, self.template_name, args)
Ejemplo n.º 12
0
def post_edit(request, id):
    context = {}
    context['category'] = Category.objects.all()
    post = get_object_or_404(Post, id=id)
    if request.method == "POST":
        form = PostForm(request.POST, instance=post)
        context['form'] = form
        if form.is_valid():
            post = form.save(commit=False)
            post.user = request.user
            post.created = timezone.now()
            post.save()
            return redirect('/post/%s' % id)
    else:
        form = PostForm(instance=post)
    return render(request, 'post_edit.html', context)
Ejemplo n.º 13
0
def classes_update(request, id):
    try:
        instance = Classes.objects.get(id=id)
    except Classes.DoesNotExist:
        instance = None

    form = PostForm(request.POST or None, instance=instance)

    if form.is_valid():
        instance = form.save(commit=False)
        instance.save()
        return redirect(reverse('home:class'))

    context = {
        "title": instance.title,
        "instance": instance,
        'form': form,
    }
    return render(request, "home/class_update.html", context)
Ejemplo n.º 14
0
def user_register(request):
    if (request.method=="POST"):
        postform = PostForm(request.POST, request.FILES)
        #print postform
        user_name = request.user   
        postform.user = user_name
        
        if postform.is_valid():
            
            profile = postform.save(commit=False)
            print profile.post
            
            profile.user = request.user
            profile.time=timezone.now() 
            #print profile.user        
            profile.save()
            messages.success(request, 'Your post submitted Successfully')
    else:                    
        postform = PostForm()
    return render(request, "home/post.html", { 'postform' : postform })
Ejemplo n.º 15
0
def add_post(request):
    if request.method == 'POST':
        form = PostForm(request.POST)
        next_url = request.POST.get('next', '/')
        if form.is_valid():
            post = form.save(commit=False)
            post.user = request.user
            post.save()
            tags = form.cleaned_data['tags'].split(',')
            for tag in tags:
                post.tags.add(tag.strip())
            post.save()
            return redirect(next_url)
        else:
            if 'public' in next_url:
                return public_posts(request, form)
            if 'user' in next_url:
                return user_page(request, request.user, form)
            return index(request, form)

    return redirect('home')
Ejemplo n.º 16
0
def post_new_thread(request, pk):

    if not request.user.is_authenticated():
        return redirect('signlog_in')

    if request.method == "POST":
        form = PostForm(request.POST)

    else:
        form = PostForm()

    if form.is_valid():
        post = form.save(commit=False)
        post.idUser = User.objects.get(username=request.user.username)
        post.forumSubCategory = forumSubCategory.objects.get(pk=pk)
        post.publish()
        post.save()
        return redirect('index')
    context = contextDefault.copy()
    title = 'Add new Post'
    context.update({'title': title, 'form': form})
    return render(request, 'home/post_new.html', context)