Deletion of tags

This commit is contained in:
reverend 2020-09-02 00:08:00 +02:00
parent 2509c669f9
commit 6d89bca033
7 changed files with 45 additions and 11 deletions

View File

@ -51,4 +51,8 @@ class PlaceImageCreateForm(forms.ModelForm):
class TagSubmitForm(forms.Form): class TagSubmitForm(forms.Form):
tag_list = forms.CharField(max_length=500, required=False) tag_list = forms.CharField(
max_length=500,
required=False,
widget=forms.TextInput(attrs={'autocomplete':'off'})
)

View File

@ -1472,7 +1472,8 @@ body {
line-height: inherit; line-height: inherit;
position: relative; position: relative;
white-space: pre-wrap; white-space: pre-wrap;
margin-left: 15px; } margin-left: 15px;
height: 1em; }
.tagify__tag__removeBtn { .tagify__tag__removeBtn {
order: 5; order: 5;

View File

@ -3,14 +3,25 @@
{% for tag in tag_list %} {% for tag in tag_list %}
<li class="LP-TagList__Item"> <li class="LP-TagList__Item">
<div class="LP-Tag"> <div class="LP-Tag">
<p class="LP-Paragraph">{{tag}}</p> <a href="#" class="LP-Link">
</a>
<span class="LP-Link__Text">{{tag}}</span>
<a href="{% url config.delete_url_name tagged_id=config.tagged_item.id tag_id=tag.id %}" class="LP-Link">
<span class="LP-Tag__Remove RV-Iconized__Container RV-Iconized__Container--extraSmall">
<svg class="RV-Iconized__Icon" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M0 0h24v24H0z" fill="none"></path>
<path d="M19 6.4L17.6 5 12 10.6 6.4 5 5 6.4 10.6 12 5 17.6 6.4 19 12 13.4 17.6 19 19 17.6 13.4 12z">
</path>
</svg>
</span>
</a>
</div> </div>
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>
</div> </div>
<form id="id_tag_submit_form" class="LP-Form LP-Form--inline LP-Form--tagging" method="POST" action="{{url}}"> <form id="id_tag_submit_form" class="LP-Form LP-Form--inline LP-Form--tagging" method="POST" action="{{config.submit_url}}">
<fieldset class="LP-Form__Fieldset"> <fieldset class="LP-Form__Fieldset">
<legend class="LP-Form__Legend">Tags hinzufügen</legend> <legend class="LP-Form__Legend">Tags hinzufügen</legend>
{% csrf_token %} {% csrf_token %}
@ -19,14 +30,14 @@
<button id="id_tag_submit_button" class="LP-Button"> Tags hinzufügen</button> <button id="id_tag_submit_button" class="LP-Button"> Tags hinzufügen</button>
</div> </div>
<div class="LP-Form__Field"> <div class="LP-Form__Field">
{% include 'partials/form/inputField.html' with field=input_field classes="LP-Input--tagging" %} {% include 'partials/form/inputField.html' with field=config.submit_form.tag_list classes="LP-Input--tagging" %}
</div> </div>
</div> </div>
</fieldset> </fieldset>
</form> </form>
<script> <script>
const input = document.getElementById('{{input_field.auto_id}}') const input = document.getElementById('{{config.submit_form.tag_list.auto_id}}')
const submit_form = document.getElementById('id_tag_submit_form') const submit_form = document.getElementById('id_tag_submit_form')
const submit_button = document.getElementById('id_tag_submit_button') const submit_button = document.getElementById('id_tag_submit_button')

View File

@ -40,7 +40,7 @@
<section class="LP-Section"> <section class="LP-Section">
{% url 'place_tag_submit' place_id=place.id as tag_submit_url%} {% url 'place_tag_submit' place_id=place.id as tag_submit_url%}
{% include 'partials/tagging.html' with tag_list=place.tags.all url=tag_submit_url input_field=tagging_form.tag_list%} {% include 'partials/tagging.html' with tag_list=place.tags.all config=tagging_config all_tags=all_tags %}
</section> </section>

View File

@ -9,7 +9,8 @@ from .views import (
PlaceDeleteView, PlaceDeleteView,
PhotoAlbumCreateView, PhotoAlbumCreateView,
PhotoAlbumDeleteView, PhotoAlbumDeleteView,
PlaceTagSubmitView PlaceTagSubmitView,
PlaceTagDeleteView
) )
urlpatterns = [ urlpatterns = [
@ -23,4 +24,5 @@ urlpatterns = [
path('place/delete/<int:pk>/', PlaceDeleteView.as_view(), name='place_delete'), path('place/delete/<int:pk>/', PlaceDeleteView.as_view(), name='place_delete'),
path('place/', PlaceListView.as_view(), name='place_list'), path('place/', PlaceListView.as_view(), name='place_list'),
path('place/tag/<int:place_id>', PlaceTagSubmitView.as_view(), name='place_tag_submit'), path('place/tag/<int:place_id>', PlaceTagSubmitView.as_view(), name='place_tag_submit'),
path('place/tag/delete/<int:tagged_id>/<int:tag_id>', PlaceTagDeleteView.as_view(), name='place_tag_delete')
] ]

View File

@ -33,8 +33,13 @@ class PlaceDetailView(IsAuthenticated, View):
'place': place, 'place': place,
'place_list': [ place ], 'place_list': [ place ],
'place_map_center': [ place.latitude, place.longitude ], 'place_map_center': [ place.latitude, place.longitude ],
'tagging_form': TagSubmitForm(), 'all_tags': Tag.objects.all(),
'all_tags': Tag.objects.all() 'tagging_config': {
'submit_url': reverse_lazy('place_tag_submit', kwargs={'place_id': place.id}),
'submit_form': TagSubmitForm(),
'tagged_item': place,
'delete_url_name': 'place_tag_delete'
}
} }
return render(request, 'place/place_detail.html', context) return render(request, 'place/place_detail.html', context)

View File

@ -5,6 +5,7 @@ from django.contrib.messages.views import SuccessMessageMixin
from django.contrib import messages from django.contrib import messages
from django.urls import reverse_lazy from django.urls import reverse_lazy
from django.shortcuts import render, redirect from django.shortcuts import render, redirect
from django.http import HttpResponseForbidden
from lostplaces_app.forms import ExplorerCreationForm, TagSubmitForm from lostplaces_app.forms import ExplorerCreationForm, TagSubmitForm
from lostplaces_app.models import Place, PhotoAlbum from lostplaces_app.models import Place, PhotoAlbum
@ -12,8 +13,11 @@ from lostplaces_app.views.base_views import IsAuthenticated
from lostplaces_app.views.base_views import ( from lostplaces_app.views.base_views import (
PlaceAssetCreateView, PlaceAssetCreateView,
PlaceAssetDeleteView PlaceAssetDeleteView,
) )
from taggit.models import Tag
class SignUpView(SuccessMessageMixin, CreateView): class SignUpView(SuccessMessageMixin, CreateView):
form_class = ExplorerCreationForm form_class = ExplorerCreationForm
success_url = reverse_lazy('login') success_url = reverse_lazy('login')
@ -56,3 +60,10 @@ class PlaceTagSubmitView(IsAuthenticated, View):
place.save() place.save()
return redirect(reverse_lazy('place_detail', kwargs={'pk': place.id})) return redirect(reverse_lazy('place_detail', kwargs={'pk': place.id}))
class PlaceTagDeleteView(IsAuthenticated, View):
def get(self, request, tagged_id, tag_id, *args, **kwargs):
place = Place.objects.get(pk=tagged_id)
tag = Tag.objects.get(pk=tag_id)
place.tags.remove(tag)
return redirect(reverse_lazy('place_detail', kwargs={'pk': tagged_id}))