Exemplo n.º 1
0
def update_modify(request):
    """Modify event update
        - This occurs only via AJAX from the i_update or m_update views (it's a POST)

    """

    logger.debug('%s view being executed.' % 'events.update_modify')

    # If this is a POST, then validate the form and save the data, otherise do nothing
    if request.method == 'POST':

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

        if form.is_valid():
            pk = form.cleaned_data['pk']
            name = form.cleaned_data['name']
            value = form.cleaned_data['value']

            # Add the column we are updating (but only allow specific values)
            if not name == 'update':
                logger.error(
                    'Invalid column specified during event update modification: %s'
                    % name)
                return HttpResponseBadRequest(
                    'An error was encountered with this request.')

            filter = {}
            filter[name] = value

            # Add the user who is performing this update
            filter['user'] = User.objects.filter(
                username=request.user.username).values('id')[0]['id']

            # Update it
            try:
                Event_Update.objects.filter(id=pk).update(**filter)
            except Exception as e:
                logger.error('%s: Error saving update: %s' %
                             ('events.update_modify', e))
                return HttpResponseBadRequest(
                    'An error was encountered with this request.')

            # Clear the cache
            cache.delete('timeline')

            return HttpResponse('Value successfully modified')

        else:
            logger.error('%s: invalid form: %s' %
                         ('events.update_modify', form.errors))
            return HttpResponseBadRequest('Invalid request')
    else:
        logger.error(
            '%s: Invalid request: GET received but only POST accepted.' %
            ('events.update_modify'))
        messages.add_message(request, messages.ERROR, 'Invalid request.')
        return HttpResponseRedirect('/admin')
Exemplo n.º 2
0
def recipient_modify(request):
    """Modify an email recipient
        - This occurs only via AJAX from the manage recipients view (it's a POST)

    """

    logger.debug('%s view being executed.' % 'email.recipient_modify')

    # If this is a POST, then validate the form and save the data, otherise do nothing
    if request.method == 'POST':

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

        if form.is_valid():
            pk = form.cleaned_data['pk']
            name = form.cleaned_data['name']
            value = form.cleaned_data['value']

            # Add the column we are updating (but only allow specific values)
            if not name == 'email':
                logger.error(
                    'Invalid column specified during recipient modification: %s'
                    % name)
                return HttpResponseBadRequest(
                    'An error was encountered with this request.')

            filter = {}
            filter[name] = value

            # Make sure the email is value
            try:
                validate_email(value)
            except ValidationError:
                return HttpResponseBadRequest('Enter a valid email address.')

            # Update it
            try:
                Email.objects.filter(id=pk).update(**filter)
            except Exception as e:
                logger.error('%s: Error saving update: %s' %
                             ('email.recipient_modify', e))
                return HttpResponseBadRequest(
                    'An error was encountered with this request.')

            return HttpResponse('Value successfully modified')

        else:
            logger.error('%s: invalid form: %s' %
                         ('email.recipient_modify', form.errors))
            return HttpResponseBadRequest('Invalid request')
    else:
        logger.error(
            '%s: Invalid request: GET received but only POST accepted.' %
            ('email.recipient_modify'))
        messages.add_message(request, messages.ERROR, 'Invalid request.')
        return HttpResponseRedirect('/admin/email_recipients')
Exemplo n.º 3
0
def update_modify(request):
    """Modify event update
        - This occurs only via AJAX from the i_update or m_update views (it's a POST)

    """

    logger.debug('%s view being executed.' % 'events.update_modify')

    # If this is a POST, then validate the form and save the data, otherise do nothing
    if request.method == 'POST':
        
        # Check the form elements
        form = XEditableModifyForm(request.POST)
        logger.debug('Form submit (POST): %s, with result: %s' % ('XEditableModifyForm',form))

        if form.is_valid():
            pk = form.cleaned_data['pk']
            name = form.cleaned_data['name']
            value = form.cleaned_data['value']

            # Add the column we are updating (but only allow specific values)
            if not name == 'update':
                logger.error('Invalid column specified during event update modification: %s' % name)
                return HttpResponseBadRequest('An error was encountered with this request.')

            filter = {}
            filter[name] = value

            # Add the user who is performing this update
            filter['user'] = User.objects.filter(username=request.user.username).values('id')[0]['id']

            # Update it
            try:
                Event_Update.objects.filter(id=pk).update(**filter)
            except Exception as e:
                logger.error('%s: Error saving update: %s' % ('events.update_modify',e))
                return HttpResponseBadRequest('An error was encountered with this request.')

            # Clear the cache 
            cache.delete('timeline')

            return HttpResponse('Value successfully modified')

        else:
            logger.error('%s: invalid form: %s' % ('events.update_modify',form.errors))
            return HttpResponseBadRequest('Invalid request')
    else:
        logger.error('%s: Invalid request: GET received but only POST accepted.' % ('events.update_modify'))
        messages.add_message(request, messages.ERROR, 'Invalid request.')
        return HttpResponseRedirect('/admin') 
Exemplo n.º 4
0
def recipient_modify(request):
    """Modify an email recipient
        - This occurs only via AJAX from the manage recipients view (it's a POST)

    """

    logger.debug('%s view being executed.' % 'email.recipient_modify')

    # If this is a POST, then validate the form and save the data, otherise do nothing
    if request.method == 'POST':
        
        # Check the form elements
        form = XEditableModifyForm(request.POST)
        logger.debug('Form submit (POST): %s, with result: %s' % ('XEditableModifyForm',form))

        if form.is_valid():
            pk = form.cleaned_data['pk']
            name = form.cleaned_data['name']
            value = form.cleaned_data['value']

            # Add the column we are updating (but only allow specific values)
            if not name == 'email':
                logger.error('Invalid column specified during recipient modification: %s' % name)
                return HttpResponseBadRequest('An error was encountered with this request.')

            filter = {}
            filter[name] = value

            # Make sure the email is value
            try:
                validate_email(value)
            except ValidationError:
                return HttpResponseBadRequest('Enter a valid email address.')

            # Update it
            try:
                Email.objects.filter(id=pk).update(**filter)
            except Exception as e:
                logger.error('%s: Error saving update: %s' % ('email.recipient_modify',e))
                return HttpResponseBadRequest('An error was encountered with this request.')

            return HttpResponse('Value successfully modified')

        else:
            logger.error('%s: invalid form: %s' % ('email.recipient_modify',form.errors))
            return HttpResponseBadRequest('Invalid request')
    else:
        logger.error('%s: Invalid request: GET received but only POST accepted.' % ('email.recipient_modify'))
        messages.add_message(request, messages.ERROR, 'Invalid request.')
        return HttpResponseRedirect('/admin/email_recipients')     
Exemplo n.º 5
0
def service_modify(request):
    """Modify the name of Services
        - This occurs only via AJAX from the services view (it's a POST)

    """

    logger.debug('%s view being executed.' % 'services.service_modify')

    # If this is a POST, then validate the form and save the data, otherise do nothing
    if request.method == 'POST':

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

        if form.is_valid():
            pk = form.cleaned_data['pk']
            name = form.cleaned_data['name']
            value = form.cleaned_data['value']

            # Add the column we are updating (but only allow specific values)
            if not name == 'service_name':
                logger.error('Invalid column specified during service modification: %s' % name)
                return HttpResponseBadRequest('An error was encountered with this request.')

            filter = {}
            filter[name] = value

            # Update it
            try:
                Service.objects.filter(id=pk).update(**filter)
            except Exception as e:
                logger.error('%s: Error saving update: %s' % ('services.service_modify',e))
                return HttpResponseBadRequest('An error was encountered with this request.')

            # Clear the cache so the modified service listing shows up in the dashboard immediately
            cache.delete('services')

            return HttpResponse('Value successfully modified')

        else:
            logger.error('%s: invalid form: %s' % ('services.service_modify',form.errors))
            return HttpResponseBadRequest('Invalid request')
    else:
        logger.error('%s: Invalid request: GET received but only POST accepted.' % ('services.service_modify'))
        messages.add_message(request, messages.ERROR, 'Invalid request.')
        return HttpResponseRedirect('/admin/services')