<s> from __future__ import absolute_import , with_statement <EOL> __all__ = [ '<STR_LIT>' ] <EOL> from treeio . core . api . utils import rc <EOL> from piston3 . handler import BaseHandler <EOL> from treeio . core . models import UpdateRecord <EOL> from treeio . news . forms import UpdateRecordForm <EOL> from treeio . news . views import _get_filter_query <EOL> class UpdateRecordHandler ( BaseHandler ) : <EOL> "<STR_LIT>" <EOL> model = UpdateRecord <EOL> form = UpdateRecordForm <EOL> allowed_methods = ( '<STR_LIT:GET>' , '<STR_LIT>' ) <EOL> fields = ( '<STR_LIT:id>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> @ classmethod <EOL> def resource_uri ( cls , obj = None ) : <EOL> object_id = "<STR_LIT:id>" <EOL> if obj is not None : <EOL> object_id = obj . id <EOL> return ( '<STR_LIT>' , [ object_id ] ) <EOL> def read ( self , request , record_id = None , * args , ** kwargs ) : <EOL> "<STR_LIT>" <EOL> profile = request . user . profile <EOL> query = _get_filter_query ( profile , filters = request . GET ) <EOL> try : <EOL> if record_id : <EOL> return UpdateRecord . objects . filter ( query ) . get ( id = record_id ) <EOL> else : <EOL> return UpdateRecord . objects . filter ( query ) . distinct ( ) <EOL> except self . model . DoesNotExist : <EOL> return rc . NOT_FOUND <EOL> except self . model . MultipleObjectsReturned : <EOL> return rc . BAD_REQUEST <EOL> def delete ( self , request , record_id = None , * args , ** kwargs ) : <EOL> "<STR_LIT>" <EOL> if not record_id : <EOL> return rc . BAD_REQUEST <EOL> try : <EOL> inst = self . model . objects . get ( pk = record_id ) <EOL> inst . delete ( ) <EOL> return rc . DELETED <EOL> except self . model . MultipleObjectsReturned : <EOL> return rc . DUPLICATE_ENTRY <EOL> except self . model . DoesNotExist : <EOL> return rc . NOT_HERE </s>
