Make normal alert profile editable if setting enabled.
This commit is contained in:
parent
379653f9ac
commit
1d82fe45bf
|
@ -24,6 +24,7 @@ import simplejson as json
|
|||
|
||||
from django import forms
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.conf import settings
|
||||
|
||||
from . import models
|
||||
|
||||
|
@ -59,11 +60,13 @@ class SimpleAlertProfileForm(forms.ModelForm):
|
|||
|
||||
class Meta:
|
||||
model = models.Patient
|
||||
fields = ['simple_alert_profile']
|
||||
fields = ['simple_alert_profile', 'alert_profile']
|
||||
widgets = {'simple_alert_profile': forms.HiddenInput()}
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(SimpleAlertProfileForm, self).__init__(*args, **kwargs)
|
||||
if not settings.DISPLAY_ALERT_PROFILE:
|
||||
del self.fields['alert_profile']
|
||||
if self.instance and self.instance.get_simple_alert_profile():
|
||||
for key, value in self.instance.get_simple_alert_profile().items():
|
||||
if value is not None:
|
||||
|
@ -72,9 +75,13 @@ class SimpleAlertProfileForm(forms.ModelForm):
|
|||
def clean(self):
|
||||
cleaned_data = super(SimpleAlertProfileForm, self).clean()
|
||||
sap = {}
|
||||
new_cd = {}
|
||||
if 'alert_profile' in cleaned_data:
|
||||
new_cd['alert_profile'] = cleaned_data.get('alert_profile')
|
||||
del cleaned_data['alert_profile']
|
||||
for k in self.fields.items():
|
||||
if cleaned_data.get(k[0]):
|
||||
sap[k[0]] = cleaned_data.get(k[0])
|
||||
cleaned_data = dict()
|
||||
cleaned_data = new_cd
|
||||
cleaned_data['simple_alert_profile'] = json.dumps(sap)
|
||||
return cleaned_data
|
||||
|
|
|
@ -184,3 +184,4 @@ SENSOR_MAPPING = {
|
|||
'HR' : 'heartrate',
|
||||
'T' : 'temperature',
|
||||
}
|
||||
DISPLAY_ALERT_PROFILE = True
|
||||
|
|
|
@ -159,6 +159,12 @@
|
|||
</div>
|
||||
<input type="submit" value="{% trans "Validate" %}"/>
|
||||
</div>
|
||||
{% if display_alert_profile %}<div class="sap-metric">
|
||||
{{ forms.simple_alert_profile.alert_profile.errors }}
|
||||
{{ forms.simple_alert_profile.alert_profile.label_tag }}
|
||||
{{ forms.simple_alert_profile.alert_profile }}
|
||||
<input type="submit" value="{% trans "Validate" %}"/>
|
||||
</div>{% endif %}
|
||||
<div class="fieldWrapper">
|
||||
{{ forms.simple_alert_profile.simple_simple_alert_profile }}
|
||||
</div>
|
||||
|
|
|
@ -28,6 +28,7 @@ from django.http import HttpResponseRedirect
|
|||
from django.core.urlresolvers import reverse_lazy
|
||||
from django.contrib import messages
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.conf import settings
|
||||
|
||||
from . import cbv
|
||||
from . import models
|
||||
|
@ -118,6 +119,10 @@ class PatientDetail(cbv.MultiUpdateView):
|
|||
messages.add_message(self.request, messages.INFO, _(u'Patient record updated.'))
|
||||
return super(PatientDetail, self).form_valid(form)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(PatientDetail, self).get_context_data(**kwargs)
|
||||
context['display_alert_profile'] = settings.DISPLAY_ALERT_PROFILE
|
||||
return context
|
||||
|
||||
class PatientDelete(DeleteView):
|
||||
model = models.Patient
|
||||
|
|
Reference in New Issue