Tomas "Jethro" Pokorny
5 years ago
9 changed files with 242 additions and 17 deletions
@ -0,0 +1,24 @@ |
|||||
|
# Generated by Django 2.2.9 on 2020-02-28 13:01 |
||||
|
|
||||
|
from django.db import migrations, models |
||||
|
import django.db.models.deletion |
||||
|
|
||||
|
|
||||
|
class Migration(migrations.Migration): |
||||
|
|
||||
|
dependencies = [ |
||||
|
('seminar', '0073_copy_osoba_email_to_user_email'), |
||||
|
] |
||||
|
|
||||
|
operations = [ |
||||
|
migrations.AddField( |
||||
|
model_name='prilohareseni', |
||||
|
name='res_poznamka', |
||||
|
field=models.TextField(blank=True, help_text='Poznámka k příloze řešení, např. co daný soubor obsahuje', verbose_name='poznámka řešitele'), |
||||
|
), |
||||
|
migrations.AlterField( |
||||
|
model_name='hodnoceni', |
||||
|
name='problem', |
||||
|
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='hodnoceni', to='seminar.Problem', verbose_name='problém'), |
||||
|
), |
||||
|
] |
@ -0,0 +1,18 @@ |
|||||
|
# Generated by Django 2.2.9 on 2020-02-28 19:10 |
||||
|
|
||||
|
from django.db import migrations, models |
||||
|
|
||||
|
|
||||
|
class Migration(migrations.Migration): |
||||
|
|
||||
|
dependencies = [ |
||||
|
('seminar', '0074_auto_20200228_1401'), |
||||
|
] |
||||
|
|
||||
|
operations = [ |
||||
|
migrations.AlterField( |
||||
|
model_name='hodnoceni', |
||||
|
name='body', |
||||
|
field=models.DecimalField(decimal_places=1, max_digits=8, null=True, verbose_name='body'), |
||||
|
), |
||||
|
] |
@ -0,0 +1,19 @@ |
|||||
|
# Generated by Django 2.2.9 on 2020-02-28 19:13 |
||||
|
|
||||
|
from django.db import migrations, models |
||||
|
import django.db.models.deletion |
||||
|
|
||||
|
|
||||
|
class Migration(migrations.Migration): |
||||
|
|
||||
|
dependencies = [ |
||||
|
('seminar', '0075_auto_20200228_2010'), |
||||
|
] |
||||
|
|
||||
|
operations = [ |
||||
|
migrations.AlterField( |
||||
|
model_name='hodnoceni', |
||||
|
name='cislo_body', |
||||
|
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, related_name='hodnoceni', to='seminar.Cislo', verbose_name='číslo pro body'), |
||||
|
), |
||||
|
] |
@ -0,0 +1,49 @@ |
|||||
|
// Credit https://medium.com/all-about-django/adding-forms-dynamically-to-a-django-formset-375f1090c2b0
|
||||
|
function updateElementIndex(el, prefix, ndx) { |
||||
|
var id_regex = new RegExp('(' + prefix + '-\\d+)'); |
||||
|
var replacement = prefix + '-' + ndx; |
||||
|
if ($(el).attr("for")) { |
||||
|
$(el).attr("for", $(el).attr("for").replace(id_regex, replacement)); |
||||
|
} |
||||
|
if (el.id) { |
||||
|
el.id = el.id.replace(id_regex, replacement); |
||||
|
} |
||||
|
if (el.name) { |
||||
|
el.name = el.name.replace(id_regex, replacement); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// Credit https://medium.com/all-about-django/adding-forms-dynamically-to-a-django-formset-375f1090c2b0
|
||||
|
function deleteForm(prefix, btn) { |
||||
|
var total = parseInt($('#id_' + prefix + '-TOTAL_FORMS').val()); |
||||
|
if (total >= 1){ |
||||
|
btn.closest('div').remove(); |
||||
|
var forms = $('.attachment'); |
||||
|
$('#id_' + prefix + '-TOTAL_FORMS').val(forms.length); |
||||
|
for (var i=0, formCount=forms.length; i<formCount; i++) { |
||||
|
$(forms.get(i)).find(':input').each(function() { |
||||
|
updateElementIndex(this, prefix, i); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
// Credit: https://simpleit.rocks/python/django/dynamic-add-form-with-add-button-in-django-modelformset-template/
|
||||
|
$(document).ready(function(){ |
||||
|
$('#add_attachment').click(function() { |
||||
|
var form_idx = $('#id_prilohy-TOTAL_FORMS').val(); |
||||
|
var new_form = $('#empty_form').html().replace(/__prefix__/g, form_idx); |
||||
|
$('#form_set').append(new_form); |
||||
|
// Newly created form has not the binding between remove button and remove function
|
||||
|
// We need to add it manually
|
||||
|
$('.remove_attachment').click(function(){ |
||||
|
deleteForm("prilohy",this); |
||||
|
}); |
||||
|
$('#id_prilohy-TOTAL_FORMS').val(parseInt(form_idx) + 1); |
||||
|
}); |
||||
|
$('.remove_attachment').click(function(){ |
||||
|
deleteForm("prilohy",this); |
||||
|
}); |
||||
|
}); |
||||
|
|
@ -0,0 +1,44 @@ |
|||||
|
{% extends "seminar/zadani/base.html" %} |
||||
|
{% load staticfiles %} |
||||
|
{% block script %} |
||||
|
<!--script type="text/javascript" src="{% static 'admin/js/vendor/jquery/jquery.js' %}"></script!--> |
||||
|
{{form.media}} |
||||
|
<script src="{% static 'seminar/dynamic_formsets.js' %}"></script> |
||||
|
{% endblock %} |
||||
|
|
||||
|
{% block content %} |
||||
|
<h1> |
||||
|
{% block nadpis1a %}{% block nadpis1b %} |
||||
|
Vložit řešení |
||||
|
{% endblock %}{% endblock %} |
||||
|
</h1> |
||||
|
<form enctype="multipart/form-data" action="{% url 'seminar_nahraj_reseni' %}" method="post"> |
||||
|
{% csrf_token %} |
||||
|
{{form}} |
||||
|
{{prilohy.management_form}} |
||||
|
<div id="form_set"> |
||||
|
{% for form in prilohy.forms %} |
||||
|
<div class="attachment"> |
||||
|
{{form.non_field_errors}} |
||||
|
{{form.errors}} |
||||
|
<table class='no_error'> |
||||
|
{{ form }} |
||||
|
</table> |
||||
|
<input type="button" value="Odebrat" class="remove_attachment" id="{{form.prefix}}-jsremove"> |
||||
|
</div> |
||||
|
{% endfor %} |
||||
|
</div> |
||||
|
<input type="button" value="Přidat přílohu" id="add_attachment"> |
||||
|
<div id="empty_form" style="display:none"> |
||||
|
<div class="attachment"> |
||||
|
<table class='no_error'> |
||||
|
{{ prilohy.empty_form }} |
||||
|
</table> |
||||
|
<input type="button" value="Odebrat" class="remove_attachment" id="id_prilohy-__prefix__-jsremove"> |
||||
|
</div> |
||||
|
|
||||
|
</div> |
||||
|
<input type="submit" value="Odevzdat"> |
||||
|
</form> |
||||
|
|
||||
|
{% endblock %} |
Loading…
Reference in new issue