<s> from datetime import date <EOL> import os <EOL> import threading <EOL> from cms . models import CMSPlugin <EOL> from cms . utils import get_cms_setting <EOL> from django . db import models <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from inline_ordering . models import Orderable <EOL> from django . utils . deconstruct import deconstructible <EOL> import utils <EOL> localdata = threading . local ( ) <EOL> localdata . TEMPLATE_CHOICES = utils . autodiscover_templates ( ) <EOL> TEMPLATE_CHOICES = localdata . TEMPLATE_CHOICES <EOL> @ deconstructible <EOL> class UploadPath ( object ) : <EOL> def __init__ ( self , sub_path ) : <EOL> self . path = sub_path <EOL> def __call__ ( self , instance , filename ) : <EOL> return "<STR_LIT>" % ( instance . generic_title , connection . schema_name , filename ) <EOL> get_upload_path = UploadPath ( '<STR_LIT>' ) <EOL> class GalleryPlugin ( CMSPlugin ) : <EOL> def copy_relations ( self , oldinstance ) : <EOL> for img in oldinstance . image_set . all ( ) : <EOL> new_img = Image ( ) <EOL> new_img . gallery = self <EOL> new_img . src = img . src <EOL> new_img . src_height = img . src_height <EOL> new_img . src_width = img . src_width <EOL> new_img . title = img . title <EOL> new_img . alt = img . alt <EOL> new_img . save ( ) <EOL> template = models . CharField ( max_length = <NUM_LIT:255> , <EOL> choices = TEMPLATE_CHOICES , <EOL> default = TEMPLATE_CHOICES [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , <EOL> editable = len ( TEMPLATE_CHOICES ) > <NUM_LIT:1> ) <EOL> def __unicode__ ( self ) : <EOL> return _ ( u'<STR_LIT>' ) % { '<STR_LIT:count>' : self . image_set . count ( ) } <EOL> class Image ( Orderable ) : <EOL> def get_media_path ( self , filename ) : <EOL> pages = self . gallery . placeholder . page_set . all ( ) <EOL> if pages . count ( ) : <EOL> return pages [ <NUM_LIT:0> ] . get_media_path ( filename ) <EOL> else : <EOL> today = date . today ( ) <EOL> return os . path . join ( get_cms_setting ( '<STR_LIT>' ) , <EOL> str ( today . year ) , str ( today . month ) , str ( today . day ) , filename ) <EOL> gallery = models . ForeignKey ( GalleryPlugin , verbose_name = _ ( "<STR_LIT>" ) ) <EOL> src = models . ImageField ( _ ( "<STR_LIT>" ) , upload_to = get_upload_path , <EOL> height_field = '<STR_LIT>' , <EOL> width_field = '<STR_LIT>' ) <EOL> src_height = models . PositiveSmallIntegerField ( _ ( "<STR_LIT>" ) , editable = False , null = True ) <EOL> src_width = models . PositiveSmallIntegerField ( _ ( "<STR_LIT>" ) , editable = False , null = True ) <EOL> title = models . CharField ( _ ( "<STR_LIT>" ) , max_length = <NUM_LIT:255> , blank = True ) <EOL> alt = models . TextField ( _ ( "<STR_LIT>" ) , blank = True ) <EOL> def __unicode__ ( self ) : <EOL> return self . title or self . alt or str ( self . pk ) </s>
