def _document_lock(doc_id, username):
 locked_by = _document_lock_check(doc_id)
 if (locked_by == username):
  locked = False
 if locked_by:
  try:
   locked = (not (locked_by == username))
   locked_by = User.objects.get(username=locked_by)
  except User.DoesNotExist:
   locked = False
   locked_by = None
 else:
  locked_by = username
  locked = False
  _document_lock_steal(doc_id, username)
 return (locked, locked_by)

def _document_lock ( doc_id , username ) : locked_by = _document_lock_check ( doc_id ) if ( locked_by == username ) : locked = False if locked_by : try : locked = ( not ( locked_by == username ) ) locked_by = User . objects . get ( username = locked_by ) except User . DoesNotExist : locked = False locked_by = None else : locked_by = username locked = False _document_lock_steal ( doc_id , username ) return ( locked , locked_by )
if there is no lock .