parameters: (request, method, obj_type, obj_id)
return_statement: return HttpResponse({})
docstring: Add/Update a source for a top-level object. Should be an AJAX POST.
  
      :param request: Django request.
      :type request: :class:`django.http.HttpRequest`
      :param method: Whether this is an "add" or "update".
      :type method: str
      :param obj_type: The type of top-level object.
      :type obj_type: str
      :param obj_id: The ObjectId to search for.
      :type obj_id: str
      :returns: :class:`django.http.HttpResponse`
docstring_summary: Add/Update a source for a top-level object. Should be an AJAX POST.
docstring_tokens: Add / Update a source for a top - level object . Should be an AJAX POST .
function: def add_update_source(request, method, obj_type, obj_id):
      """
      Add/Update a source for a top-level object. Should be an AJAX POST.
  
      :param request: Django request.
      :type request: :class:`django.http.HttpRequest`
      :param method: Whether this is an "add" or "update".
      :type method: str
      :param obj_type: The type of top-level object.
      :type obj_type: str
      :param obj_id: The ObjectId to search for.
      :type obj_id: str
      :returns: :class:`django.http.HttpResponse`
      """
  
      if request.method == "POST" and request.is_ajax():
          form = SourceForm(request.user, request.POST)
          if form.is_valid():
              data = form.cleaned_data
              user = request.user
              acl = get_acl_object(obj_type)
              # check to see that this user can already see the object
              if (data['name'] in user_sources(user)):
                  if method == "add":
                      date = datetime.datetime.now()
                      if user.has_access_to(acl.SOURCES_ADD):
                          result = source_add_update(obj_type,
                                                     obj_id,
                                                     method,
                                                     data['name'],
                                                     method=data['method'],
                                                     reference=data['reference'],
                                                     tlp=data['tlp'],
                                                     date=date,
                                                     user=user.username)
                      else:
                          result = {"success":False,
                                    "message":"User does not have permission to add sources to object."}
                  else:
                      date = datetime.datetime.strptime(data['date'],
                                                        settings.PY_DATETIME_FORMAT)
                      if user.has_access_to(acl.SOURCES_EDIT):
                          result = source_add_update(obj_type,
                                                     obj_id,
                                                     method,
                                                     data['name'],
                                                     method=data['method'],
                                                     reference=data['reference'],
                                                     tlp=data['tlp'],
                                                     date=date,
                                                     user=user.username)
                      else:
                          result = {"success":False,
                                    "message":"User does not have permission to edit sources."}
  
                  if 'object' in result:
                      if method == "add":
                          result['header'] = result['object'].name
                          result['data_field'] = 'name'
                          result['html'] = render_to_string('sources_header_widget.html',
                                                            {'source': result['object'],
                                                             'obj_type': obj_type,
                                                             'obj_id': obj_id},
                                                            request=request)
                      else:
                          result['html'] = render_to_string('sources_row_widget.html',
                                                            {'source': result['object'],
                                                             'instance': result['instance'],
                                                             'obj_type': obj_type,
                                                             'obj_id': obj_id},
                                                            request=request)
                  return HttpResponse(json.dumps(result,
                                                 default=json_handler),
                                      content_type="application/json")
              else:
                  return HttpResponse(json.dumps({'success': False,
                                                  'form': form.as_table()}),
                                      content_type="application/json")
          else:
              return HttpResponse(json.dumps({'success': False,
                                              'form':form.as_table()}),
                                  content_type="application/json")
      return HttpResponse({})
function_tokens: def add_update_source ( request , method , obj_type , obj_id ) : if request . method == "POST" and request . is_ajax ( ) : form = SourceForm ( request . user , request . POST ) if form . is_valid ( ) : data = form . cleaned_data user = request . user acl = get_acl_object ( obj_type ) # check to see that this user can already see the object if ( data [ 'name' ] in user_sources ( user ) ) : if method == "add" : date = datetime . datetime . now ( ) if user . has_access_to ( acl . SOURCES_ADD ) : result = source_add_update ( obj_type , obj_id , method , data [ 'name' ] , method = data [ 'method' ] , reference = data [ 'reference' ] , tlp = data [ 'tlp' ] , date = date , user = user . username ) else : result = { "success" : False , "message" : "User does not have permission to add sources to object." } else : date = datetime . datetime . strptime ( data [ 'date' ] , settings . PY_DATETIME_FORMAT ) if user . has_access_to ( acl . SOURCES_EDIT ) : result = source_add_update ( obj_type , obj_id , method , data [ 'name' ] , method = data [ 'method' ] , reference = data [ 'reference' ] , tlp = data [ 'tlp' ] , date = date , user = user . username ) else : result = { "success" : False , "message" : "User does not have permission to edit sources." } if 'object' in result : if method == "add" : result [ 'header' ] = result [ 'object' ] . name result [ 'data_field' ] = 'name' result [ 'html' ] = render_to_string ( 'sources_header_widget.html' , { 'source' : result [ 'object' ] , 'obj_type' : obj_type , 'obj_id' : obj_id } , request = request ) else : result [ 'html' ] = render_to_string ( 'sources_row_widget.html' , { 'source' : result [ 'object' ] , 'instance' : result [ 'instance' ] , 'obj_type' : obj_type , 'obj_id' : obj_id } , request = request ) return HttpResponse ( json . dumps ( result , default = json_handler ) , content_type = "application/json" ) else : return HttpResponse ( json . dumps ( { 'success' : False , 'form' : form . as_table ( ) } ) , content_type = "application/json" ) else : return HttpResponse ( json . dumps ( { 'success' : False , 'form' : form . as_table ( ) } ) , content_type = "application/json" ) return HttpResponse ( { } )