Browse Source

nouveau formulaire : ajout d'un point de réference sur la page main

julpec 8 years ago
parent
commit
6b40c58a35

+ 8 - 0
panorama/forms.py

@@ -28,3 +28,11 @@ class PanoramaForm(forms.ModelForm):
     class Meta:
         model = Panorama
         fields = ['name', 'image', 'loop', 'latitude', 'longitude', 'altitude']
+
+class ReferencePointForm(forms.ModelForm):
+    """Form to insert a new reference point"""
+    prefix = 'newrefpoint'
+
+    class Meta:
+        model = ReferencePoint
+        fields = ['name', 'latitude', 'longitude', 'altitude']

+ 2 - 2
panorama/templates/panorama/main.html

@@ -127,11 +127,11 @@
     
             // Autofill forms while moving crosshair and expanding menus
             map.on('moveend', function(e) {
-                if ($("#locate-gps,#new-pano").hasClass("collapse in")){
+                if ($("#locate-gps,#new-pano,#new-refpoint").hasClass("collapse in")){
                     fillCoord();
                 }
             });
-            $('#locate-gps-btn, #new-pano-btn').click(function(e) {
+            $('#locate-gps-btn, #new-pano-btn, #new-refpoint-btn').click(function(e) {
                 fillCoord();
             });
     

+ 9 - 0
panorama/templates/panorama/new-refpoint.html

@@ -0,0 +1,9 @@
+{% extends "panorama/base.html" %}
+{% load panorama_url %}
+
+{% block content %}
+<form action="" enctype="multipart/form-data" method="post">{% csrf_token %}
+  {{ form.as_p }}
+  <input type="submit" value="Submit" />
+</form>
+{% endblock content %}

+ 14 - 0
panorama/templates/panorama/sidebar-all.html

@@ -19,6 +19,20 @@
             </ul>
         </li>
         <li>
+            <a id="new-refpoint-btn" href="javascript:;" data-toggle="collapse" data-target="#new-refpoint"><i class="fa fa-fw fa-plus-square"></i> {% trans "Add new reference point" %}<i class="fa fa-fw fa-caret-down"></i></a>
+            <ul id="new-refpoint" class="collapse">
+                <li>
+                    <form action="{% url 'panorama:new_refpoint' %}" enctype="multipart/form-data" method="post">{% csrf_token %}
+                        {{ newrefpoint_form.name.label_tag }}{{ newrefpoint_form.name }}
+                        {{ newrefpoint_form.latitude.label_tag }}{{ newrefpoint_form.latitude }}
+                        {{ newrefpoint_form.longitude.label_tag }}{{ newrefpoint_form.longitude }}
+                        {{ newrefpoint_form.altitude.label_tag }}{{ newrefpoint_form.altitude }}
+                        <input type="submit" class="btn btn-primary btn-sm" value={% trans "Add" %} />
+                    </form>
+                </li>
+            </ul>
+        </li>
+        <li>
             <a id="new-pano-btn" href="javascript:;" data-toggle="collapse" data-target="#new-pano"><i class="fa fa-fw fa-plus-square"></i> {% trans "Add new panorama" %}<i class="fa fa-fw fa-caret-down"></i></a>
             <ul id="new-pano" class="collapse">
                 <li>

+ 2 - 1
panorama/urls.py

@@ -3,7 +3,7 @@ from __future__ import unicode_literals
 
 from django.conf.urls import include, url
 
-from .views import MainView, PanoramaUpload, PanoramaView, PanoramaGenTiles, LocateReferencePointView, LocateCustomPointView
+from .views import MainView, PanoramaUpload, PanoramaView, PanoramaGenTiles, LocateReferencePointView, LocateCustomPointView, CreateReferencePoint
 
 
 urlpatterns = [
@@ -11,6 +11,7 @@ urlpatterns = [
     url(r'^locate_refpoint/$', LocateReferencePointView.as_view(), name="locate_refpoint"),
     url(r'^locate_custompoint/$', LocateCustomPointView.as_view(), name="locate_custompoint"),
     url(r'^pano/new/$', PanoramaUpload.as_view(), name="new"),
+    url(r'^refpoint/new/$', CreateReferencePoint.as_view(), name="new_refpoint"),
     url(r'^pano/view/(?P<pk>\d+)/$', PanoramaView.as_view(), name="view_pano"),
     url(r'^pano/gen_tiles/(?P<pk>\d+)/$', PanoramaGenTiles.as_view(), name="gen_tiles"),
 ]

+ 11 - 1
panorama/views.py

@@ -9,7 +9,7 @@ from django.views.generic import CreateView, DetailView, RedirectView, ListView,
 from django.contrib.auth.mixins import LoginRequiredMixin
 
 from .models import Point, Panorama, ReferencePoint
-from .forms import SelectReferencePointForm, CustomPointForm, PanoramaForm
+from .forms import SelectReferencePointForm, CustomPointForm, PanoramaForm, ReferencePointForm
 
 
 class CelutzLoginMixin(LoginRequiredMixin):
@@ -68,6 +68,7 @@ class MainView(CelutzLoginMixin, TemplateView):
         context['refpoints_form'] = SelectReferencePointForm
         context['custom_point_form'] = CustomPointForm
         context['newpanorama_form'] = PanoramaForm
+        context['newrefpoint_form'] = ReferencePointForm
         context['panoramas'] = Panorama.objects.all()
         context['poi_list'] = [poi for poi in ReferencePoint.objects.all() if not hasattr(poi, 'panorama')]
         return context
@@ -87,6 +88,15 @@ class MainView(CelutzLoginMixin, TemplateView):
         return sorted(l, key=lambda x: x[1])
 
 
+class CreateReferencePoint(CelutzLoginMixin, CreateView):
+    model = ReferencePoint
+    fields = ('name', 'latitude', 'longitude', 'altitude')
+    template_name = 'panorama/new-refpoint.html'
+
+    def get_success_url(self):
+        return reverse_lazy("panorama:main")
+
+
 class LocateReferencePointView(MainView):
     """Displays a located reference point"""
     template_name = 'panorama/locate_point.html'