Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def index(request):
- if request.method == 'POST':
- post_form = AddPostForm(request.POST)
- comment_form = AddCommentForm(request.POST)
- # FORMULARZ DODAWANIA POSTU
- if post_form.is_valid():
- new_post = post_form.save(commit=False)
- new_post.author = request.user
- new_post.tags = ''
- content = ''
- for word in new_post.content_post.split():
- if '#' in word:
- # tag_length = len(word) + 1
- new_post.tags += f"{word} "
- content += f"{word} "
- # new_post.content_post = new_post.content_post[:-tag_length]
- else:
- content += f"{word} "
- new_post.content_post = content
- new_post.save()
- for word in content.split():
- if '@' in word:
- print(word)
- user_to_notificate = CustomUser.objects.get(username=word[1:])
- new_notification = TalkAbout()
- new_notification.where = new_post
- new_notification._from = new_post.author
- new_notification.to = user_to_notificate
- new_notification.sended = False
- print(new_notification)
- new_notification.save()
- post_form = AddPostForm()
- # FORMULARZ DODAWANIA KOMENTARZA
- if comment_form.is_valid():
- new_comment = comment_form.save(commit=False)
- new_comment.author = request.user
- new_comment.save()
- comment_form = AddCommentForm()
- else:
- post_form = AddPostForm()
- comment_form = AddCommentForm()
- if request.user.is_authenticated:
- logged_user = CustomUser.objects.get(id=request.user.id)
- blocked_users = logged_user.blocked.all()
- posts = Post.objects.exclude(author__in=blocked_users)
- print(blocked_users)
- posts = posts.order_by('-pub_date')
- else:
- posts = Post.objects.all()
- posts = posts.order_by('-pub_date')
- comments = Comment.objects.all()
- comments = comments.order_by("-pub_date")
- return render(request, 'mikroblog/index.html', {'posts': posts, 'comments': comments,
- 'post_form': post_form, 'comment_form': comment_form})
Add Comment
Please, Sign In to add comment