Browse Source

tried to build a tag list of the logged in user

newsletter
Esther Kleinhenz 5 years ago
parent
commit
e78011daca

+ 12
- 3
application/templates/base.html View File

@@ -31,10 +31,20 @@
<li class="nav-item">
<a class="nav-link" href="{% url 'admin:index' %}">Administration</a>
</li>
<li>
<a class="nav-link" href="{% url 'post_list' %}">Dashboard</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'student_page' %}">Studentenansicht</a>
</li>
{% elif user.is_staff %}
<li class="nav-item">
<a class="nav-link" href="{% url 'logout' %}">Administration</a>
</li>

<li class="nav-item">
<a class="nav-link" href="{% url 'post_list' %}">Dashboard</a>
</li>
{% else %}
<li class="nav-item">
<a class="nav-link" href="{% url 'student_page' %}">{{user.get_username}}'s Dashboard</a>
@@ -60,8 +70,7 @@
<li>
<form class="form" role="form" method="post" action="{% url 'login' %}" accept-charset="UTF-8" id="login-nav">
{% csrf_token %} {% if next %}
<input type="hidden" name="next" value="{{ next }}" />
{% endif %}
<input type="hidden" name="next" value="{{ next }}" /> {% endif %}
<div class="form-group">
<label class="sr-only" for="username">Benutzername</label>
<input type="text" class="form-control" id="username" name="username" placeholder="Benutzername" required>
@@ -92,7 +101,7 @@
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="{% static 'bootstrap/js/jquery-1.11.1.js' %} "></script>
<script src="{% static 'bootstrap/jsjquery.tagcanvas.min.js' %} " type="text/javascript"></script>
<script src="{% static 'js/app.js' %}"></script>
<script src="{% static 'js/app.js' %}"></script>
<script src="{% static 'bootstrap/js/bootstrap.bundle.js' %}"></script>
</body>


+ 1
- 1
application/templates/post_list.html View File

@@ -1,6 +1,6 @@
{% extends 'base.html' %} {% block content %}
{% if tag %} Posts tagged with "{{ tag.name }}" {% endif %}
{% for post in posts %} {% load taggit_templatetags2_tags %}
{% for post in posts %}
<div class="post">
<div class="date">
{{ post.published_date }}

+ 25
- 0
application/templates/tag_list.html View File

@@ -0,0 +1,25 @@
{% extends "base.html" %} {% block content %} {% load taggit_templatetags2_tags %}
{% get_taglist as tags for 'application.customuser'%}


<div id="">
Your tags:
<ul>
{% for tag in tags %}
<li>
<a href="{% url 'post_list_by_tag' tag.slug %}">{{ tag }}</a>
</li>
{% endfor %}
</ul>
</div>
<div>
{{ tags }} {{ u }}
</div>
<div>
from List: {% for tag in tags %}

{% for tag in posts %}
<p>{{ tag.name }} </p>{% endfor %}{% endfor %}

</div>
{% endblock %}

+ 2
- 0
application/urls.py View File

@@ -6,6 +6,8 @@ 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'^taglist/$', views.tag_list, name='tag_list'),
url(r'^taglist/(?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'),

+ 7
- 2
application/views.py View File

@@ -10,6 +10,7 @@ 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
import collections
from taggit_templatetags2.views import TagCanvasListView

import logging
@@ -127,7 +128,7 @@ def tag_remove(request):

@login_required
def student_page(request):
user_instance = CustomUser.objects.get(user=request.user)
user_instance = get_object_or_404(CustomUser, user=request.user)
if request.method == "POST":
form = NewTagForm(request.POST, instance=user_instance)
if form.is_valid():
@@ -144,7 +145,11 @@ def student_page(request):
return render(request, 'student_page.html', {'form':form})


@login_required
def tag_list(request):
u= CustomUser.objects.get(user=request.user)
tags= Tag.objects.filter(name=u)
return render(request, 'tag_list.html', locals())

class TagSearch(TagCanvasListView):

Loading…
Cancel
Save