@@ -1,4 +1,6 @@ | |||
{% extends 'base.html' %} {% block content %} {% for post in posts %} {% load taggit_templatetags2_tags %} | |||
{% extends 'base.html' %} {% block content %} | |||
{% if tag %} Posts tagged with "{{ tag.name }}" {% endif %} | |||
{% for post in posts %} {% load taggit_templatetags2_tags %} | |||
<div class="post"> | |||
<div class="date"> | |||
{{ post.published_date }} | |||
@@ -7,15 +9,11 @@ | |||
<a href="{% url 'post_detail' pk=post.pk %}">{{ post.title }}</a> | |||
</h1> | |||
<p>{{ post.text|linebreaks }}</p> | |||
<p> | |||
{% for tag in post.tags.all %} | |||
<a href="">{{ tag.name }}, </a> | |||
{% endfor %} | |||
</p> | |||
<p> | |||
Tags: {% for tag in post.tags.all %} | |||
<a href="{% url 'post_list_by_tag' tag.slug %}">{{ tag.name }}</a> | |||
{% if not forloop.last %}, {% endif %} {% endfor %} <p> | |||
{{ post.author }} | |||
</p> | |||
</div> | |||
{% endfor %} | |||
</div> |
@@ -1,5 +1,18 @@ | |||
{% extends "base.html" %} {% block content %} | |||
{% extends "base.html" %} {% block content %} {% load taggit_templatetags2_tags %} {% get_taglist as tags for 'application.post'%} | |||
<div id=""> | |||
<ul> | |||
{% for tag in tags %} | |||
<li>{{tag}} | |||
<a class="btn btn-outline-dark" href="{% url 'tag_remove' %}"> | |||
<span class="glyphicon glyphicon-remove">Remove</span> | |||
</a> | |||
</li> | |||
{{ result }} {% endfor %} | |||
</ul> | |||
</div> | |||
<div> | |||
</div> | |||
<form id="searchform" action="{% url 'blog_search_list_view' %}" method="get" accept-charset="utf-8"> | |||
<button class="searchbutton" type="submit"> | |||
<i class="fa fa-search"></i> | |||
@@ -12,8 +25,7 @@ | |||
</div> | |||
<form class="post-form" method="post"> | |||
{% csrf_token %} | |||
{{form.as_p}} | |||
{% csrf_token %} {{form.as_p}} | |||
<button type="submit" class="save btn btn-outline-dark">Save</button> | |||
</form> | |||
{% endblock %} |
@@ -5,6 +5,7 @@ from . import views | |||
urlpatterns = [ | |||
url(r'^$', views.post_list, name='post_list'), | |||
url(r'^tag/(?P<slug>[-\w]+)/$', views.post_list, name='post_list_by_tag'), | |||
url(r'^student/', views.student_page, name='student_page'), | |||
url(r'^search/', views.blog_search_list_view, name='blog_search_list_view'), | |||
url(r'^post/(?P<pk>\d+)/$', views.post_detail, name='post_detail'), | |||
@@ -13,6 +14,7 @@ urlpatterns = [ | |||
url(r'^drafts/$', views.post_draft_list, name='post_draft_list'), | |||
url(r'^post/(?P<pk>\d+)/publish/$', views.post_publish, name='post_publish'), | |||
url(r'^post/(?P<pk>\d+)/remove/$', views.post_remove, name='post_remove'), | |||
url(r'^student/remove/$', views.tag_remove, name='tag_remove'), | |||
url(r'^tags/', include('taggit_templatetags2.urls')), | |||
] | |||
@@ -1,12 +1,15 @@ | |||
from django.shortcuts import render, get_object_or_404 | |||
from django.utils import timezone | |||
from .models import Post, CustomUser | |||
from taggit.models import Tag | |||
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger | |||
from .forms import PostForm, NewTagForm | |||
from django.shortcuts import redirect | |||
from django.contrib.auth.decorators import login_required | |||
from django.contrib.admin.views.decorators import staff_member_required | |||
from django.contrib.auth import authenticate, login, logout | |||
from django.db.models import Q | |||
import sys | |||
from taggit_templatetags2.views import TagCanvasListView | |||
import logging | |||
@@ -42,10 +45,13 @@ def navlogin(request): | |||
@login_required | |||
def post_list(request): | |||
posts = Post.objects.filter( | |||
published_date__lte=timezone.now()).order_by('published_date') | |||
return render(request, 'post_list.html', {'posts': posts}) | |||
def post_list(request, slug=None): | |||
posts = Post.objects.filter(published_date__lte=timezone.now()).order_by('published_date') | |||
if slug: | |||
tag = get_object_or_404(Tag, slug=slug) | |||
posts= posts.filter(tags__in=[tag]) | |||
page = request.GET.get('page') | |||
return render(request, 'post_list.html', locals()) | |||
@login_required | |||
@@ -110,6 +116,15 @@ def post_remove(request, pk): | |||
return redirect('post_list') | |||
@login_required | |||
def tag_remove(request): | |||
tag_to_delete = CustomUser.objects.get(tags) | |||
obj.user = request.user | |||
obj.save() | |||
obj.tags.tag_remove(tag_to_delete) | |||
obj.save_m2m() | |||
return redirect('student_page') | |||
@login_required | |||
def student_page(request): | |||
user_instance = CustomUser.objects.get(user=request.user) |