added hitcount for staff

This commit is contained in:
Esther Kleinhenz
2018-10-30 18:43:30 +01:00
parent 38a25437b6
commit d773cba908
30 changed files with 1445 additions and 12 deletions
+9 -1
View File
@@ -1,5 +1,7 @@
{% extends 'base.html' %} {% block content %}
{% extends 'base.html' %}{% block content %}
{% load hitcount_tags %}
<div class="post">
{% if post.published_date %}
<div class="date">
{{ post.published_date }}
@@ -17,6 +19,7 @@
<h1>{{ post.title }}</h1>
<p>{{ post.text|linebreaksbr }}</p>
<p>
Tags:
{% for tag in post.tags.all %}
<a href="{% url 'blog_search_list_view' %}">{{ tag.name }}, </a>
{% endfor %}
@@ -24,5 +27,10 @@
<p>
Autor: {{ post.author }}
</p>
{% if user.is_staff %}
<p>
{% get_hit_count for post %} Benutzer haben diesen Post bereits gelesen!
</p>
{% endif %}
</div>
{% endblock %}
+8 -11
View File
@@ -16,6 +16,8 @@ from django.contrib import messages
from post_office.models import EmailTemplate
from post_office import mail
from hitcount.models import HitCount
from hitcount.views import HitCountMixin
import logging
@@ -61,7 +63,9 @@ def post_list(request, slug=None):
@login_required
def post_detail(request, pk):
post = get_object_or_404(Post, pk=pk)
return render(request, 'post_detail.html', {'post': post})
hit_count = HitCount.objects.get_for_object(post)
hit_count_response = HitCountMixin.hit_count(request, hit_count)
return render(request, 'post_detail.html', locals())
@login_required
@@ -182,17 +186,10 @@ def blog_search_list_view(request):
def tag_cloud(request):
return render(request, 'tag_cloud.html', {})
EmailTemplate.objects.create(
name='weekly-update',
subject='Hi' + User.objects.get(username=request.user) + '!',
content='How are you feeling today?' + Post.objects.filter(published_date__lte=timezone.now()).order_by('published_date'),
html_content='Hi <strong>{{ name }}</strong>, how are you feeling today?',
)
mail.send(
'kleinhenz.e@gmail.com', # List of email addresses also accepted
'esther.kleinhenz@web.de',
template='weekly-update',
context={'name': 'alice'},
subject='My email',
message='Hi there!',
html_message='Hi <strong>there</strong>!',
)