<commit_before>from django import forms


def datasource_list():
    from datasource import client
    return [(ds['Name'], ds['Name']) for ds in client.list().json()]


def action_list():
    from action import client
    return [(ds['Name'], ds['Name']) for ds in client.list().json()]


class AlarmForm(forms.Form):
    name = forms.CharField()
    expression = forms.CharField()
    enabled = forms.BooleanField()
    wait = forms.IntegerField()
    datasource = forms.ChoiceField(choices=datasource_list)
    actions = forms.MultipleChoiceField(choices=action_list)<commit_msg>alarm/forms: fix form when datasource list or action list is empty.<commit_after>from django import forms


def datasource_list():
    from datasource import client
    dl = client.list().json() or []
    return [(ds['Name'], ds['Name']) for ds in dl]


def action_list():
    from action import client
    al = client.list().json() or []
    return [(ds['Name'], ds['Name']) for ds in al]


class AlarmForm(forms.Form):
    name = forms.CharField()
    expression = forms.CharField()
    enabled = forms.BooleanField()
    wait = forms.IntegerField()
    datasource = forms.ChoiceField(choices=datasource_list)
    actions = forms.MultipleChoiceField(choices=action_list)
{'fraction_non_alphanumeric': 0.12998405103668262, 'fraction_numerical': 0.0, 'mean_word_length': 4.1646090534979425, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3252450', 'n_tokens_mistral': 379, 'n_tokens_neox': 360, 'n_words': 103}