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

Tags #29

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open

Tags #29

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
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions .idea/Django_blog.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 0 additions & 48 deletions blog/migrations/0001_initial.py

This file was deleted.

19 changes: 0 additions & 19 deletions blog/migrations/0002_comment_parent.py

This file was deleted.

17 changes: 0 additions & 17 deletions blog/migrations/0003_remove_comment_parent.py

This file was deleted.

22 changes: 0 additions & 22 deletions blog/migrations/0004_auto_20191015_0853.py

This file was deleted.

23 changes: 0 additions & 23 deletions blog/migrations/0005_auto_20211014_1338.py

This file was deleted.

File renamed without changes.
File renamed without changes.
0 blog/apps.py → src/blog/apps.py
100755 → 100644
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions blog/models.py → src/blog/models.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Post(models.Model):
content = models.TextField()
created_on = models.DateTimeField(auto_now_add=True)
status = models.IntegerField(choices=STATUS, default=0)
tag = models.CharField(unique=False, max_length=50)

class Meta:
ordering = ["-created_on"]
Expand Down
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions blog/urls.py → src/blog/urls.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
from django.urls import include, path

from . import views
from blog.views import PostTag, AllPosts
from .feeds import AtomSiteNewsFeed, LatestPostsFeed

urlpatterns = [
path("feed/rss", LatestPostsFeed(), name="post_feed"),
path("feed/atom", AtomSiteNewsFeed()),
path("", views.PostList.as_view(), name="home"),
path("posts/", views.AllPosts.as_view(), name="articles"),
# path('<slug:slug>/', views.PostDetail.as_view(), name='post_detail'),
path("<slug:slug>/", views.post_detail, name="post_detail"),
path("posts/<str:tag>/", PostTag.as_view(), name="post_tag")
]
21 changes: 19 additions & 2 deletions blog/views.py → src/blog/views.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.shortcuts import get_object_or_404, render
from django.shortcuts import get_object_or_404, render, redirect
from django.views import generic

from .forms import CommentForm
Expand All @@ -15,6 +15,18 @@ class PostList(generic.ListView):
# model = Post
# template_name = 'post_detail.html'

class PostTag(generic.ListView):
template_name = "index.html"
paginate_by = 3

def get_queryset(self):
posts = Post.objects.filter(tag=self.kwargs['tag'])
return posts
def get_context_data(self, *args, **kwargs):
context = super().get_context_data(*args, **kwargs)
context['tag'] = self.kwargs['tag']
return context


def post_detail(request, slug):
template_name = "post_detail.html"
Expand All @@ -25,7 +37,6 @@ def post_detail(request, slug):
if request.method == "POST":
comment_form = CommentForm(data=request.POST)
if comment_form.is_valid():

# Create Comment object but don't save to database yet
new_comment = comment_form.save(commit=False)
# Assign the current post to the comment
Expand All @@ -45,3 +56,9 @@ def post_detail(request, slug):
"comment_form": comment_form,
},
)


class AllPosts(generic.ListView):
template_name = "index.html"
queryset = Post.objects.filter(status=1).order_by("-created_on")
paginate_by = 3
0 manage.py → src/manage.py
100755 → 100644
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions mysite/settings.py → src/mysite/settings.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
TEMPLATES_DIR = os.path.join(BASE_DIR, "templates")




# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/

Expand Down
1 change: 0 additions & 1 deletion mysite/urls.py → src/mysite/urls.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from django.contrib.sitemaps.views import sitemap
from django.urls import include, path
import debug_toolbar

from blog.sitemaps import PostSitemap

sitemaps = {
Expand Down
File renamed without changes.
6 changes: 6 additions & 0 deletions static/css/base.css → src/static/css/base.css
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ body {
background-color: #fdfdfd;
}

.post-tag {
color: black;
text-decoration: none;
}


.shadow {
box-shadow: 0 4px 2px -2px rgba(0, 0, 0, 0.1);
}
Expand Down
File renamed without changes.
18 changes: 13 additions & 5 deletions templates/index.html → src/templates/index.html
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,35 @@
<div class="row">
<div class=" col-md-8 col-md-10 mx-auto">
<div class="site-heading">

{% if "/posts/"|add:tag|add:"/" in request.path %}

<h3 class=" site-heading my-4 mt-3 text-white">Tag: {{tag}}</h3>

{% elif "/posts/" in request.path %}
<h3 class=" site-heading my-4 mt-3 text-white">all posts</h3>

{% else %}
<h3 class=" site-heading my-4 mt-3 text-white"> Welcome to my awesome Blog </h3>
<p class="text-light">We Love Django As much as you do &nbsp
</p>
<p class="text-light">We Love Django As much as you do &nbsp</p>

{% endif %}
</div>
</div>
</div>
</div>
</div>
</header>

<div class="container">
<div class="row">

<!-- Blog Entries Column -->
<div class="col-md-8 mt-3 left">
{% for post in post_list %}
<div class="card mb-4">
<div class="card-body">
<a href="{% url 'post_tag' post.tag %}" class="btn btn-light">{{ post.tag }}</a>
<h2 class="card-title">{{ post.title }}</h2>
<p class="card-text text-muted h6">{{ post.author }} | {{ post.created_on}} </p>

<p class="card-text">{{post.content|safe|slice:":200" }}</p>
<a href="{% url 'post_detail' post.slug %}" class="btn btn-primary">Read More &rarr;</a>
</div>
Expand Down
5 changes: 3 additions & 2 deletions templates/post_detail.html → src/templates/post_detail.html
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
<h1>{% block title %} {{ post.title }} {% endblock title %}</h1>
<p class=" text-muted">{{ post.author }} | {{ post.created_on }}</p>
<p class="card-text ">{{ post.content | safe }}</p>
<hr>
<h3>Tag</h3>
<a href="{% url 'post_tag' post.tag %}" class="btn btn-light">{{ post.tag }}</a>
</div>
</div>
{% block sidebar %} {% include 'sidebar.html' %} {% endblock sidebar %}
Expand All @@ -17,11 +20,9 @@ <h1>{% block title %} {{ post.title }} {% endblock title %}</h1>
<!-- comments -->
{% with comments.count as total_comments %}
<h2>{{ total_comments }} comments</h2>

<p>
{% endwith %} {% for comment in comments %}
</p>

<div class="comments" style="padding: 10px;">
<p class="font-weight-bold">
{{ comment.name }}
Expand Down
File renamed without changes.