parameters: (request, method)
return_statement: return render(request, "error.html", {'error': 'Expected AJAX/POST'})
docstring: Add/update an IP address. Should be an AJAX POST.
  
      :param request: Django request.
      :type request: :class:`django.http.HttpRequest`
      :param method: If this is an "add" or an "update".
      :type method: str
      :returns: :class:`django.http.HttpResponse`
docstring_summary: Add/update an IP address. Should be an AJAX POST.
docstring_tokens: Add / update an IP address . Should be an AJAX POST .
function: def add_update_ip(request, method):
      """
      Add/update an IP address. Should be an AJAX POST.
  
      :param request: Django request.
      :type request: :class:`django.http.HttpRequest`
      :param method: If this is an "add" or an "update".
      :type method: str
      :returns: :class:`django.http.HttpResponse`
      """
  
      if request.method == "POST" and request.is_ajax():
          request.user._setup()
          data = request.POST
          form = AddIPForm(request.user, None, data)
  
          if form.is_valid():
              cleaned_data = form.cleaned_data
              ip = cleaned_data['ip']
              source_name = cleaned_data['source_name']
              source_reference = cleaned_data['source_reference']
              source_method = cleaned_data['source_method']
              source_tlp= cleaned_data['source_tlp']
              campaign = cleaned_data['campaign']
              confidence = cleaned_data['confidence']
              ip_type = cleaned_data['ip_type']
              add_indicator = False
              if cleaned_data.get('add_indicator'):
                  add_indicator = True
              indicator_reference = cleaned_data.get('indicator_reference')
              bucket_list = cleaned_data.get(form_consts.Common.BUCKET_LIST_VARIABLE_NAME)
              ticket = cleaned_data.get(form_consts.Common.TICKET_VARIABLE_NAME)
              related_id = cleaned_data['related_id']
              related_type = cleaned_data['related_type']
              relationship_type = cleaned_data['relationship_type']
  
              result = ip_add_update(ip,
                                     ip_type,
                                     source=source_name,
                                     source_method=source_method,
                                     source_reference=source_reference,
                                     source_tlp=source_tlp,
                                     campaign=campaign,
                                     confidence=confidence,
                                     user=request.user,
                                     bucket_list=bucket_list,
                                     ticket=ticket,
                                     is_add_indicator=add_indicator,
                                     indicator_reference=indicator_reference,
                                     related_id=related_id,
                                     related_type=related_type,
                                     relationship_type=relationship_type)
              if 'message' in result:
                  if not isinstance(result['message'], list):
                      result['message'] = [result['message']]
              else:
                  result['message'] = []
                  message = ('<div>Success! Click here to view the new IP: <a '
                             'href="%s">%s</a></div>'
                             % (reverse('crits-ips-views-ip_detail',
                                        args=[ip]),
                                ip))
                  result['message'].insert(0, message)
              return HttpResponse(json.dumps(result,
                                             default=json_handler),
                                  content_type="application/json")
  
          return HttpResponse(json.dumps({'success': False,
                                          'form':form.as_table()}),
                              content_type="application/json")
      return render(request, "error.html", {'error': 'Expected AJAX/POST'})
function_tokens: def add_update_ip ( request , method ) : if request . method == "POST" and request . is_ajax ( ) : request . user . _setup ( ) data = request . POST form = AddIPForm ( request . user , None , data ) if form . is_valid ( ) : cleaned_data = form . cleaned_data ip = cleaned_data [ 'ip' ] source_name = cleaned_data [ 'source_name' ] source_reference = cleaned_data [ 'source_reference' ] source_method = cleaned_data [ 'source_method' ] source_tlp = cleaned_data [ 'source_tlp' ] campaign = cleaned_data [ 'campaign' ] confidence = cleaned_data [ 'confidence' ] ip_type = cleaned_data [ 'ip_type' ] add_indicator = False if cleaned_data . get ( 'add_indicator' ) : add_indicator = True indicator_reference = cleaned_data . get ( 'indicator_reference' ) bucket_list = cleaned_data . get ( form_consts . Common . BUCKET_LIST_VARIABLE_NAME ) ticket = cleaned_data . get ( form_consts . Common . TICKET_VARIABLE_NAME ) related_id = cleaned_data [ 'related_id' ] related_type = cleaned_data [ 'related_type' ] relationship_type = cleaned_data [ 'relationship_type' ] result = ip_add_update ( ip , ip_type , source = source_name , source_method = source_method , source_reference = source_reference , source_tlp = source_tlp , campaign = campaign , confidence = confidence , user = request . user , bucket_list = bucket_list , ticket = ticket , is_add_indicator = add_indicator , indicator_reference = indicator_reference , related_id = related_id , related_type = related_type , relationship_type = relationship_type ) if 'message' in result : if not isinstance ( result [ 'message' ] , list ) : result [ 'message' ] = [ result [ 'message' ] ] else : result [ 'message' ] = [ ] message = ( '<div>Success! Click here to view the new IP: <a ' 'href="%s">%s</a></div>' % ( reverse ( 'crits-ips-views-ip_detail' , args = [ ip ] ) , ip ) ) result [ 'message' ] . insert ( 0 , message ) return HttpResponse ( json . dumps ( result , default = json_handler ) , content_type = "application/json" ) return HttpResponse ( json . dumps ( { 'success' : False , 'form' : form . as_table ( ) } ) , content_type = "application/json" ) return render ( request , "error.html" , { 'error' : 'Expected AJAX/POST' } )