Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template
- {% extends 'base/base.html' %}
- {% block content %}
- <form class="user" method="POST">
- <div class="card mb-4 py-3 border-left-primary">
- <h2 class="m-2 font-weight-bold text-primary"> Pre Testing Details</h2>
- <div class="dropdown-divider"></div>
- <div class="card-body">
- {% csrf_token %}
- <div class="row form-group">
- <div class="col-sm-6">
- <label id="id_school" class="text-body ">School</label>
- {{ form_enc.school }}
- </div>
- <div class="col-sm-3">
- <label class="text-body ">Testing Date</label>
- {{ form_enc.fecha_examen }}
- </div>
- <div class="col-sm-3">
- <label class="text-body ">Graduation Date</label>
- {{ form_enc.fecha_graduacion }}
- </div>
- </div>
- <div class="dropdown-divider"></div>
- <div class="row form-group">
- <button type="submit" class="btn btn-success waves-effect waves-float mr-2"><span class="fa fa-save"></span> Save</button>
- <a href="{% url 'testing:pretest_list' %}" class="btn btn-danger waves-effect waves-float"><span class="fa fa-undo"></span> Cancel</a>
- </div>
- <h4>Select Candidates</h1>
- <div class="table-responsive">
- <table width="100%" class="table table-bordered " id="dataTables-example" cellspacing="0">
- <thead>
- <tr>
- <th>Id</th>
- <th>Student Name</th>
- <th>Rank</th>
- <th>Test</th>
- <th>Midterm</th>
- <th>Paid</th>
- <th>Order Belt</th>
- </tr>
- </thead>
- <tbody>
- {% for item in student %}
- <tr id="{{ item.id }}">
- <td>{{ item.id }}</td>
- <td>{{ item.first_name }}, {{ item.first_last_name }}</td>
- <td>{{ item.rank }}</td>
- <td><input type="checkbox" name="test" id="test" /> </td>
- <td><input type="checkbox" name="midterm" id="midterm" /> </td>
- <td><input type="checkbox" name="pago" id="pago"/> </td>
- <td><input type="checkbox" name="orderbelt" id="orderbelt" /> </td>
- </tr>
- {% endfor %}
- </tbody>
- </table>
- </div>
- </div>
- <!-- botones aqui -->
- </div>
- </form>
- {% endblock %}
- {% block js_page %}
- <script>
- $(function () {
- $("#id_fecha_examen").datetimepicker({
- format: 'd/m/Y',
- timepicker:false
- });
- $("#id_fecha_graduacion").datetimepicker({
- format: 'd/m/Y',
- timepicker:false
- });
- $("#school").focus();
- });
- var token = $('input[name=csrfmiddlewaretoken]').val();
- $.ajaxSetup({
- beforeSend: function(xhr, settings) {
- if (!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url))) {
- xhr.setRequestHeader("X-CSRFToken", token);
- }
- }
- });
- $('form').on('submit', function(e) {
- e.preventDefault();
- var $dataElements = $('#dataTables-example').find('td'),
- data = [];
- $.each($dataElements, function(i, elem){
- data.push($(elem).html());
- });
- var template="{% url 'testing:pretest_list' %}";
- $.ajax({
- type: "POST",
- url: template,
- data: {data:JSON.stringify(data)},
- beforeSend: function(xhr,settings){
- $.ajaxSettings.beforeSend(xhr,settings);
- },
- success: function(response){
- console.log(response);
- cerrar_modal();
- window.location.reload()
- //alert(response);
- var tipo=(response.startsWith('Escuela no existe') ? 'red':'green' );
- mensaje(response,tipo);
- },
- error: function(jqXHR, textStatus, errorThrow){
- console.log(textStatus, errorThrow);
- mensaje(errorThrow,'red');
- cerrar_modal();
- }
- });
- });
- </script>
- {% endblock js_page %}
- VIEW
- def pretest(request, pretest_id=None):
- template_name="testing/pretesting_form.html"
- rango = ProgramaRank.objects.filter(activo=True).order_by('pk')
- form_pretest ={}
- contexto = {}
- if request.method=="GET":
- form_pretest = PreTestEncForm()
- enc= PreTestEnc.objects.filter(school_id=pretest_id).first()
- if enc:
- det=PreTestDet.objects.filter(pretestenc = enc)
- student = People.objects.filter(school_id=enc.school_id)
- if enc.fecha_examen:
- fecha_examen = datetime.date.isoformat(enc.fecha_examen)
- else:
- fecha_examen = 0
- if enc.fecha_graduacion:
- fecha_graduacion = datetime.date.isoformat(enc.fecha_graduacion)
- else:
- fecha_graduacion = 0
- e={
- 'school': enc.school,
- 'fecha_examen': fecha_examen,
- 'fecha_graduacion': fecha_graduacion,
- }
- form_pretest= PreTestEncForm(e)
- else:
- det = None
- student = People.objects.all()
- contexto = {'rango':rango, 'encabezado':enc, 'detalle':det,'student':student, 'form_enc':form_pretest}
- if request.method=="POST":
- school = request.POST.get("school")
- fecha_examen = request.POST.get("fecha_examen")
- # fecha_examen = datetime.datetime.strptime(fecha_examen, "%d/%m/%Y")
- fecha_graduacion = request.POST.get("fecha_graduacion")
- # fecha_graduacion = datetime.datetime.strptime(fecha_graduacion, "%d/%m/%Y")
- table = request.POST.get("data")
- if not pretest_id:
- enc = PreTestEnc(
- school = school,
- fecha_examen = fecha_examen,
- fecha_graduacion = fecha_graduacion
- )
- if enc:
- enc.save()
- pretest_id = enc.id
- else:
- school = School.objects.filter(pk = school).first()
- enc= PreTestEnc.objects.filter(pk=pretest_id).first()
- if enc:
- enc.school = school
- enc.fecha_examen = fecha_examen
- enc.fecha_graduacion = fecha_graduacion
- enc.save()
- if not pretest_id:
- return redirect("testing:pretest_list")
- for x in table:
- people = request.POST.get("id_student")
- rank = request.POST.get("student.rank")
- test = request.POST.get("test")
- midterm = request.POST.get("midterm")
- paid = request.POST.get("paid")
- orderbelt = request.POST.get("orderbelt")
- det = PreTestDet(
- pretestenc = enc,
- people = people,
- rangoactual = rank,
- test = test,
- midterm = midterm,
- pago = paid,
- order_belt = orderbelt
- )
- # if det:
- #det.save()
- return redirect("testing:pretest_list")
- return render(request, template_name, contexto)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement