def handle(self): data = { 'name': self.form_data['group_name'], 'enabled_nodes': None } all_groups = NodeGroups.objects() if data['name'] in [g.name for g in all_groups]: raise forms.ValidationError(self.valid_msg['group_exist']) new_group = NodeGroups(**data) new_group.save() return new_group
def handle(self): selected_node = self.form_data['select_node'] selected_group = self.form_data['select_group'] group = NodeGroups.objects(name=selected_group).first() enabled_nodes = group.enabled_nodes if selected_node in enabled_nodes: del enabled_nodes[enabled_nodes.index(selected_node)] group.update(enabled_nodes=enabled_nodes) return True
def handle(self): selected_node = self.form_data['select_node'] selected_group = self.form_data['select_group'] group = NodeGroups.objects(name=selected_group).first() enabled_nodes = group.enabled_nodes if selected_node in enabled_nodes: raise forms.ValidationError(self.valid_msg['node_in_group']) enabled_nodes.append(selected_node) group.update(enabled_nodes=enabled_nodes) return group.enabled_nodes
def __init__(self, attrs=None, **kwargs): self.kwargs = kwargs if attrs is not None: self.attrs = attrs.copy() else: self.attrs = {} NODES_LIST = [(item.node_name, item.node_name) for item in NodeInfo.objects()] ATTRS = {'class': 'form-control'} PLUGINS_LIST = [(item.plugin_name, item.plugin_name) for item in PluginInfo.objects()] GROUPS_LIST = [(item.name, item.name) for item in NodeGroups.objects()] class CheckboxSelectMultiple(forms.CheckboxSelectMultiple): def render(self, name, value, attrs=None, choices=()): html = super(CheckboxSelectMultiple, self).render(name, value, attrs, choices) return mark_safe(html.replace('<ul>', '<ul class="myClass">')) class MonitoringSettingsForm(forms.Form): operation = forms.ChoiceField(choices=MONITORING_SETTINGS_OPERATIONS, widget=forms.Select(attrs=ATTRS), label=u'Операции по настройке мониторинга') node_name = forms.CharField(widget=forms.TextInput(attrs=ATTRS),
def get_context_data(self, **kwargs): kwargs["groups"] = NodeGroups.objects() return super(GroupsView, self).get_context_data(**kwargs)
def handle(self): group = NodeGroups.objects( name=self.form_data['select_group']).first() group.delete() return True