<s> def save ( ) : <EOL> datatype = require_alphanumeric ( request . args [ <NUM_LIT:0> ] ) <EOL> lookup_id = require_alphanumeric ( request . vars . get ( '<STR_LIT:id>' ) ) <EOL> dm . link ( datatype , lookup_id ) <EOL> return dm . get ( datatype , lookup_id ) . json ( ) <EOL> def load ( ) : <EOL> datatype = require_alphanumeric ( request . args [ <NUM_LIT:0> ] ) <EOL> if len ( request . args ) > <NUM_LIT:1> and request . args [ <NUM_LIT:1> ] : <EOL> kw = require_alphanumeric ( request . args [ <NUM_LIT:1> ] ) <EOL> rec = boolean ( request . vars . get ( '<STR_LIT>' ) ) <EOL> if not rec : <EOL> return '<STR_LIT>' + dm . global_load ( datatype , [ kw ] ) . json ( ) + '<STR_LIT:}>' <EOL> else : <EOL> result = mongo . words . find ( { '<STR_LIT>' : kw } ) <EOL> if not result . count ( ) : <EOL> return '<STR_LIT>' <EOL> keys = result [ <NUM_LIT:0> ] [ '<STR_LIT>' ] . items ( ) <EOL> keys . sort ( key = lambda x : x [ <NUM_LIT:1> ] ) <EOL> keys . reverse ( ) <EOL> top = len ( keys ) / <NUM_LIT:4> <EOL> words = map ( lambda x : x [ <NUM_LIT:0> ] , keys [ <NUM_LIT:0> : top ] ) <EOL> return '<STR_LIT>' + dm . global_load ( datatype , words ) . json ( ) + '<STR_LIT:}>' <EOL> else : <EOL> return '<STR_LIT>' + dm . global_load ( datatype ) . json ( ) + '<STR_LIT:}>' <EOL> def unlink ( ) : <EOL> datatype = require_alphanumeric ( request . args [ <NUM_LIT:0> ] ) <EOL> lookup_id = require_alphanumeric ( request . vars . get ( '<STR_LIT:id>' ) ) <EOL> dm . unlink ( datatype , lookup_id ) <EOL> def tag ( ) : <EOL> datatype = require_alphanumeric ( request . args [ <NUM_LIT:0> ] ) <EOL> lookup_id = require_alphanumeric ( request . vars . get ( '<STR_LIT:id>' ) ) <EOL> kw = require_alphanumeric ( request . vars . get ( '<STR_LIT>' ) ) <EOL> dm . tag ( datatype , lookup_id , [ kw ] ) </s>
