Adding tags is now possible
This commit is contained in:
		@@ -11,7 +11,7 @@ from django.urls import reverse_lazy
 | 
			
		||||
 | 
			
		||||
from lostplaces_app.models import Place, PlaceImage
 | 
			
		||||
from lostplaces_app.views import IsAuthenticated, IsPlaceSubmitter
 | 
			
		||||
from lostplaces_app.forms import PlaceForm, PlaceImageCreateForm
 | 
			
		||||
from lostplaces_app.forms import PlaceForm, PlaceImageCreateForm, TagSubmitForm
 | 
			
		||||
 | 
			
		||||
class PlaceListView(IsAuthenticated, ListView):
 | 
			
		||||
    paginate_by = 5
 | 
			
		||||
@@ -30,7 +30,8 @@ class PlaceDetailView(IsAuthenticated, View):
 | 
			
		||||
        context = {
 | 
			
		||||
            'place': place,
 | 
			
		||||
            'place_list': [ place ],
 | 
			
		||||
            'place_map_center': [ place.latitude, place.longitude ]
 | 
			
		||||
            'place_map_center': [ place.latitude, place.longitude ],
 | 
			
		||||
			'tagging_form': TagSubmitForm()
 | 
			
		||||
        }
 | 
			
		||||
        return render(request, 'place/place_detail.html', context)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -6,8 +6,9 @@ from django.contrib import messages
 | 
			
		||||
from django.urls import reverse_lazy
 | 
			
		||||
from django.shortcuts import render, redirect
 | 
			
		||||
 | 
			
		||||
from lostplaces_app.forms import ExplorerCreationForm
 | 
			
		||||
from lostplaces_app.forms import ExplorerCreationForm, TagSubmitForm
 | 
			
		||||
from lostplaces_app.models import Place, PhotoAlbum
 | 
			
		||||
from lostplaces_app.views.base_views import IsAuthenticated
 | 
			
		||||
 | 
			
		||||
from lostplaces_app.views.base_views import (
 | 
			
		||||
    PlaceAssetCreateView, 
 | 
			
		||||
@@ -39,4 +40,19 @@ class PhotoAlbumDeleteView(PlaceAssetDeleteView):
 | 
			
		||||
    model = PhotoAlbum
 | 
			
		||||
    pk_url_kwarg = 'pk'
 | 
			
		||||
    success_message = 'Photo Album deleted'
 | 
			
		||||
    permission_denied_messsage = 'You do not have permissions to alter this photo album'
 | 
			
		||||
    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)
 | 
			
		||||
		form = TagSubmitForm(request.POST)
 | 
			
		||||
		if form.is_valid():
 | 
			
		||||
			tag_list_raw = form.cleaned_data['tag_list']
 | 
			
		||||
			tag_list_raw = tag_list_raw.strip().split(',')
 | 
			
		||||
			tag_list = []
 | 
			
		||||
			for tag in tag_list_raw:
 | 
			
		||||
				tag_list.append(tag.strip())
 | 
			
		||||
			place.tags.add(*tag_list)
 | 
			
		||||
			place.save()
 | 
			
		||||
 | 
			
		||||
		return redirect(reverse_lazy('place_detail', kwargs={'pk': place.id}))
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user