<s> import os <EOL> from PIL import Image as PImage <EOL> from django . conf import settings <EOL> from os . path import join as pjoin , basename <EOL> from tempfile import NamedTemporaryFile <EOL> from django . db . models import * <EOL> from django . core . files import File <EOL> from shared . utils import * <EOL> link = "<STR_LIT>" <EOL> imgtag = "<STR_LIT>" <EOL> class Group ( BaseModel ) : <EOL> title = CharField ( max_length = <NUM_LIT> ) <EOL> description = TextField ( blank = True , null = True ) <EOL> link = URLField ( blank = True , null = True ) <EOL> hidden = BooleanField ( default = True ) <EOL> def __unicode__ ( self ) : <EOL> return self . title <EOL> def get_absolute_url ( self , show = "<STR_LIT>" ) : <EOL> return reverse2 ( "<STR_LIT>" , dpk = self . pk , show = show ) <EOL> def image_links ( self ) : <EOL> lst = [ img . image . name for img in self . images . all ( ) ] <EOL> lst = [ link % ( settings . MEDIA_URL + img , basename ( img ) ) for img in lst ] <EOL> return "<STR_LIT:U+002CU+0020>" . join ( lst ) <EOL> image_links . allow_tags = True <EOL> class Image ( BaseModel ) : <EOL> title = CharField ( max_length = <NUM_LIT> , blank = True , null = True ) <EOL> description = TextField ( blank = True , null = True ) <EOL> image = ImageField ( upload_to = "<STR_LIT>" ) <EOL> thumbnail1 = ImageField ( upload_to = "<STR_LIT>" , blank = True , null = True ) <EOL> thumbnail2 = ImageField ( upload_to = "<STR_LIT>" , blank = True , null = True ) <EOL> width = IntegerField ( blank = True , null = True ) <EOL> height = IntegerField ( blank = True , null = True ) <EOL> hidden = BooleanField ( default = True ) <EOL> group = ForeignKey ( Group , related_name = "<STR_LIT>" , blank = True ) <EOL> created = DateTimeField ( auto_now_add = True ) <EOL> class Meta : <EOL> ordering = [ "<STR_LIT>" ] <EOL> def __unicode__ ( self ) : <EOL> return self . image . name <EOL> def get_absolute_url ( self ) : <EOL> return reverse2 ( "<STR_LIT:image>" , mfpk = self . pk ) <EOL> def save ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> super ( Image , self ) . save ( * args , ** kwargs ) <EOL> img = PImage . open ( pjoin ( settings . MEDIA_ROOT , self . image . name ) ) <EOL> self . width , self . height = img . size <EOL> self . save_thumbnail ( img , <NUM_LIT:1> , ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> self . save_thumbnail ( img , <NUM_LIT:2> , ( <NUM_LIT:64> , <NUM_LIT:64> ) ) <EOL> super ( Image , self ) . save ( * args , ** kwargs ) <EOL> def save_thumbnail ( self , img , num , size ) : <EOL> fn , ext = os . path . splitext ( self . image . name ) <EOL> img . thumbnail ( size , PImage . ANTIALIAS ) <EOL> thumb_fn = fn + "<STR_LIT>" + str ( num ) + ext <EOL> tf = NamedTemporaryFile ( ) <EOL> img . convert ( "<STR_LIT>" ) . save ( tf . name , "<STR_LIT>" ) <EOL> thumbnail = getattr ( self , "<STR_LIT>" % num ) <EOL> thumbnail . save ( thumb_fn , File ( open ( tf . name ) ) , save = False ) <EOL> tf . close ( ) <EOL> def size ( self ) : <EOL> return "<STR_LIT>" % ( self . width , self . height ) <EOL> def thumbnail1_url ( self ) : <EOL> return settings . MEDIA_URL + self . thumbnail1 . name <EOL> def thumbnail2_url ( self ) : <EOL> return settings . MEDIA_URL + self . thumbnail2 . name <EOL> def image_url ( self ) : <EOL> return settings . MEDIA_URL + self . image . name </s>
