Compare commits

...

3 Commits

Author SHA1 Message Date
ed6879b7f1 Add clone option for schedules 2020-05-19 11:20:09 +02:00
485307b78e Add text color red 2020-05-19 11:19:58 +02:00
1edae44647 Allow some fields to be null 2020-05-19 11:19:37 +02:00
7 changed files with 103 additions and 20 deletions

View File

@ -35,6 +35,10 @@ form#new_schedule_form input {
width: 100%
}
.text-danger {
color: #721c24;
}
.alert-warning {
color: #856404;
background-color: #fff3cd;

View File

@ -0,0 +1,30 @@
# Generated by Django 3.0.6 on 2020-05-19 08:21
import collections
from django.db import migrations, models
import jsonfield.fields
class Migration(migrations.Migration):
dependencies = [
('schedule', '0004_auto_20200518_1425'),
]
operations = [
migrations.AlterField(
model_name='schedule',
name='output_peregrine',
field=models.BinaryField(blank=True, help_text='This is the output in binary format from the Peregrine cluster', null=True, verbose_name='Peregrine binary output'),
),
migrations.AlterField(
model_name='schedule',
name='peregrine_result',
field=jsonfield.fields.JSONField(blank=True, help_text='The results from the Peregrine job in JSON', load_kwargs={'object_pairs_hook': collections.OrderedDict}, null=True, verbose_name='Peregrine JSON output'),
),
migrations.AlterField(
model_name='schedule',
name='planning_source',
field=jsonfield.fields.JSONField(blank=True, help_text='The schedule input in JSON format based on the form data', load_kwargs={'object_pairs_hook': collections.OrderedDict}, null=True, verbose_name='Schedule input'),
),
]

View File

@ -76,11 +76,11 @@ class Schedule(MetaDataModel):
status = models.CharField(_('Status'), max_length=10, choices=ScheduleStatus.choices, default=ScheduleStatus.NEW, help_text=_('The status of this schedule.'), db_index=True, )
planning_source = JSONField(_('Schedule input'), blank=True, load_kwargs={'object_pairs_hook': collections.OrderedDict}, help_text=_('The schedule input in JSON format based on the form data'))
planning_source = JSONField(_('Schedule input'), blank=True, null=True, load_kwargs={'object_pairs_hook': collections.OrderedDict}, help_text=_('The schedule input in JSON format based on the form data'))
peregrine_result = JSONField(_('Peregrine JSON output'), blank=True, load_kwargs={'object_pairs_hook': collections.OrderedDict}, help_text=_('The results from the Peregrine job in JSON'))
peregrine_result = JSONField(_('Peregrine JSON output'), blank=True, null=True, load_kwargs={'object_pairs_hook': collections.OrderedDict}, help_text=_('The results from the Peregrine job in JSON'))
output_peregrine = models.BinaryField(_('Peregrine binary output'), blank=True, help_text=_('This is the output in binary format from the Peregrine cluster'))
output_peregrine = models.BinaryField(_('Peregrine binary output'), blank=True, null=True, help_text=_('This is the output in binary format from the Peregrine cluster'))
report_sent = models.DateTimeField(_('Report is send to user'), blank=True, null=True, help_text=_('The date and time when the report has sended to the user.'))

View File

@ -14,6 +14,7 @@
<th>{% trans "Updated" %}</th>
<th>{% trans "Status" %}</th>
<th>{% trans "Report" %}</th>
<th>{% trans "Actions" %}</th>
</tr>
{% for schedule in object_list %}
<tr>
@ -23,6 +24,7 @@
<td>{{ schedule.updated_at|date:"SHORT_DATETIME_FORMAT" }}</td>
<td>{{ schedule.get_status_display }}</td>
<td>None</td>
<td><a href="{% url 'schedule:clone' schedule_id=schedule.id %}">Clone</a></td>
</tr>
{% empty %}
<tr>

View File

@ -2,8 +2,8 @@
{% load i18n %}
{% load static %}
{% block title %}{% trans "New schedule" %}{% endblock %}
{% block pagetitle %}{% trans "New schedule" %}{% endblock %}
{% block title %}{% if form.json.value %}{% trans "Clone schedule" %}{% else %}{% trans "New schedule" %}{% endif %}{% endblock %}
{% block pagetitle %}{% if form.json.value %}{% trans "Clone schedule" %}{% else %}{% trans "New schedule" %}{% endif %}{% endblock %}
{% block content %}
<form method="POST" action="{% url 'schedule:new' %}" id="new_schedule_form">
{% csrf_token %}
@ -464,7 +464,7 @@
var clone = jQuery('div.poliekliniek_specialisatie:first').clone()
clone.find('input').val('');
clone.find('option:disabled').removeAttr('disabled');
clone.find('small').show();
clone.find('small.text-muted').show();
clone.insertAfter('div.poliekliniek_specialisatie:last');
updateSpecialisaties();
loadRemoveSpecialisatie();
@ -476,6 +476,7 @@
jQuery(this).parentsUntil('.poliekliniek_specialisatie').parent().remove();
updateSpecialisaties();
updateSpecialisatieValues();
calculateBehandelingen();
});
}
@ -502,7 +503,7 @@
});
jQuery('div.werktijden select').off('change').on('change',function(event){
check_working_hours(this);
check_working_hours(jQuery(this).parentsUntil('.werktijden').parent());
});
}
@ -536,11 +537,7 @@
clone.insertAfter('tr.behandeling:last');
jQuery('tr.behandeling input.behandeling_calc').off('change keyup').on('change keyup',function(){
calculateBehandelingen();
});
jQuery('tr.behandeling select').off('change').on('change',function(){
jQuery('tr.behandeling :input').off('change keyup').on('change keyup',function(){
calculateBehandelingen();
});
@ -554,6 +551,7 @@
jQuery(this).parentsUntil('.behandeling').parent().remove();
updateBehandelingen();
calculateBehandelingen();
});
}
@ -811,8 +809,11 @@
}
function check_working_hours(html, showerror) {
html = jQuery(html).parentsUntil('.werktijden').parent();
html = jQuery(html[0]);
if (Array.isArray(html)) {
html = html[0];
}
html = jQuery(html);
let day_start = html.find('select[name^="werkdag_start_afdeling_"]');
let day_end = html.find('select[name^="werkdag_end_afdeling_"]');
@ -917,6 +918,35 @@
}
}
function load_clone_data() {
if (jQuery('input#id_json').val() != '') {
let form = jQuery('form#new_schedule_form');
let json_data = JSON.parse(form.find('input#id_json').val());
jQuery.each(json_data,function(key,value){
let input = form.find(':input[name="' + key + '"]');
if (input.length == 0) {
// check for second or more specilism or treatment
if (key.indexOf('behandeling') >= 0) {
addBehandeling();
} else {
addSpecialisatie();
}
input = form.find(':input[name="' + key + '"]');
}
input.val(value);
updateSpecialisatieValues();
});
validate_working_hours();
calculateBehandelingen();
validate_behandeling_hours();
}
}
jQuery(function() {
jQuery('a.add_specialisatie').on('click',function(event){
event.preventDefault();
@ -939,7 +969,7 @@
});
jQuery('div.werktijden select').off('change').on('change',function(event){
check_working_hours(this);
check_working_hours(jQuery(this).parentsUntil('.werktijden').parent());
calculateBehandelingen();
});
@ -949,7 +979,7 @@
});
});
jQuery('input.behandeling_calc').off('change keyup').on('change keyup',function(event){
jQuery('tr.behandeling :input').off('change keyup').on('change keyup',function(event){
calculateBehandelingen();
});
@ -966,10 +996,11 @@
return true;
} else {
alert('Er zijn wat problemen met het formulier. Controleer de invoer velden');
}
return false;
});
load_clone_data();
});
</script>
{% endblock %}

View File

@ -5,5 +5,8 @@ from . import views
app_name = 'schedule'
urlpatterns = [
path('', views.ScheduleListView.as_view(), name='list'),
path('new', views.new_or_update_study, name='new'),
path('new', views.new_or_update_schedule, name='new'),
#path('<int:pk>', views.ScheduleDetailView.as_view(), name='detail'),
path('<int:schedule_id>/clone', views.new_or_update_schedule, name='clone'),
]

View File

@ -3,6 +3,7 @@ from django.shortcuts import render, redirect
from django.views.generic.list import ListView
from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.auth.decorators import login_required
from django.forms.models import model_to_dict
from .models import Schedule
from .forms import ScheduleForm
@ -19,9 +20,16 @@ class ScheduleListView(LoginRequiredMixin,ListView):
return Schedule.objects.filter(employee=self.request.user.employee).order_by('-created_at')
@login_required
def new_or_update_study(request, schedule = None):
def new_or_update_schedule(request, schedule_id = None):
template_name = 'schedule/schedule_new.html'
schedule = None
if schedule_id is not None:
try:
schedule = Schedule.objects.get(pk=schedule_id)
except Schedule.DoesNotExist:
pass
if request.method == 'POST':
schedule_form = ScheduleForm(request.POST)
@ -43,7 +51,12 @@ def new_or_update_study(request, schedule = None):
return redirect('schedule:list')
else:
schedule_form = ScheduleForm()
if schedule is not None:
print(dir(schedule.planning_source))
schedule = json.dumps(schedule.planning_source)
print(schedule)
schedule_form = ScheduleForm(initial={'json' : schedule})
return render(request, template_name, {
'form' : schedule_form,