def reorder_plugins(placeholder, parent_id, language, order):
 plugins = CMSPlugin.objects.filter(parent=parent_id, placeholder=placeholder, language=language).order_by('position')
 order = list(order)
 if order:
  plugins = plugins.filter(pk__in=order)
  for plugin in plugins.iterator():
   position = order.index(plugin.pk)
   plugin.update(position=position)
 else:
  for (position, plugin) in enumerate(plugins.iterator()):
   plugin.update(position=position)
 return plugins

def reorder_plugins ( placeholder , parent_id , language , order ) : plugins = CMSPlugin . objects . filter ( parent = parent_id , placeholder = placeholder , language = language ) . order_by ( 'position' ) order = list ( order ) if order : plugins = plugins . filter ( pk__in = order ) for plugin in plugins . iterator ( ) : position = order . index ( plugin . pk ) plugin . update ( position = position ) else : for ( position , plugin ) in enumerate ( plugins . iterator ( ) ) : plugin . update ( position = position ) return plugins
reorder the plugins according the order parameter .