def ticket(request, id): if not check(request): return redirect(reverse('accounts:logout')) ticket = get_object_or_404(Ticket, id=id) # The specific ticketdetail comments = Comment.objects.filter( ticket=ticket ) # All comments for this (ticket variable) specific ticketdetail if request.method == 'POST': form = CommentForm( request.POST) # The populated form for the new comment if form.is_valid(): comment = form.save( commit=False ) # Assign form to comment variable without saving to data base. I need to change something first. comment.ticket = ticket # Added the current ticket to the comment's foreign key 'ticket'. comment.user_id = request.user.id # User Id comment.save() # Save changes form = CommentForm() # reset form for new comments # Return template return render(request, 'tracker/ticketdetail.html', { 'ticket': ticket, 'comments': comments, 'form': form }) else: form = CommentForm() return render(request, 'tracker/ticketdetail.html', { 'ticket': ticket, 'comments': comments, 'form': form })
def settings(request): if not check(request): return redirect(reverse('accounts:logout')) return render(request, 'accounts/settings.html', { "subscription": request.user.subscription, "pubkey": pubKey })
def post_detail(request, id): if not check(request): return redirect(reverse('accounts:logout')) post = get_object_or_404(Post, pk=id) post.views += 1 post.save() return render(request, "blog/postdetail.html", {'post': post})
def new_post(request): if not check(request): return redirect(reverse('accounts:logout')) # only staff can make blog posts if not request.user.is_staff: return redirect('blog:postlist') form = BlogPostForm() return render(request, 'blog/blogpostform.html', {'form': form})
def edit_post(request, id): if not check(request): return redirect(reverse('accounts:logout')) # only staff can make blog posts if not request.user.is_staff: return redirect('blog:postlist') post = get_object_or_404(Post, pk=id) form = BlogPostForm(instance=post) return render(request, 'blog/blogpostform.html', {'form': form, 'id': id})
def form(request): if not check(request): return redirect(reverse('accounts:logout')) # Temp - Process form if request.method == 'POST': form = TicketForm(request.POST) if form.is_valid(): form = form.save(commit=False) form.user_id = request.user.id # form.submitted = timezone.now # form.modified = '' form.save() # return render(request,'tracker/index.html',{'form':form}) return redirect('tracker:index') else: # Temp - Display form form = TicketForm() return render(request, 'tracker/form.html', {'form': form})
def profile(request): if not check(request): return redirect(reverse('accounts:logout')) print(request.user) user = get_object_or_404(User, id=request.user.id) args = {} try: allTickets = Ticket.objects.all() tickets = Ticket.objects.filter(user=user) comments = Comment.objects.filter(user=user) votes = UpVote.objects.filter(user=user) args['alltickets'] = allTickets args['tickets'] = tickets args['votes'] = votes except Exception as e: print e return render(request, 'accounts/profile.html', args)
def posts_view(request): if not check(request): return redirect(reverse('accounts:logout')) posts = Post.objects.filter( published_date__lte=timezone.now()).order_by('-published_date') return render(request, "blog/posts.html", {'posts': posts})