parameters: (request, message, bookid, version)
return_statement: return {"result": True}
docstring: Reorders the TOC.
  
      Creates Book history record. Sends "chapters_changed" message to the channel.
  
      Input:
       - chapters
       - hold
  
      @type request: C{django.http.HttpRequest}
      @param request: Client Request object
      @type message: C{dict}
      @param message: Message object
      @type bookid: C{string}
      @param bookid: Unique Book id
      @type version: C{string}
      @param version: Book version
docstring_summary: Reorders the TOC.
docstring_tokens: Reorders the TOC .
function: def remote_chapters_changed(request, message, bookid, version):
      """
      Reorders the TOC.
  
      Creates Book history record. Sends "chapters_changed" message to the channel.
  
      Input:
       - chapters
       - hold
  
      @type request: C{django.http.HttpRequest}
      @param request: Client Request object
      @type message: C{dict}
      @param message: Message object
      @type bookid: C{string}
      @param bookid: Unique Book id
      @type version: C{string}
      @param version: Book version
      """
  
      book, book_version, book_security = get_book(request, bookid, version)
  
      if not book_security.has_perm('edit.reorder_toc'):
          raise PermissionDenied
  
      lst = [(chap['item_id'], chap['parent_id']) for chap in message["chapters"]]
      lstHold = []
  
      weight = len(lst)
  
      logBookHistory(
          book=book,
          version=book_version,
          user=request.user,
          kind="chapter_reorder"
      )
  
      for chap in lst:
          try:
              toc_item = models.BookToc.objects.get(id__exact=int(chap[0]), version=book_version)
              toc_item.weight = weight
  
              # check if toc item has parent
              parent = None
              if chap[1] != 'root':
                  try:
                      parent = models.BookToc.objects.get(
                          id__exact=int(chap[1]),
                          version=book_version
                      )
                  except Exception, e:
                      pass
  
              toc_item.parent = parent
              toc_item.save()
          except Exception, e:
              print e
  
          weight -= 1
  
      if message["kind"] == "remove":
          if type(message["chapter_id"]) == type(u' ') and message["chapter_id"][0] == 's':
              m = models.BookToc.objects.get(id__exact=message["chapter_id"][1:], version=book_version)
              m.delete()
          else:
              m = models.BookToc.objects.get(chapter__id__exact=int(message["chapter_id"]), version=book_version)
              m.delete()
  
  #        addMessageToChannel(request, "/chat/%s/%s/" % (projectid, bookid), {"command": "message_info", "from": request.user.username, "message": 'User %s has rearranged chapters.' % request.user.username})
  
      sputnik.addMessageToChannel(
          request, "/booktype/book/%s/%s/" % (bookid, version), {
              "command": "chapters_changed",
              "ids": lst,
              "hold_ids": lstHold,
              "kind": message["kind"],
              "chapter_id": message["chapter_id"]
          }
      )
  
      send_notification(request, bookid, version, "notification_toc_order_was_changed")
  
      # TODO
      # this should be changed, to check for errors
  
      return {"result": True}
function_tokens: def remote_chapters_changed ( request , message , bookid , version ) : book , book_version , book_security = get_book ( request , bookid , version ) if not book_security . has_perm ( 'edit.reorder_toc' ) : raise PermissionDenied lst = [ ( chap [ 'item_id' ] , chap [ 'parent_id' ] ) for chap in message [ "chapters" ] ] lstHold = [ ] weight = len ( lst ) logBookHistory ( book = book , version = book_version , user = request . user , kind = "chapter_reorder" ) for chap in lst : try : toc_item = models . BookToc . objects . get ( id__exact = int ( chap [ 0 ] ) , version = book_version ) toc_item . weight = weight # check if toc item has parent parent = None if chap [ 1 ] != 'root' : try : parent = models . BookToc . objects . get ( id__exact = int ( chap [ 1 ] ) , version = book_version ) except Exception , e : pass toc_item . parent = parent toc_item . save ( ) except Exception , e : print e weight -= 1 if message [ "kind" ] == "remove" : if type ( message [ "chapter_id" ] ) == type ( u' ' ) and message [ "chapter_id" ] [ 0 ] == 's' : m = models . BookToc . objects . get ( id__exact = message [ "chapter_id" ] [ 1 : ] , version = book_version ) m . delete ( ) else : m = models . BookToc . objects . get ( chapter__id__exact = int ( message [ "chapter_id" ] ) , version = book_version ) m . delete ( ) #        addMessageToChannel(request, "/chat/%s/%s/" % (projectid, bookid), {"command": "message_info", "from": request.user.username, "message": 'User %s has rearranged chapters.' % request.user.username}) sputnik . addMessageToChannel ( request , "/booktype/book/%s/%s/" % ( bookid , version ) , { "command" : "chapters_changed" , "ids" : lst , "hold_ids" : lstHold , "kind" : message [ "kind" ] , "chapter_id" : message [ "chapter_id" ] } ) send_notification ( request , bookid , version , "notification_toc_order_was_changed" ) # TODO # this should be changed, to check for errors return { "result" : True }