3
I’m making a check if there are active classes, if there is should present a modal and not the registration form, but it is not working:
py views.:
from django.shortcuts import render, redirect
from django.core.mail import send_mail
from django.template.loader import get_template
from django.conf import settings
from .models import *
from .forms import *
from registrations.services import email, parentEmail
# CRIAR UM NOVO ALUNO
def create_student(request):
    form = StudentForm(request.POST or None)
    group = Group.objects.filter(active=True).first()
    show_modal = False
    if not group:
        show_modal = True
    if form.is_valid():
        group = Group.objects.filter(active=True).first()
        form.instance.group = group
        student = form.save()
        request.session['student_id'] = student.id
        return redirect('registrations:parent_student')
    return render(request, 'student-form-registration.html', {'form': form})
student-form-registrations.html:
<!-- Modal Fim Inscrição -->
{% if show_modal is True %}
    <div id="modal" class="modal fade" tabindex="-1" role="dialog" id="inscricaoEncerrada">
        <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">Olá! As inscrições para a próxima turma da Estação Hack Teens estão encerradas. A próxima turma vai
                                acontecer nos dias 06 e 07 de Outubro, e as inscrições estarão abertas a partir do dia 03
                                de Setembro! Volte nessa data e não deixe de participar :) </p>
                            <div class="text-center">
                                <a data-dismiss="modal" class="btn btn-primary btn-estacao">Voltar para Estação Hack Teens</a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
{% endif %}
I don’t think you know how to use the {% if %} in the template, someone knows how to help me ?
+1 by the pleonasm in the code, I will definitely use this comparison in the future. hahaha
– fernandosavio
Sorry there Dr. @jsbueno, but it was worth the explanation oksaoskaoskaoksaosk
– Raphael Melo De Lima
In fact, the use of
is Truegoes beyond the aesthetic problem in Python - since values that would normally be true in aifmay not be exactly the same object asTrue(as the very number 1) .– jsbueno
It makes sense @jsbueno mt thanks for the explanation, now it’s already working out you are too!
– Raphael Melo De Lima