<s> from django . conf import settings <EOL> from django . template import RequestContext <EOL> from django . template . loader import render_to_string <EOL> from djangorestframework . response import Response , ErrorResponse <EOL> from djangorestframework import status <EOL> from ionyweb . website . rendering import HTMLRendering <EOL> from ionyweb . administration . views import IsAdminView <EOL> from ionyweb . administration . utils import MESSAGES <EOL> from models import Link <EOL> class EntriesListOrderView ( IsAdminView ) : <EOL> def get ( self , request , relation_id , plugin , action_pk = None ) : <EOL> content = render_to_string ( '<STR_LIT>' , <EOL> { '<STR_LIT>' : plugin , <EOL> '<STR_LIT>' : relation_id } , <EOL> context_instance = RequestContext ( request ) ) <EOL> response = Response ( status . HTTP_200_OK , { '<STR_LIT:html>' : content , } ) <EOL> return self . render ( response ) <EOL> def post ( self , request , relation_id , plugin , action_pk = None ) : <EOL> links_html_id = request . POST . getlist ( '<STR_LIT>' ) <EOL> if links_html_id : <EOL> order = <NUM_LIT:1> <EOL> for link_id in map ( lambda s : s . split ( '<STR_LIT:->' ) [ <NUM_LIT:1> ] , links_html_id ) : <EOL> try : <EOL> obj = Link . objects . get ( pk = link_id ) <EOL> if obj . plugin == plugin : <EOL> obj . order = order <EOL> obj . save ( ) <EOL> order += <NUM_LIT:1> <EOL> except Link . DoesNotExist : <EOL> pass <EOL> html = request . page . render_page ( request ) . content <EOL> if isinstance ( html , HTMLRendering ) : <EOL> html = html . content <EOL> response = Response ( status . HTTP_200_OK , { '<STR_LIT>' : MESSAGES . get ( '<STR_LIT>' , "<STR_LIT>" ) , <EOL> '<STR_LIT:html>' : html , <EOL> '<STR_LIT>' : placeholder_type , <EOL> '<STR_LIT>' : relation_id } ) <EOL> return self . render ( response ) <EOL> else : <EOL> raise ErrorResponse ( status . HTTP_400_BAD_REQUEST , <EOL> { '<STR_LIT>' : MESSAGES . get ( '<STR_LIT>' , "<STR_LIT>" ) } ) </s>
