def site_alert_rules(request, site_id): """ Alert rules for a given site """ context_dict = {} site = Sesh_Site.objects.filter(id=site_id).first() alert_rules = Alert_Rule.objects.filter(site=site) form = AlertRuleForm() if request.method == 'POST': form = AlertRuleForm(request.POST) if form.is_valid(): alert_rule = form.save(commit=False) alert_rule.site = site alert_rule.save() return redirect(reverse('site_alert_rules', args=[site.id])) context_dict['form'] = form context_dict['site'] = site context_dict['alert_rules'] = alert_rules user_sites = _get_user_sites(request) context_dict['permitted'] = get_org_edit_permissions(request.user) context_dict['sites_stats'] = get_quick_status(user_sites) return render(request, 'seshdash/settings/alert_rules.html', context_dict)
def edit_alert_rule(request, alert_rule_id): """ Editing alert rules for a given alert rule id """ context_dict = {} alert_rule = Alert_Rule.objects.filter(id=alert_rule_id).first() form = AlertRuleForm(instance=alert_rule) if request.method == 'POST': form = AlertRuleForm(request.POST, instance=alert_rule) if form.is_valid(): form.save() return redirect(reverse('site_alert_rules', args=[alert_rule.site.id])) context_dict['form'] = form return render(request, 'seshdash/settings/edit_alert_rule.html', context_dict)