further improvements to create/edit alerts
This commit is contained in:
@@ -38,16 +38,17 @@ def create_alert(manager, rower, measured,period=7, emailalert=True,
|
||||
if 'filter' in kwargs:
|
||||
filters = kwargs['filter']
|
||||
for f in filters:
|
||||
m = Condition(
|
||||
metric = f['metric'],
|
||||
value1 = f['value1'],
|
||||
value2 = f['value2'],
|
||||
condition = f['condition']
|
||||
if f['metric'] and f['condition']:
|
||||
m = Condition(
|
||||
metric = f['metric'],
|
||||
value1 = f['value1'],
|
||||
value2 = f['value2'],
|
||||
condition = f['condition']
|
||||
)
|
||||
|
||||
m.save()
|
||||
|
||||
m.save()
|
||||
|
||||
alert.filter.add(m)
|
||||
alert.filter.add(m)
|
||||
|
||||
|
||||
return alert.id,'Your alert was created'
|
||||
|
||||
@@ -1022,7 +1022,7 @@ class Condition(models.Model):
|
||||
)
|
||||
metric = models.CharField(max_length=50,choices=parchoicesy1,verbose_name='Metric')
|
||||
value1 = models.FloatField(default=0)
|
||||
value2 = models.FloatField(default=0)
|
||||
value2 = models.FloatField(default=0,null=True,blank=True)
|
||||
condition = models.CharField(max_length=20,choices=conditionchoices,null=True)
|
||||
|
||||
class ConditionEditForm(ModelForm):
|
||||
@@ -1030,6 +1030,11 @@ class ConditionEditForm(ModelForm):
|
||||
model = Condition
|
||||
fields = ['metric','condition','value1','value2']
|
||||
|
||||
def clean(self):
|
||||
cd = self.cleaned_data
|
||||
if cd['condition'] == 'between' and cd['value2'] is None:
|
||||
raise forms.ValidationError('When using between, you must fill value 1 and value 2')
|
||||
|
||||
class BaseConditionFormSet(BaseFormSet):
|
||||
def clean(self):
|
||||
if any(self.errors):
|
||||
|
||||
@@ -41,16 +41,16 @@
|
||||
<input type="submit" value="Save">
|
||||
</p>
|
||||
</li>
|
||||
{% for filter_form in formset %}
|
||||
<li class="grid_2">
|
||||
{% for filter_form in formset %}
|
||||
<div class="fav-formset">
|
||||
<h2>Filter {{ forloop.counter }}</h2>
|
||||
<table width=100%>
|
||||
{{ filter_form.as_table }}
|
||||
</table>
|
||||
</div>
|
||||
</li>
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
</li>
|
||||
</ul>
|
||||
</form>
|
||||
|
||||
|
||||
@@ -39,16 +39,16 @@
|
||||
<input type="submit" value="Save">
|
||||
</p>
|
||||
</li>
|
||||
{% for filter_form in formset %}
|
||||
<li class="grid_2">
|
||||
{% for filter_form in formset %}
|
||||
<div class="fav-formset">
|
||||
<h2>Filter {{ forloop.counter }}</h2>
|
||||
<table width=100%>
|
||||
{{ filter_form.as_table }}
|
||||
</table>
|
||||
</div>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</li>
|
||||
</ul>
|
||||
</form>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user