django-bootstrap-modal-forms icon indicating copy to clipboard operation
django-bootstrap-modal-forms copied to clipboard

Modal forms empty URL

Open saadsaoulajan opened this issue 5 years ago • 0 comments
trafficstars

Hi,

I have been working with modalforms for a couple of months and just run into this bug that i don't seem to underdtand ! The global issue is:

  • When a ModalForms opens, i update or create an object (depending on the form)
  • Once I submit the form, it takes me to "/" (which is my login) instead of my success_url

Am i doing something wrong?

Here are my files (i put only one example) models.py

class Pass (models.Model):
	EURO = "€"
	POUND = "£"
	DOLLAR = "$"
	dv = [(EURO,'€'),(POUND,'£'),(DOLLAR,'$')]
	nom = models.CharField(max_length=200)
	prix = models.IntegerField(default=0,null=True,blank=True)
	devise = models.CharField(max_length=150, choices= dv, default=EURO)
	descriptif = models.TextField(null=True,blank=True)
	descriptifEn = models.TextField(null=True,blank=True)
	nbPaiement = models.IntegerField(default=1,null=True,blank=True)
	def __str__(self):
		return self.nom

forms.py

from siteweb.models import Pass
from bootstrap_modal_forms.forms import BSModalForm,BSModalModelForm
from django import forms
from django.db import models
import os

class NewPassForm(BSModalModelForm):
    class Meta:
        model = Pass
        fields = ['id', 'nom', 'prix','devise','descriptif','descriptifEn','nbPaiement']

urls.py

from django.urls import path, include
from django.conf.urls import url
from django.conf.urls.static import static
from django.conf import settings
from django.contrib.auth import views as auth_views
from . import views

urlpatterns = [
    path('', views.toLogin, name='toLogin'),
    path('dashboard/', include('django.contrib.auth.urls')),
    path('dashboard/logout/',views.logoutView,name="logout"),
    path('conventions/', views.convPage, name='convention'),
    path('createPass/', views.PassCreateView.as_view(), name='create_pass'),
    path('createPass/<int:idConv>', views.PassCreateView2.as_view(), name='create_pass2'),
    path('updatePass/<int:pk>', views.PassUpdateView.as_view(), name='update_pass'),
]+ static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

view.py

class PassUpdateView(BSModalUpdateView):
    model = Pass
    template_name = 'formulaires/updatePass.html'
    form_class = NewPassForm
    success_message = 'Success: The Pass was updated.'
    success_url = reverse_lazy('convention')

convention.html

<div class="row partnerDiv" id="passes">
    <button type="button" id="create-pass" class="addSerie">Ajouter un Pass</button>
    {% for p in conventionToRender.passes.all %}
    <div class="passElement">
	  <button type='button' class=" partner passRectangle" data-form-url="{% url 'update_pass' p.pk %}" data-id="p.pk">{{p.nom}}</button>
	        								
    </div>
    {% endfor %}
</div>

<script>
	$(function () {
		
      // Update, Read and Delete book buttons open modal with id="modal" (default)
      // The formURL is retrieved from the data of the element
      $(".partner").each(function () {
        $(this).modalForm({
            formURL: $(this).data('form-url')
        });
      });


  </script>

updatePass.html

{% load widget_tweaks %}
{% load static %}
<form method="post" action="">
  {% csrf_token %}



  <div class="modal-body">

    <div class="{% if form.non_field_errors %}invalid{% endif %} mb-2">
      {% for error in form.non_field_errors %}
        {{ error }}
      {% endfor %}
    </div>

      <div class="form-group row">
          <div class="col">
            <p class="titreMiniBoxesAccueil">Nom</p>
            <div class="input-group " id="nom" data-target-input="nearest">
                <input type="text" class="form-control textAccueil" data-target="#nom" name="nom" value="{{form.nom.value}}" placeholder="Nom du pass" required/>
            </div>
            <hr>
            <p class="soustitreMiniBoxesAccueil">Nombre de paiements</p>
            <div class="input-group " id="nbPaiement" data-target-input="nearest">
                <input type="number" class="form-control textAccueil" data-target="#nbPaiement" name="nbPaiement" value="{{form.nbPaiement.value}}" placeholder="Chiffre" required/>
            </div>
            <hr>
            <p class="soustitreMiniBoxesAccueil">Descriptif Français</p>
            <div class="input-group " id="descriptif" data-target-input="nearest">
                <input type="text" class="form-control textAccueil" data-target="#descriptif" name="descriptif" {% if form.descriptif.value %} value="{{form.descriptif.value}}" {% endif %} placeholder="Descriptif du pass en français"/>
            </div>
            <hr>
            <p class="soustitreMiniBoxesAccueil">Descriptif Anglais</p>
            <div class="input-group " id="descriptifEn" data-target-input="nearest">
                <input type="text" class="form-control textAccueil" data-target="#descriptifEn" name="descriptifEn" {% if form.descriptifEn.value %} value="{{form.descriptifEn.value}}" {% endif %} placeholder="Descriptif du pass en anglais"/>
            </div>
            <hr>
            <p class="soustitreMiniBoxesAccueil">Prix</p>
            <div class="input-group " id="prix" data-target-input="nearest">
                <input type="number" class="form-control textAccueil" data-target="#prix" name="prix" value="{{form.prix.value}}" placeholder="Prix du pass" required />
            </div>
            <hr>
            <p class="soustitreMiniBoxesAccueil">Devise</p>
            {% render_field form.devise class="selectVenue" value="form.devise.value" name="devise"%}


          </div>

      </div>

  </div>

  <div class="modal-footer">
      <button type="button" class=" cancelbtn" data-dismiss="modal">Annuler</button>
      <button type="submit" class=" submit-btn btn deletebtn">Confirmer</button>
  </div>

</form>
<script>
$(function () {
    $("option").addClass("selectGuestItem")
  });
</script>


image

As you can see in the picture, it goes from: Create -> success_url -> "/". Do you know how i'd make it stop at the success url?

saadsaoulajan avatar Nov 18 '20 10:11 saadsaoulajan