Esempio n. 1
0
def i_delete(request):
    """Delete Incident Page

    Delete an incident given an id

    """

    logger.debug('%s view being executed.' % 'incidents.i_delete')

    # If it's a POST, then we are going to delete it after confirmation
    if request.method == 'POST':

        # Check the form elements
        form = DeleteEventForm(request.POST)
        logger.debug('Form submit (POST): %s, with result: %s' % ('DeleteEventForm',form))

        if form.is_valid():

            # Obtain the cleaned data
            id = form.cleaned_data['id']

            # Delete the incident
            Event.objects.filter(id=id).delete()

            # Clear the cache - don't discriminate and just clear everything that impacts events
            cache.delete_many(['timeline','events_ns','event_count_ns'])

            # Set a message that the delete was successful
            messages.add_message(request, messages.SUCCESS, 'Incident id:%s successfully deleted' % id)

        # Invalid form submit
        else:
            # Set a message that the delete was not successful
            messages.add_message(request, messages.ERROR, 'Incident id:%s not deleted' % id)

        # Redirect to the open incidents page
        return HttpResponseRedirect('/admin/i_list')

    # If we get this far, it's a GET

    # Make sure we have an ID
    form = DeleteEventForm(request.GET)
    logger.debug('Form submit (GET): %s, with result: %s' % ('DeleteEventForm',form))

    if form.is_valid():

        # Obtain the cleaned data
        id = form.cleaned_data['id']

        # Print the page (confirm they want to delete the incident)
        return render_to_response(
           'incidents/i_delete.html',
           {
              'title':'System Status Dashboard | Confirm Delete',
              'id':id,
              'nav_section':'event',
              'nav_sub':'i_delete'
           },
           context_instance=RequestContext(request)
        )

    # Invalid request
    else:

        # Set a message that the delete failed and send back to the incidents page
        messages.add_message(request, messages.ERROR, 'Invalid request.')
        return HttpResponseRedirect('/admin/i_list')
Esempio n. 2
0
def ireport_delete(request):
    """Delete Incident Report Page

    Delete an incident report given an id

    """

    logger.debug('%s view being executed.' % 'ireport.ireport_delete')

    # If it's a POST, then we are going to delete it after confirmation
    if request.method == 'POST':

        # Check the form elements
        form = DeleteEventForm(request.POST)
        logger.debug('Form submit (POST): %s, with result: %s' %
                     ('DeleteEventForm', form))

        if form.is_valid():

            # Obtain the cleaned data
            id = form.cleaned_data['id']

            # First, delete any screenshots
            # Obtain the local uploads location
            upload_path = Config_Ireport.objects.filter(
                id=Config_Ireport.objects.values('id')[0]['id']).values(
                    'upload_path')[0]['upload_path']
            # Get any screenshots
            screenshots = Ireport.objects.filter(id=id).values(
                'screenshot1', 'screenshot2')
            for screenshot in screenshots:
                for name, file_path in screenshot.items():
                    if file_path:
                        # Remove the file
                        try:
                            os.remove('%s/%s' % (upload_path, file_path))
                        except OSError:
                            pass

            # Delete the incident
            Ireport.objects.filter(id=id).delete()

            # Set a message that the delete was successful
            messages.add_message(
                request, messages.SUCCESS,
                'Incident report id:%s successfully deleted' % id)

            # Redirect to the incident reports page
            return HttpResponseRedirect('/admin/ireport_list')

        # Invalid form submit
        else:
            # Set a message that the delete was not successful
            messages.add_message(request, messages.ERROR,
                                 'Incident report id:%s not deleted' % id)

            # Redirect to the incident reports page
            return HttpResponseRedirect('/admin/ireport_list')

    # If we get this far, it's a GET and we're looking for confirmation of the delete

    # Make sure we have an ID
    form = DeleteEventForm(request.GET)
    logger.debug('Form submit (GET): %s, with result: %s' %
                 ('DeleteEventForm', form))

    if form.is_valid():

        # Obtain the cleaned data
        id = form.cleaned_data['id']

        # Print the page (confirm they want to delete the incident)
        return render_to_response('ireport/ireport_delete.html', {
            'title':
            'System Status Dashboard | Confirm Incident Report Delete',
            'id': id,
            'nav_section': 'ireport',
            'nav_sub': 'ireport_delete'
        },
                                  context_instance=RequestContext(request))

        # Redirect to the incident reports page
        return HttpResponseRedirect('/admin/ireport_list')

    # Invalid request
    else:
        # Redirect to the incident reports page
        return HttpResponseRedirect('/admin/ireport_list')
def m_delete(request):
    """Delete Maintenance Page

    Delete a maintenance given an id

    """

    logger.debug('%s view being executed.' % 'maintenance.m_delete')

    # If it's a POST, then we are going to delete it after confirmation
    if request.method == 'POST':

        # Check the form elements
        form = DeleteEventForm(request.POST)
        logger.debug('Form submit (POST): %s, with result: %s' %
                     ('DeleteEventForm', form))

        if form.is_valid():

            # Obtain the cleaned data
            id = form.cleaned_data['id']

            # Delete the maintenance
            Event.objects.filter(id=id).delete()

            # Clear the cache - don't discriminate and just clear everything that impacts events
            cache.delete_many(['timeline', 'events_ns', 'event_count_ns'])

            # Set a message that the delete was successful
            messages.add_message(request, messages.SUCCESS,
                                 'Maintenance id:%s successfully deleted' % id)

        # Invalid form submit
        else:
            # Set a message that the delete was not successful
            messages.add_message(request, messages.ERROR,
                                 'Maintenance id:%s not deleted' % id)

        # Redirect to the open incidents page
        return HttpResponseRedirect('/admin/m_list')

    # If we get this far, it's a GET

    # Make sure we have an ID
    form = DeleteEventForm(request.GET)
    logger.debug('Form submit (GET): %s, with result: %s' %
                 ('DeleteEventForm', form))

    if form.is_valid():

        # Obtain the cleaned data
        id = form.cleaned_data['id']

        # Print the page (confirm they want to delete the incident)
        return render_to_response('maintenance/m_delete.html', {
            'title': 'System Status Dashboard | Confirm Delete',
            'id': id,
            'nav_section': 'event',
            'nav_sub': 'm_delete'
        },
                                  context_instance=RequestContext(request))

    # Invalid request
    else:

        # Set a message that the delete failed and send back to the maintenance page
        messages.add_message(request, messages.ERROR, 'Invalid request.')
        return HttpResponseRedirect('/admin/m_list')
def ireport_delete(request):
    """Delete Incident Report Page

    Delete an incident report given an id

    """

    logger.debug('%s view being executed.' % 'ireport.ireport_delete')

    # If it's a POST, then we are going to delete it after confirmation
    if request.method == 'POST':
        
        # Check the form elements
        form = DeleteEventForm(request.POST)
        logger.debug('Form submit (POST): %s, with result: %s' % ('DeleteEventForm',form))

        if form.is_valid():

            # Obtain the cleaned data
            id = form.cleaned_data['id']

            # First, delete any screenshots
            # Obtain the local uploads location
            upload_path = Config_Ireport.objects.filter(id=Config_Ireport.objects.values('id')[0]['id']).values('upload_path')[0]['upload_path']
            # Get any screenshots
            screenshots = Ireport.objects.filter(id=id).values('screenshot1','screenshot2')
            for screenshot in screenshots:
                for name,file_path in screenshot.items():
                    if file_path:
                        # Remove the file
                        try:
                            os.remove('%s/%s' % (upload_path,file_path))
                        except OSError:
                            pass


            # Delete the incident
            Ireport.objects.filter(id=id).delete()

            # Set a message that the delete was successful
            messages.add_message(request, messages.SUCCESS, 'Incident report id:%s successfully deleted' % id)

            # Redirect to the incident reports page
            return HttpResponseRedirect('/admin/ireport_list')

        # Invalid form submit
        else:
            # Set a message that the delete was not successful
            messages.add_message(request, messages.ERROR, 'Incident report id:%s not deleted' % id)
            
            # Redirect to the incident reports page
            return HttpResponseRedirect('/admin/ireport_list')

    # If we get this far, it's a GET and we're looking for confirmation of the delete
   
    # Make sure we have an ID
    form = DeleteEventForm(request.GET)
    logger.debug('Form submit (GET): %s, with result: %s' % ('DeleteEventForm',form))

    if form.is_valid():

        # Obtain the cleaned data
        id = form.cleaned_data['id']

        # Print the page (confirm they want to delete the incident)
        return render_to_response(
           'ireport/ireport_delete.html',
           {
              'title':'System Status Dashboard | Confirm Incident Report Delete',
              'id':id,
              'nav_section':'ireport',
              'nav_sub':'ireport_delete'
           },
           context_instance=RequestContext(request)
        )

        # Redirect to the incident reports page
        return HttpResponseRedirect('/admin/ireport_list')

    # Invalid request
    else:
        # Redirect to the incident reports page
        return HttpResponseRedirect('/admin/ireport_list')