Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Main #16

Merged
merged 3 commits into from
Nov 15, 2024
Merged

Main #16

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions apps/blog/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,11 @@ def get_search_model_queryset(
)

return search_query
# search_for_title = model_queryset.filter(title__icontains=search_query)
# if not search_for_title:
# search_for_content = model_queryset.filter(content__icontains=search_query)
# if not search_for_content:
# queryset = search_for_content
# else:
# queryset = search_for_content
# else:
# queryset = search_for_title
# return queryset



def get_pagination_obj(model_queryset: QuerySet, page: int = 1, size: int = 4) -> Page:
paginator = Paginator(model_queryset.order_by("id"), size)
paginator = Paginator(model_queryset.order_by("-created_at"), size)

try:
page_obj = paginator.page(page)
Expand Down
2 changes: 1 addition & 1 deletion apps/blog/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def get(self, request):
context = {
"title": "My posts",
"template_htmx": self.template_htmx,
"posts": posts
"posts": posts.order_by("-created_at")
}
return render(request, self.template_name, context)

Expand Down
17 changes: 1 addition & 16 deletions templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,7 @@
{% include 'components/headers.html' %}
<div class="mt-5">
<!-- Messages -->

{% if messages %}
{% for message in messages %}
{% if message.tags == 'error' %}
<div class="alert alert-danger alert-dismissible fade show" role="alert">
{{ message }}
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
{% else %}
<div class="alert alert-{{ message.tags }} alert-dismissible fade show" role="alert">
{{ message }}
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
{% endif %}
{% endfor %}
{% endif %}
{% include 'components/messages.html' %}

<!-- Content -->
<div id="main-content">
Expand Down
14 changes: 7 additions & 7 deletions templates/blog/post_confirm_delete.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
{% extends 'base.html' %}
{% load static %}

{% block title %} Post Confirm Delete {% endblock %}

{% block content %}
<main role="main" class="container">
<div class="row">
<div class="col-md-8">
Expand All @@ -16,14 +11,19 @@ <h4>"{{ post.title }}" ?</h4>
</fieldset>
<div class="form-group">
<button class="btn btn-outline-danger" type="submit">Yes, Delete</button>
<a class="btn btn-outline-secondary" href="{{ post.get_absolute_url }}#content">Cancel</a>
<a
class="btn btn-outline-secondary"
href="{{ post.get_absolute_url }}#content"
hx-get="{{ post.get_absolute_url }}#content"
hx-push-url="true"
hx-target="#main-content"
>Cancel</a>
</div>
</form>
</div>
</div>
{% include 'components/latest_posts.html' %}
</div>
</main>
{% endblock %}


60 changes: 52 additions & 8 deletions templates/blog/post_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@
<div class="col-md-8">
<article class="blog-post">
<h2 class="blog-post-title">{{ post.title }}</h2>
<p class="blog-post-meta">{{ post.publisher_at }}by <a href="{% url 'users:user_profile' post.author.username %}">{{ post.author }}</a></p>
<p class="blog-post-meta">{{ post.publisher_at }}by
<a
href="{% url 'users:user_profile' post.author.username %}"
hx-get="{% url 'users:user_profile' post.author.username %}"
hx-push-url="true"
hx-target="#main-content"
>{{ post.author }}</a>
</p>

<div class="text">
<p><small>{{ post.description }}</small></p>
Expand All @@ -19,19 +26,34 @@ <h2 class="blog-post-title">{{ post.title }}</h2>

<!-- Watching count-->
<div class="mb-2">
<a href="#main-content" class="nav-link text-dark">
<a
href="#main-content"
hx-get="#main-content"
hx-push-url="true"
hx-target="#main-content"
class="nav-link text-dark">
<i class="bi bi-eye">({{ post.watching }})</i>
</a>
</div>
<!-- Comments count -->
<div class="mb-2">
<a href="#post_comments" class="nav-link text-dark">
<a
href="#post_comments"
hx-get="#post_comments"
hx-push-url="true"
hx-target="#main-content"
class="nav-link text-dark">
<i class="bi bi-chat-left-text">({{ post.comment_count }})</i>
</a>
</div>
<!-- Like count -->
<div class="md-2" id="post_like_count">
<a href="{% url 'blog:post_like' post.slug %}#post_like_count" class="nav-link text-dark">
<a
href="{% url 'blog:post_like' post.slug %}#post_like_count"
hx-get="{% url 'blog:post_like' post.slug %}#post_like_count"
hx-push-url="true"
hx-target="#main-content"
class="nav-link text-dark">
{% if request.user.is_authenticated %}
{% if post|check_like:request.user %}
<i class="bi bi-star-fill">({{ post.like_count }})</i>
Expand All @@ -45,7 +67,12 @@ <h2 class="blog-post-title">{{ post.title }}</h2>
</div>
<!-- Dislike count -->
<div class="md-2" id="post_dislike_count">
<a href="{% url 'blog:post_dislike' post.slug %}#post_dislike_count" class="nav-link text-dark">
<a
href="{% url 'blog:post_dislike' post.slug %}#post_dislike_count"
hx-get="{% url 'blog:post_dislike' post.slug %}#post_dislike_count"
hx-push-url="true"
hx-target="#main-content"
class="nav-link text-dark">
{% if request.user.is_authenticated %}
{% if post|check_dislike:request.user %}
<i class="bi bi-emoji-frown-fill">({{ post.dislike_count }})</i>
Expand All @@ -61,13 +88,30 @@ <h2 class="blog-post-title">{{ post.title }}</h2>
<!-- Delete, Update buttons -->
{% if request.user == post.author %}
<nav class="blog-pagination mt-3 mb-3" aria-label="Pagination">
<a class="btn btn-outline-danger" href="{% url 'blog:post_delete' post.slug %}">delete</a>
<a class="btn btn-outline-warning" href="{% url 'blog:post_update' post.slug %}">update</a>
<a
class="btn btn-outline-danger"
href="{% url 'blog:post_delete' post.slug %}"
hx-get="{% url 'blog:post_delete' post.slug %}"
hx-push-url="true"
hx-target="#main-content"
>delete</a>
<a
class="btn btn-outline-warning"
href="{% url 'blog:post_update' post.slug %}"
hx-get="{% url 'blog:post_update' post.slug %}"
hx-push-url="true"
hx-target="#main-content"
>update</a>
</nav>
{% endif %}
<!-- Send comment message -->
<div id="post_comments_form">
<form action="{% url 'blog:post_message' post.slug %}#post_comments_form" class="mt-3 mb-3">
<form
action="{% url 'blog:post_message' post.slug %}#post_comments_form"
hx-get="{% url 'blog:post_message' post.slug %}#post_comments_form"
hx-push-url="true"
hx-target="#main-content"
class="mt-3 mb-3">
{% csrf_token %}
<div class="d-flex">
<input type="text" name="post_message_input" class="form-control" placeholder="message..." required="">
Expand Down
11 changes: 9 additions & 2 deletions templates/blog/post_update.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<main role="main" class="container">
<div class="row">
<div class="col-md-8">
<form action="{% url 'blog:post_update' post.slug %}" method="post">
<form
action="{% url 'blog:post_update' post.slug %}"
method="post">
{% csrf_token %}
<fieldset class="form-group">
<legend class="border-bottom mb-4"><b>Update post</b>: {{ post.title}}</legend>
Expand All @@ -26,7 +28,12 @@
</div>
</fieldset>
<div class="mt-3">
<a href="{{ post.get_absolute_url }}#content" class="btn btn-outline-secondary">Cancel</a>
<a
href="{{ post.get_absolute_url }}#content"
hx-get="{{ post.get_absolute_url }}#content"
hx-push-url="true"
hx-target="#main-content"
class="btn btn-outline-secondary">Cancel</a>
<button type="submit" class="btn btn-outline-primary">Update</button>
</div>
</form>
Expand Down
15 changes: 13 additions & 2 deletions templates/blog/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ <h3>

{% if request.user == user %}
<div class="col">
<a href="{% url 'blog:post_create' %}" class="btn btn-outline-secondary">Create New Post</a>
<a
href="{% url 'blog:post_create' %}"
hx-get="{% url 'blog:post_create' %}"
hx-push-url="true"
hx-target="#main-content"
class="btn btn-outline-secondary">Create New Post</a>
</div>
{% endif %}
<div class="col">
Expand All @@ -56,7 +61,13 @@ <h3>
<h3 class="mb-0">{{ post.title }}</h3>
<div class="mb-1 text-muted">{{ post.publisher_at }}</div>
<p class="card-text mb-auto">{{ post.description|truncatewords_html:30 }}</p>
<a href="{{ post.get_absolute_url }}" class="stretched-link">Continue reading</a>
<a
href="{{ post.get_absolute_url }}"
hx-get="{{ post.get_absolute_url }}"
hx-push-url="true"
hx-target="#main-content"
class="stretched-link"
>Continue reading</a>
<div class="d-flex">
<strong class="d-inline-block mb-2 col text-primary"><i class="bi bi-eye">{{ post.watching }}</i></strong>
<strong class="d-inline-block mb-2 col text-primary"><i class="bi bi-star">{{ post.like_count }}</i></strong>
Expand Down
25 changes: 17 additions & 8 deletions templates/blog/user_posts.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
<main role="main" class="container">
<div class="row">
<div class="col-md-8">
<!-- {% for message in massages %}
<div class="alert alert-{{ message.tags }}">
<h6>{{ message }}</h6>
</div>
{% endfor %} -->
<div class="d-flex">

<div class="col">
<a href="{% url 'blog:post_create' %}" class="btn btn-outline-secondary">Create New Post</a>
<a
href="{% url 'blog:post_create' %}"
hx-get="{% url 'blog:post_create' %}"
hx-push-url="true"
hx-target="#main-content"
class="btn btn-outline-secondary">Create New Post</a>
</div>
<div class="col">
<form action="{% url 'blog:user_posts' %}">
<form
action="{% url 'blog:user_posts' %}"
hx-get="{% url 'blog:user_posts' %}"
hx-push-url="true"
hx-target="#main-content">
<div class="d-flex">
<input class="form-control" type="text" name="search_query_for_user_posts" placeholder="Search"
aria-label="Search">
Expand All @@ -34,7 +38,12 @@ <h6>{{ message }}</h6>
<h3 class="mb-0">{{ post.title }}</h3>
<div class="mb-1 text-muted">{{ post.publisher_at }}</div>
<p class="card-text mb-auto">{{ post.description|truncatewords_html:30 }}</p>
<a href="{{ post.get_absolute_url }}" class="stretched-link">Continue reading</a>
<a
href="{{ post.get_absolute_url }}"
hx-get="{{ post.get_absolute_url }}"
hx-push-url="true"
hx-target="#main-content"
class="stretched-link">Continue reading</a>
</div>
</div>
</div>
Expand Down
4 changes: 4 additions & 0 deletions templates/components/headers.html
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@
hx-triget="#main-content"
>
</form>
<div class="d-flex md-2 ms-2">

<i class="bi bi-search"></i>
</div>

</div>
</div>
Expand Down
17 changes: 17 additions & 0 deletions templates/components/messages.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% if messages %}
<div id="messages">
{% for message in messages %}
{% if message.tags == 'error' %}
<div class="alert alert-danger alert-dismissible fade show" role="alert">
{{ message }}
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
{% else %}
<div class="alert alert-{{ message.tags }} alert-dismissible fade show" role="alert">
{{ message }}
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
{% endif %}
{% endfor %}
</div>
{% endif %}
Loading