<s> from django . db import models <EOL> from django . db . models . signals import post_save <EOL> import mimetypes <EOL> import wellknown <EOL> class Resource ( models . Model ) : <EOL> path = models . CharField ( max_length = <NUM_LIT> ) <EOL> content = models . TextField ( blank = True ) <EOL> content_type = models . CharField ( max_length = <NUM_LIT> , blank = True ) <EOL> class Meta : <EOL> ordering = ( '<STR_LIT:path>' , ) <EOL> def __unicode__ ( self ) : <EOL> return self . path <EOL> def save ( self , ** kwargs ) : <EOL> self . path = self . path . strip ( '<STR_LIT:/>' ) <EOL> if not self . content_type : <EOL> self . content_type = mimetypes . guess_type ( self . path ) [ <NUM_LIT:0> ] or '<STR_LIT>' <EOL> super ( Resource , self ) . save ( ** kwargs ) <EOL> def save_handler ( sender , ** kwargs ) : <EOL> reg = kwargs [ '<STR_LIT>' ] <EOL> wellknown . register ( <EOL> reg . path , <EOL> content = reg . content , <EOL> content_type = reg . content_type , <EOL> update = True <EOL> ) <EOL> post_save . connect ( save_handler , sender = Resource ) </s>
