-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add posts search option to feed (#131)
- Search posts by username, profession, decripation of post. - Delete search from tool bar. - Create search.html file. - Add tests to search. Co-authored-by: yulisuliman <[email protected]> Co-authored-by: TomerNewmanPrograms <[email protected]> Co-authored-by: TomerNewmanPrograms <[email protected]>
- Loading branch information
1 parent
f26b5e3
commit d75b7f9
Showing
7 changed files
with
253 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,73 @@ | ||
{% extends "base.html" %} | ||
{% load static %} | ||
{% block styles %} | ||
<link rel="stylesheet" type="text/css" href="{% static 'posts/feed.css' %}"> | ||
{% endblock styles %} | ||
{% block content %} | ||
{% if searched %} | ||
<br/> | ||
{% if posts %} | ||
<h5>You Searched For: {{searched}}</h5> | ||
{% for post in posts %} | ||
<article class="content-section"> | ||
<div class="media-body"> | ||
<div class="post-header"> | ||
<div class="article-metadata"> | ||
<img class="rounded-circle article-img" src="{{ post.author.profile.profile_pic.url }}"> | ||
<a class="mr-2" href="#">{{ post.author }}</a> | ||
<small class="text-muted">{{ post.date_posted|date:"F d, Y" }}</small> | ||
</div> | ||
<div class="menu-nav"> | ||
<div class="dropdown-container" tabindex="-1"> | ||
<div class="three-dots"></div> | ||
<div class="dropdown"> | ||
<a href="{% url 'post-detail' post.pk %}" class="btn btn-outline-secondary btn-light btn-sm" ><div>Go to post</div></a> | ||
{% if post.author == user %} | ||
{% if post.resume %} | ||
<a href="{% url 'resume-update' post.pk %}" class="btn btn-outline-secondary btn-light btn-sm"><div>Edit post</div></a> | ||
{% endif %} | ||
<a href="{% url 'post-delete' post.pk %}" class="btn btn-outline-danger btn-light btn-sm" ><div>Delete post</div></a> | ||
{% endif %} | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<p class="article-content">{{ post.description }}</p> | ||
<div class="file-and-comments"> | ||
{% if post.resume %} | ||
<iframe src="{{ post.resume.resume_file.url }}" style="width: 560px;height: 780px ;border: none;"></iframe> | ||
{% endif %} | ||
<div class="comments-block"> | ||
<div class="buttons"> | ||
{% if post.resume %} | ||
{% include 'posts/rating_view.html' %} | ||
{% if post.author != user %} | ||
<div> | ||
<a href="{% url 'create-a-rate' post.pk %}"><button type="button" class="btn btn-secondary">Rate ResuMe</button></a> | ||
<hr> | ||
</div> | ||
{% endif %} | ||
{% endif %} | ||
<a href="{% url 'comment-create' post.pk %}"><button type="button" class="btn btn-secondary">Add comment</button></a> | ||
<hr> | ||
</div> | ||
{% for comment in post.comment_set.all %} | ||
<div class="comment-data"> | ||
<img class="rounded-circle article-img" src="{{ comment.author.profile.profile_pic.url }}"> | ||
<a class="mr-2" href="#">{{ comment.author }}</a> | ||
<hr class="comment-hr"> | ||
<p class="comment-content">{{ comment.comment_text }}</p> | ||
</div> | ||
{% endfor %} | ||
</div> | ||
</div> | ||
</div> | ||
</article> | ||
{% endfor %} | ||
{% else %} | ||
<h5>{{searched}} does not match any results!</h5> | ||
{% endif %} | ||
{% else %} | ||
<h5>You Forgot To Search ...</h5> | ||
{% endif %} | ||
{% endblock content %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import pytest | ||
from pytest_django.asserts import assertTemplateUsed | ||
|
||
|
||
@pytest.mark.django_db | ||
class TestViews: | ||
|
||
search_url = '/search/?searched=' | ||
|
||
def test_searching_usernames_posts_view(self, client, persist_user, persist_post): | ||
'''test searching for an exist post by username, | ||
also testing for template and status code response''' | ||
response = client.get(f'{self.search_url}{persist_user.username}') | ||
assert response.status_code == 200 | ||
assertTemplateUsed(response, 'posts/search.html') | ||
assert persist_post in response.context['posts'] | ||
|
||
def test_serching_professions_posts_view(self, client, persist_user, persist_post): | ||
'''test searching for an exist post by user's profession | ||
also testing for template and status code response''' | ||
response = client.get(f'{self.search_url}{persist_user.profile.profession}') | ||
assert response.status_code == 200 | ||
assertTemplateUsed(response, 'posts/search.html') | ||
assert persist_post in response.context['posts'] | ||
|
||
def test_searching_descriptions_posts_view(self, client, persist_post): | ||
'''test searching for an exist post by post's description, | ||
also testing for template and status code response''' | ||
response = client.get(f'{self.search_url}{persist_post.description}') | ||
assert response.status_code == 200 | ||
assertTemplateUsed(response, 'posts/search.html') | ||
assert persist_post in response.context['posts'] | ||
|
||
def test_searching_for_a_non_existing_user_posts_in_view(self, client, persist_user, persist_post): | ||
'''test searching for a non exist post by username, | ||
also testing for template and status code response''' | ||
persist_user.delete() | ||
response = client.get(f'{self.search_url}{persist_user.username}') | ||
assert response.status_code == 200 | ||
assertTemplateUsed(response, 'posts/search.html') | ||
assert persist_post not in response.context['posts'] | ||
|
||
def test_searcing_a_non_existing_post_view(self, client, persist_user, persist_post): | ||
'''test searching for a non exist post, | ||
also testing for template and status code response''' | ||
persist_post.delete() | ||
response = client.get(f'{self.search_url}{persist_post.description}') | ||
assert response.status_code == 200 | ||
assertTemplateUsed(response, 'posts/search.html') | ||
assert persist_post not in response.context['posts'] |