Refactoring tagging

This commit is contained in:
reverend 2020-09-12 11:24:16 +02:00
parent 317437fedc
commit 7f73035b02
5 changed files with 11 additions and 15 deletions

View File

@ -1,6 +1,6 @@
<div class="LP-TagList">
<ul class="LP-TagList__List">
{% for tag in tag_list %}
{% for tag in config.tagged_item.tags.all %}
<li class="LP-TagList__Item">
<div class="LP-Tag">
<a href="#" class="LP-Link">
@ -23,7 +23,7 @@
</ul>
</div>
<form id="id_tag_submit_form" class="LP-Form LP-Form--inline LP-Form--tagging" method="POST" action="{{config.submit_url}}">
<form id="id_tag_submit_form" class="LP-Form LP-Form--inline LP-Form--tagging" method="POST" action="{% url config.submit_url_name tagged_id=config.tagged_item.id%}">
<fieldset class="LP-Form__Fieldset">
<legend class="LP-Form__Legend">Tags hinzufügen</legend>
{% csrf_token %}
@ -46,14 +46,10 @@
submit_form.onsubmit = () => false
const tagify = new Tagify(input, {
'whitelist': [{
%
for tag in all_tags %
}
'whitelist': [
{% for tag in config.tagged_item.tags.all %}
'{{tag}}',
{
% endfor %
}
{% endfor %}
]
})

View File

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

View File

@ -25,6 +25,6 @@ urlpatterns = [
path('flat/<slug:slug>/', FlatView, name='flatpage'),
# POST-only URLs for tag submission
path('place/tag/<int:place_id>', PlaceTagSubmitView.as_view(), name='place_tag_submit'),
path('place/tag/<int:tagged_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,11 +33,11 @@ class PlaceDetailView(IsAuthenticated, View):
'place': place,
'place_list': [ place ],
'place_map_center': [ place.latitude, place.longitude ],
'all_tags': Tag.objects.all(),
'tagging_config': {
'submit_url': reverse_lazy('place_tag_submit', kwargs={'place_id': place.id}),
'all_tags': Tag.objects.all(),
'submit_form': TagSubmitForm(),
'tagged_item': place,
'submit_url_name': 'place_tag_submit',
'delete_url_name': 'place_tag_delete'
}
}

View File

@ -54,8 +54,8 @@ class PhotoAlbumDeleteView(PlaceAssetDeleteView):
permission_denied_messsage = 'You do not have permissions to alter this photo album'
class PlaceTagSubmitView(IsAuthenticated, View):
def post(self, request, place_id, *args, **kwargs):
place = Place.objects.get(pk=place_id)
def post(self, request, tagged_id, *args, **kwargs):
place = Place.objects.get(pk=tagged_id)
form = TagSubmitForm(request.POST)
if form.is_valid():
tag_list_raw = form.cleaned_data['tag_list']