0
When someone registers their name and email I create a session and I rescan the page with the name of who signed up, but I’m not able to understand how I do so that the time I rescan the page appears a modal.
py views.:
from django.shortcuts import render, redirect
from .models import *
from registrations.models import Group
def index(request):
form = NewsletterForm(request.POST or None)
group = Group.objects.filter(active=True).first()
show_modal = False
content = {'show_modal': show_modal, 'group': group, 'form': form}
if not group:
show_modal = True
content = {'show_modal': show_modal, 'form': form}
return render(request, 'index.html', content)
if form.is_valid():
contact = form.save()
request.session['contact_id'] = contact.id
request.session.set_expiry(100)
if 'contact_id' in request.session:
show_modal_contact = True
content = {'contact': contact, 'show_modal': show_modal, 'group': group, 'show_modal_contact': show_modal_contact}
return render(request, 'index.html', content)
content = {'contact': contact, 'show_modal': show_modal, 'group': group, 'show_modal_contact': show_modal_contact}
return render(request, 'index.html', content)
return render(request, 'index.html', content)
Modal I want to appear when you save and render the page again:
<!-- Modal Contato -->
{% if show_modal_contact %}
<script type="text/javascript">
setTimeout(function(){
$(window).load(function(){
$('#modal_contato').modal('show');
});
}, 1000)
</script>
{% endif %}
{% if show_modal_contact %}
<div id="modal_contato" class="modal fade in" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-body">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="text-center bottom-border">
<img class="img-modal" src="{% static 'images/ilustra3.png' %}" />
</div>
<p class="text-modal text-center">Pronto, iremos te avisar assim que abrirem novas turmas</p>
<div class="text-center">
<a id="close_modal" class="btn btn-primary btn-estacao">Voltar para Estação Hack Teens</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
{% endif %}
I even read something about AJAX and such, but I could not put in practice, will you be able to give me more this help?
Wouldn’t have to have the class
in
in modal for it to get already open? typeclass="modal fade in"
– fernandosavio
then @fernandosavio the problem that this modal can only be "open" when the person signs up after I use the command
contact = form.save()
 request.session['contact_id'] = contact.id
 request.session.set_expiry(100)
basically it is redirected then I would have a check if you have a session means that he has signed up so then yes should show the modal and not when the page loads– Raphael Melo De Lima
Is this validation done in the correct backend? The frontend only knows that if it receives a variable
show_modal_contact
the true modal should be shown, it is not?– fernandosavio
exact @fernandosavio I’m doing so I’ll edit the post here to be better to view
– Raphael Melo De Lima
Then the line
{% if show_modal_contact %}
will only send the modal HTML when it is required to be shown on the screen. As this modal will only exist when it needs to be shown, IE, will not be hidden waiting for its activation, would just insert thein
same. Already tried to see if the behavior is not the desired?– fernandosavio
worst I tried @fernandosavio as you can see ai edition I did, tested but it does not appear the modal I did a test with a Alert in function and worked, but with modal no kkkk
– Raphael Melo De Lima