deleted studentpage and added code to bloglist view
This commit is contained in:
@@ -2,9 +2,21 @@
|
||||
{% load taggit_templatetags2_tags %}
|
||||
{% get_tagcloud as tags for 'application' %}
|
||||
{% include_tagcloud 'application.Post' %}
|
||||
|
||||
<div>
|
||||
<form class="post-form" method="post">
|
||||
{% csrf_token %} {{form.as_p}}
|
||||
<button type="submit" class="save btn btn-outline-dark">Save</button>
|
||||
</form>
|
||||
{% if messages %}
|
||||
{% for message in messages %}
|
||||
<div {% if message.tags %} class="{{ message.tags }}" {% endif %}>{{ message }}</div>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
<form type="get" action="." style="margin: 0">
|
||||
<input id="search_box" type="text" name="search_box" placeholder="Search...">
|
||||
<button id="search_submit" type="submit">Suchen</button>
|
||||
<input id="search_box" type="text" name="search_box" placeholder="Search..."></br>
|
||||
<button id="search_submit" type="submit" class="btn btn-outline-dark">Suchen</button>
|
||||
</form>
|
||||
<div>
|
||||
{% for post in posts %}
|
||||
|
||||
+4
-2
@@ -11,7 +11,6 @@ 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'^student/', views.student_page, name='student_page'),
|
||||
url(r'^search/', views.blog_search_list_view, name='blog_search_list_view'),
|
||||
url(r'^search/result/$', views.blog_search_list_view, name='post_list_by_search'),
|
||||
url(r'^post/(?P<pk>\d+)/$', views.post_detail, name='post_detail'),
|
||||
@@ -20,10 +19,13 @@ 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/(?P<slug>[-\w]+)/remove/$', views.tag_remove, name='tag_remove'),
|
||||
url(r'^tags/', include('taggit_templatetags2.urls')),
|
||||
]
|
||||
|
||||
"""
|
||||
url(r'^student/(?P<slug>[-\w]+)/remove/$', views.tag_remove, name='tag_remove'),
|
||||
"""
|
||||
|
||||
if settings.DEBUG:
|
||||
import debug_toolbar
|
||||
urlpatterns += [
|
||||
|
||||
+26
-36
@@ -126,47 +126,16 @@ def post_remove(request, pk):
|
||||
return redirect('post_list')
|
||||
|
||||
|
||||
@login_required
|
||||
""" @login_required
|
||||
def tag_remove(request, slug=None):
|
||||
log = logging.getLogger('mysite')
|
||||
user_instance = get_object_or_404(CustomUser, user=request.user)
|
||||
log.info(u)
|
||||
tag = Tag.get_object_or_404(Tag, slug = slug)
|
||||
log.info(tag)
|
||||
if slug:
|
||||
user_instance.tags.remove(tag)
|
||||
save_m2m()
|
||||
return redirect('student_page')
|
||||
|
||||
|
||||
@login_required
|
||||
def student_page(request):
|
||||
log = logging.getLogger('mysite')
|
||||
user_instance = get_object_or_404(CustomUser, user=request.user)
|
||||
if request.method == "POST":
|
||||
log.info('post method')
|
||||
form = NewTagForm(request.POST, instance=user_instance)
|
||||
if form.is_valid():
|
||||
log.info('form is valid')
|
||||
obj = form.save(commit=False)
|
||||
obj.user = request.user
|
||||
obj.save()
|
||||
tag_names = [tag.name for tag in Tag.objects.all()]
|
||||
log.info(tag_names)
|
||||
m_tags = form.cleaned_data['tags']
|
||||
m_tags = ' '.join(str(m_tags) for m_tags in m_tags)
|
||||
log.info(m_tags)
|
||||
if m_tags in tag_names:
|
||||
log.info('worked out')
|
||||
obj.tags.add(m_tags)
|
||||
form.save_m2m()
|
||||
messages.info(request, 'Der Tag "' + m_tags + '" wurde gespeichert')
|
||||
return redirect('/student/')
|
||||
else:
|
||||
messages.info(request, 'Sorry !! Den Tag den du suchst gibt es leider nicht!')
|
||||
else:
|
||||
form = NewTagForm()
|
||||
return render(request, 'student_page.html', {'form':form})
|
||||
return redirect('student_page') """
|
||||
|
||||
@login_required
|
||||
def tag_list(request):
|
||||
@@ -187,11 +156,32 @@ def blog_search_list_view(request):
|
||||
search_query = request.GET.get('search_box', None)
|
||||
log.info(search_query)
|
||||
posts = posts.filter(tags__name__in=[search_query])
|
||||
log = logging.getLogger('mysite')
|
||||
user_instance = get_object_or_404(CustomUser, user=request.user)
|
||||
if request.method == "POST":
|
||||
log.info('post method')
|
||||
form = NewTagForm(request.POST, instance=user_instance)
|
||||
if form.is_valid():
|
||||
log.info('form is valid')
|
||||
obj = form.save(commit=False)
|
||||
obj.user = request.user
|
||||
tag_names = [tag.name for tag in Tag.objects.all()]
|
||||
log.info(tag_names)
|
||||
m_tags = form.cleaned_data['tags']
|
||||
m_tags = ' '.join(str(m_tags) for m_tags in m_tags)
|
||||
log.info(m_tags)
|
||||
if m_tags in tag_names:
|
||||
log.info('worked out')
|
||||
obj.tags.add(m_tags)
|
||||
obj.save()
|
||||
messages.info(request, 'Der Tag "' + m_tags + '" wurde gespeichert')
|
||||
return redirect('/search/')
|
||||
else:
|
||||
messages.info(request, 'Sorry !! Den Tag den du suchst gibt es leider nicht!')
|
||||
else:
|
||||
form = NewTagForm()
|
||||
return render(request, 'blog_search_list_view.html', locals())
|
||||
|
||||
def tag_cloud(request):
|
||||
return render(request, 'tag_cloud.html', {})
|
||||
|
||||
mail.send(
|
||||
'kleinhenz.e@gmail.com', # List of email addresses also accepted
|
||||
'esther.kleinhenz@web.de',
|
||||
|
||||
Reference in New Issue
Block a user