Skip to content

Commit

Permalink
Check_2
Browse files Browse the repository at this point in the history
  • Loading branch information
smaspb17 committed Mar 18, 2023
1 parent 88e240b commit c67383d
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 55 deletions.
6 changes: 5 additions & 1 deletion yatube/posts/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ class PostForm(forms.ModelForm):
class Meta:
model = Post
# fields = '__all__'
fields = ('text', 'group', 'image')
fields = ('text', 'group', 'image',)
labels = {'image': 'Картинка'}
help_texts = {'image': 'Загрузите картинку'}


class CommentForm(forms.ModelForm):
class Meta:
model = Comment
fields = ('text',)
labels = {'text': 'Коментарий'}
help_text = {'text': 'Ваш коментарий'}
2 changes: 2 additions & 0 deletions yatube/posts/tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from django.contrib.auth import get_user_model
from django.test import Client, TestCase, override_settings
from django.urls import reverse
from django.core.cache import cache

from posts.forms import PostForm
from posts.models import Group, Post, Comment
Expand Down Expand Up @@ -33,6 +34,7 @@ def setUp(self):
self.guest_client = Client()
self.authorized_client = Client()
self.authorized_client.force_login(self.author)
cache.clear()

def test_posts_forms_create_post(self):
"""Cоздание формы поста."""
Expand Down
25 changes: 0 additions & 25 deletions yatube/posts/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
class PostModelTest(TestCase):

def test_models_have_correct_object_names(self):
"""В модели Post корректно работает __str__."""
long_post = Post(
text='Не более 15 символов может уместиться в превью'
)
Expand All @@ -17,7 +16,6 @@ def test_models_have_correct_object_names(self):
self.assertEqual(str(post), 'Короткий пост')

def test_models_have_correct_object_names2(self):
"""В модели Group корректно работает __str__."""
group = Group(title="Тестовая группа")
expected_object_name = group.title
self.assertEqual(expected_object_name, str(group))
Expand All @@ -39,26 +37,3 @@ def test_help_text_values(field):
'Введите текст поста_h')
self.assertEqual(test_help_text_values('group'),
'Группа, к которой будет относиться пост_h')

# def test_verbose_name_values(self):
# """Корректный verbose_name у полей модели Post."""
# field_values = {
# 'text': 'Текст поста_v',
# 'author': 'Автор публикации_v',
# 'group': 'Группа_v',
# }
# for field, value in field_values.items():
# with self.subTest(field=field):
# verbose = Post._meta.get_field(field).verbose_name
# self.assertEqual(verbose, value)

# def test_help_text_values(self):
# """Корректный help_text у полей модели Post."""
# field_values = {
# 'text': 'Введите текст поста_h',
# 'group': 'Группа, к которой будет относиться пост_h',
# }
# for field, value in field_values.items():
# with self.subTest(field=field):
# help_text = Post._meta.get_field(field).help_text
# self.assertEqual(help_text, value)
1 change: 1 addition & 0 deletions yatube/posts/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def setUp(self):
self.user2 = User.objects.create_user(username='notfollower')
self.authorized_client2 = Client()
self.authorized_client2.force_login(self.user2)
cache.clear()

def posts_check_all_fields(self, post):
"""Корректность полей поста."""
Expand Down
33 changes: 4 additions & 29 deletions yatube/posts/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# from django.views.decorators.cache import cache_page

from django.contrib.auth.models import User
from django.shortcuts import render, get_object_or_404, redirect
Expand All @@ -19,9 +18,8 @@ def paginator(request, posts):
return page_obj


# @cache_page(60 * 20, key_prefix='index_page')
def index(request):
post_list = Post.objects.all()
post_list = Post.objects.all().select_related('author')
page_obj = paginator(request, post_list)
context = {
'page_obj': page_obj,
Expand All @@ -47,6 +45,7 @@ def profile(request, username):
posts = author.posts.select_related('group', 'author')
page_obj = paginator(request, posts)
post_count = author.posts.select_related('group', 'author').count()
follower_count = Follow.objects.filter(user=user).count()
following = (
user.is_authenticated
and Follow.objects.filter(user=user, author=author)
Expand All @@ -57,6 +56,7 @@ def profile(request, username):
'username': author,
'posts': posts,
'following': following,
'follower_count': follower_count,
}
return render(request, 'posts/profile.html', context)

Expand Down Expand Up @@ -166,30 +166,5 @@ def profile_unfollow(request, username):
user=user,
author=author
)
if follow.exists():
follow.delete()
follow.delete()
return redirect('posts:profile', username)


'''
@login_required # декоратор авторизации
def post_edit(request, post_id):
template = 'posts/create_post.html'
post = get_object_or_404(Post, pk=post_id)
if post.author != request.user:
return redirect('posts:post_detail', post_id)
if request.method == "POST":
form = PostForm(request.POST, instance=post)
if form.is_valid():
form.save()
return redirect('posts:post_detail', post_id)
return render(
request,
'posts/create_post.html',
{'form': form, 'is_edit': True}
)
form = PostForm(instance=post)
return render(request, template,
{'form': form, 'is_edit': True,
'post': post})
'''
1 change: 1 addition & 0 deletions yatube/templates/posts/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<div class="mb-5">
<h1>Все посты пользователя {{ username }} </h1>
<h3>Всего постов: {{ post_count }} </h3>
<h3>Всего подписчиков: {{ follower_count }} </h3>
{% if following %}
<a
class="btn btn-lg btn-light"
Expand Down

0 comments on commit c67383d

Please sign in to comment.