def __init__(self, *args, **kwargs): super(ThresholdForm, self).__init__(*args, **kwargs) self.fields['alert'].label = 'Alert threshold' self.fields['clear'].label = 'Clear alert' self.fields['raw'].help_text = "(Advanced): Do not transform the " \ "target according to NAV's own rules" if self.instance.pk is None: action_text = 'Create rule' else: action_text = 'Edit rule' column_class = 'small-4' self.helper = FormHelper() self.helper.form_action = '' self.helper.layout = Layout( Fieldset( action_text, 'target', Row( Column(HelpField('alert'), css_class=column_class), Column(HelpField('clear'), css_class=column_class), Column(HelpField('period'), css_class=column_class), ), 'description', Row( Column(Submit('submit', 'Save', css_class='small'), css_class='small-6'), Column(HelpField('raw'), css_class='small-6'), )))
def __init__(self, *args, **kwargs): super(MatchFieldForm, self).__init__(*args, **kwargs) self.helper = FormHelper() self.helper.form_tag = False self.helper.layout = Layout( 'id', Row(Column('name', css_class='medium-4'), Column('description', css_class='medium-8')), HelpField('value_help'), Row(Column(HelpField('value_id'), css_class='medium-4'), Column(HelpField('value_name'), css_class='medium-4'), Column(HelpField('value_sort'), css_class='medium-4')), Row(Column(HelpField('list_limit'), css_class='medium-4'), Column(HelpField('data_type'), css_class='medium-4'), Column(HelpField('show_list'), css_class='medium-4')))
def __init__(self, *args, **kwargs): time_period = kwargs.pop('time_period', None) super(AlertSubscriptionForm, self).__init__(*args, **kwargs) hidden_fields = ['id'] if isinstance(time_period, TimePeriod): self.fields['time_period'] = forms.ModelChoiceField( queryset=TimePeriod.objects.filter(id=time_period.id), widget=forms.HiddenInput, initial=time_period.id) hidden_fields.append('time_period') # Get account account = time_period.profile.account addresses = AlertAddress.objects.filter( account=account).order_by('type', 'address') filter_groups = FilterGroup.objects.filter( Q(owner__isnull=True) | Q(owner__exact=account)).order_by('owner', 'name') self.fields['alert_address'] = forms.ModelChoiceField( queryset=addresses, empty_label=None, error_messages={ 'required': 'Alert address is a required field.', 'invalid_choice': ('The selected alert address is an ' 'invalid choice.'), }, label='Send alerts to') self.fields['filter_group'] = forms.ModelChoiceField( queryset=filter_groups, empty_label=None, error_messages={ 'required': 'Filter group is a required field.', 'invalid_choice': ('The selected filter group is an ' 'invalid choice.'), }, label='Watch') self.fields['type'].label = 'When' self.fields['type'].help_text = """ <dl> <dt>Immediately</dt> <dd>Send the alert as soon as alertengine has processed it.</dd> <dt>Daily at predefined time</dt> <dd>Send all matched alerts at the specified daily dispatch time.</dd> <dt>Weekly at predefined time</dt> <dd>Send all matched alerts at the specified weekly dispatch time.</dd> <dt>At end of timeperiod</dt> <dd>Send all matched alerts when the current timeperiod is over and a new one starts.</dd> </dl> """ self.helper = FormHelper() self.helper.layout = Layout( Row( Column(Field('filter_group', css_class='select2'), css_class='medium-3'), Column(Field('alert_address', css_class='select2'), css_class='medium-3'), Column(HelpField('type', css_class='select2'), css_class='medium-3'), Column(Field('ignore_resolved_alerts', css_class='input-align'), css_class='medium-3') ), *hidden_fields )