diff --git a/python/geoimage/urls.py b/python/geoimage/urls.py
index 3238bb04d..b23ecaa79 100644
--- a/python/geoimage/urls.py
+++ b/python/geoimage/urls.py
@@ -1,5 +1,5 @@
from django.conf.urls import url
-from .views import geoimagesOnMap,geoimageByIdentId,geoimagesByCoordinate
+from .views import geoimagesOnMap,geoimageById,geoimagesByCoordinate,geoimageDelete
urlpatterns = [
url(r'^geoimagesonmap$',
@@ -8,8 +8,11 @@
url(r'^geoimagesonmap/(?P
[-_\w]+)/$',
geoimagesOnMap,name="geoimages-on-map-by-ident"),
- url(r'^geoimagebyidentid/(?P[-_\w]+)/(?P[-_\w]+)/$',
- geoimageByIdentId,name="geoimage-by-ident-id"),
+ url(r'^geoimagebyid/(?P[-_\w]+)/$',
+ geoimageById,name="geoimage-by-id"),
+
+ url(r'^geoimagedelete/(?P[-_\w]+)/$',
+ geoimageDelete,name="geoimage-delete"),
url(r'^geoimagesbycoordinate/(?P[-_\w.]+)/(?P[-_\w.]+)/$',
geoimagesByCoordinate,name="geoimages-by-coordinate"),
diff --git a/python/geoimage/views.py b/python/geoimage/views.py
index a7a45f947..c475b65c5 100644
--- a/python/geoimage/views.py
+++ b/python/geoimage/views.py
@@ -7,6 +7,7 @@
from django.forms.widgets import SelectDateWidget
from django.utils.translation import ugettext_lazy
from django.core.paginator import Paginator
+from django.http import HttpResponse
class ExtremeForm(forms.Form):
@@ -43,9 +44,9 @@ def geoimagesOnMap(request,ident=None):
form = ExtremeForm() # An unbound form
if ident is None:
- grimages=GeorefencedImage.objects.filter(date__gte=datetime_start,date__lte=datetime_end).order_by("date")
+ grimages=GeorefencedImage.objects.filter(active=True,date__gte=datetime_start,date__lte=datetime_end).order_by("date")
else:
- grimages=GeorefencedImage.objects.filter(date__gte=datetime_start,date__lte=datetime_end,user__username=ident).order_by("date")
+ grimages=GeorefencedImage.objects.filter(active=True,date__gte=datetime_start,date__lte=datetime_end,user__username=ident).order_by("date")
return render(request, 'geoimage/geoimages_on_map.html',{'form': form,"grimages":grimages,"ident":ident})
@@ -55,13 +56,63 @@ def geoimagesByCoordinate(request,lon,lat):
# json come from an unordered dict!
# so this do not work #geom={'type': 'Point', 'coordinates': [float(lon),float(lat)]}
coordinate="[{},{}]".format(float(lon),float(lat))
- grimages=GeorefencedImage.objects.filter(geom__contains=coordinate).order_by("date")
+ grimages=GeorefencedImage.objects.filter(active=True,geom__contains=coordinate).order_by("date")
paginator = Paginator(grimages, 1) # Show 1 image per page.
page_number = request.GET.get('page',-1) # start with last page
page_obj = paginator.get_page(page_number)
return render(request, 'geoimage/geoimages_by_coordinate.html',{"page_obj":page_obj})
-def geoimageByIdentId(request,ident,id):
- grimage=GeorefencedImage.objects.get(user__username=ident,id=id)
- return render(request, 'geoimage/geoimage_by_ident_id.html',{"grimage":grimage})
+def geoimageById(request,id):
+ grimage=GeorefencedImage.objects.get(id=id)
+ return render(request, 'geoimage/geoimage_by_id.html',{"grimage":grimage})
+class DelGeoimageForm(forms.Form):
+ pass
+
+
+def geoimageDelete(request,id):
+
+ if request.method == 'POST': # If the form has been submitted...
+
+ delgeoimageform = DelGeoimageForm(request.POST) # A form bound to the POST data
+ if delgeoimageform.is_valid(): # All validation rules pass
+
+ try:
+ if request.user.is_authenticated:
+ grimage = GeorefencedImage.objects.get(user__username=request.user.get_username(),id=id)
+ grimage.delete()
+ else:
+ grimage = GeorefencedImage.objects.get(id=id)
+ return render(request, 'geoimage/geoimage_delete.html',{"grimage":grimage,'delgeoimageform':delgeoimageform,"notauthorized":True})
+
+ except Exception as e:
+ print(e)
+
+ grimage = GeorefencedImage.objects.get(id=id)
+ return render(request, 'geoimage/geoimage_delete.html',{"grimage":grimage,'delgeoimageform':delgeoimageform,"error":True})
+
+ return render(request, 'geoimage/geoimage_delete.html',{'delgeoimageform':delgeoimageform,"deleted":True})
+ else:
+ delgeoimageform = DelGeoimageForm()
+ grimage = GeorefencedImage.objects.get(id=id)
+ return render(request, 'geoimage/geoimage_delete.html',{"grimage":grimage,'delgeoimageform':delgeoimageform,"invalid":True})
+
+ else:
+ delgeoimageform = DelGeoimageForm() # An unbound form
+ try:
+
+ if request.user.is_authenticated:
+ notauthorized=False
+ else:
+ notauthorized=True
+
+ grimage = GeorefencedImage.objects.get(id=id)
+ return render(request, 'geoimage/geoimage_delete.html',{"grimage":grimage,'delgeoimageform':delgeoimageform,"notauthorized":notauthorized})
+
+
+ except Exception as e:
+ print(e)
+
+ response=HttpResponse("GeorefencedImage matching query does not exist")
+ response.status_code=403
+ return response
diff --git a/python/insertdata/templates/insertdata/form.html b/python/insertdata/templates/insertdata/form.html
index f6a76c66f..32f71ced1 100644
--- a/python/insertdata/templates/insertdata/form.html
+++ b/python/insertdata/templates/insertdata/form.html
@@ -21,7 +21,7 @@
{% trans 'OK, data published' %}