Beispiel #1
0
 def do_action_change(self, request, queryset,
                      action: ChangeFieldAction,
                      action_name: str) -> HttpResponse:
     """
     Execute a change action on a group of selected records
     :param request: Request object from the page
     :param queryset: queryset with the data to edit
     :param action: ChangeFieldAction object containing the messages
     :param action_name: called action name
     :return: HttpResponse or HttpResponseRedirect object
     """
     form = action.form(request.POST)
     if 'action_%s' % action_name in request.POST:
         if form.is_valid():
             # Change Field for every selected row
             fields = {action.field_name: form.cleaned_data['changed_data']}
             queryset.update(**fields)
             # Operation successful
             self.message_user(request,
                               pgettext_lazy(
                                   'Host',
                                   'Changed {COUNT} hosts'.format(
                                       COUNT=queryset.count())))
             return HttpResponseRedirect(request.get_full_path())
     # Render form to confirm changes
     return render(request,
                   'utility/change_attribute/form.html',
                   context={'queryset': queryset,
                            'form': form,
                            'title': action.title,
                            'question': action.question,
                            'items_name': action.item,
                            'action': 'action_%s' % action_name,
                            'action_description': action.title,
                            })
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <https://www.gnu.org/licenses/>.
##

from django import forms
from django.utils.translation import pgettext_lazy

from ..models.company import Company

from utility.misc import ChangeFieldAction


class ChangeCompanyForm(forms.Form):
    _selected_action = forms.CharField(widget=forms.MultipleHiddenInput)
    changed_data = forms.ModelChoiceField(queryset=Company.objects,
                                          required=False,
                                          label=pgettext_lazy(
                                              'Host', 'Company'))


change_field_company_action = ChangeFieldAction(
    item='Company',
    field_name='company',
    title=pgettext_lazy('Host', 'Change Company'),
    question=pgettext_lazy(
        'Host', 'Confirm you want to change the '
        'company for the selected hosts?'),
    form=ChangeCompanyForm)
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <https://www.gnu.org/licenses/>.
##

from django import forms
from django.utils.translation import pgettext_lazy

from ..models.snmp_version import SNMPVersion

from utility.misc import ChangeFieldAction


class ChangeSNMPVersionForm(forms.Form):
    _selected_action = forms.CharField(widget=forms.MultipleHiddenInput)
    changed_data = forms.ModelChoiceField(queryset=SNMPVersion.objects,
                                          required=False,
                                          label=pgettext_lazy(
                                              'Host', 'SNMP version'))


change_field_snmp_version_action = ChangeFieldAction(
    item='SNMP Version',
    field_name='snmp_version',
    title=pgettext_lazy('Host', 'Change SNMP Version'),
    question=pgettext_lazy(
        'Host', 'Confirm you want to change the '
        'SNMP version for the selected hosts?'),
    form=ChangeSNMPVersionForm)
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <https://www.gnu.org/licenses/>.
##

from django import forms
from django.utils.translation import pgettext_lazy

from ..models.location import Location

from utility.misc import ChangeFieldAction


class ChangeLocationForm(forms.Form):
    _selected_action = forms.CharField(widget=forms.MultipleHiddenInput)
    changed_data = forms.ModelChoiceField(queryset=Location.objects,
                                          required=False,
                                          label=pgettext_lazy(
                                              'Host', 'Location'))


change_field_location_action = ChangeFieldAction(
    item='Location',
    field_name='location',
    title=pgettext_lazy('Host', 'Change Location'),
    question=pgettext_lazy(
        'Host', 'Confirm you want to change the '
        'location for the selected hosts?'),
    form=ChangeLocationForm)
Beispiel #5
0
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <https://www.gnu.org/licenses/>.
##

from django import forms
from django.utils.translation import pgettext_lazy

from ..models.operating_system import OperatingSystem

from utility.misc import ChangeFieldAction


class ChangeOperatingSystemForm(forms.Form):
    _selected_action = forms.CharField(widget=forms.MultipleHiddenInput)
    changed_data = forms.ModelChoiceField(
        queryset=OperatingSystem.objects,
        required=False,
        label=pgettext_lazy('Host',
                            'Operating system'))


change_field_os_action = ChangeFieldAction(
    item='Operating System',
    field_name='os',
    title=pgettext_lazy('Host', 'Change Operating System'),
    question=pgettext_lazy('Host',
                           'Confirm you want to change the '
                           'operating system for the selected hosts?'),
    form=ChangeOperatingSystemForm)
Beispiel #6
0
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <https://www.gnu.org/licenses/>.
##

from django import forms
from django.utils.translation import pgettext_lazy

from ..models.scanner import Scanner

from utility.misc import ChangeFieldAction


class ChangeScannerForm(forms.Form):
    _selected_action = forms.CharField(widget=forms.MultipleHiddenInput)
    changed_data = forms.ModelChoiceField(queryset=Scanner.objects,
                                          required=False,
                                          label=pgettext_lazy(
                                              'Discovery', 'Scanner'))


change_field_scanner_action = ChangeFieldAction(
    item='Scanner',
    field_name='scanner',
    title=pgettext_lazy('Discovery', 'Change Scanner'),
    question=pgettext_lazy(
        'Discovery', 'Confirm you want to change the '
        'scanner for the selected discoveries?'),
    form=ChangeScannerForm)
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <https://www.gnu.org/licenses/>.
##

from django import forms
from django.utils.translation import pgettext_lazy

from ..models.domain import Domain

from utility.misc import ChangeFieldAction


class ChangeDomainForm(forms.Form):
    _selected_action = forms.CharField(widget=forms.MultipleHiddenInput)
    changed_data = forms.ModelChoiceField(queryset=Domain.objects,
                                          required=False,
                                          label=pgettext_lazy(
                                              'Host', 'Network domain'))


change_field_domain_action = ChangeFieldAction(
    item='Domain',
    field_name='domain',
    title=pgettext_lazy('Host', 'Change Domain'),
    question=pgettext_lazy(
        'Host', 'Confirm you want to change the '
        'domain for the selected hosts?'),
    form=ChangeDomainForm)
from ..models.subnet_v4 import SubnetV4

from utility.misc import ChangeFieldAction


class ChangeSubnetV4Form(forms.Form):
    _selected_action = forms.CharField(widget=forms.MultipleHiddenInput)
    changed_data = forms.ModelChoiceField(queryset=SubnetV4.objects,
                                          required=False,
                                          label=pgettext_lazy(
                                              'Host', 'Subnet v4'))


change_field_host_subnetv4_action = ChangeFieldAction(
    item='Subnet v4',
    field_name='subnetv4',
    title=pgettext_lazy('Host', 'Change Subnet v4'),
    question=pgettext_lazy(
        'Host', 'Confirm you want to change the '
        'subnet v4 for the selected hosts?'),
    form=ChangeSubnetV4Form)

change_field_discovery_subnetv4_action = ChangeFieldAction(
    item='Subnet v4',
    field_name='subnetv4',
    title=pgettext_lazy('Discovery', 'Change Subnet v4'),
    question=pgettext_lazy(
        'Discovery', 'Confirm you want to change the '
        'subnet v4 for the selected discoveries?'),
    form=ChangeSubnetV4Form)
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <https://www.gnu.org/licenses/>.
##

from django import forms
from django.utils.translation import pgettext_lazy

from ..models.device_model import DeviceModel

from utility.misc import ChangeFieldAction


class ChangeDeviceModelForm(forms.Form):
    _selected_action = forms.CharField(widget=forms.MultipleHiddenInput)
    changed_data = forms.ModelChoiceField(queryset=DeviceModel.objects,
                                          required=False,
                                          label=pgettext_lazy(
                                              'Host', 'Device model'))


change_field_device_model_action = ChangeFieldAction(
    item='Device Model',
    field_name='device_model',
    title=pgettext_lazy('Host', 'Change Device model'),
    question=pgettext_lazy(
        'Host', 'Confirm you want to change the '
        'device model for the selected hosts?'),
    form=ChangeDeviceModelForm)