def create_photosize(name, width=0, height=0, crop=False, pre_cache=False, increment_count=False): try: size = PhotoSize.objects.get(name=name) exists = True except PhotoSize.DoesNotExist: size = PhotoSize(name=name) exists = False if exists: msg = 'A "%s" photo size already exists. Do you want to replace it? (yes, no):' % name if not get_response(msg, lambda inp: inp == 'yes', False): return print '\nWe will now define the "%s" photo size:\n' % size w = get_response('Width (in pixels):', lambda inp: int(inp), width) h = get_response('Height (in pixels):', lambda inp: int(inp), height) c = get_response('Crop to fit? (yes, no):', lambda inp: inp == 'yes', crop) p = get_response('Pre-cache? (yes, no):', lambda inp: inp == 'yes', pre_cache) i = get_response('Increment count? (yes, no):', lambda inp: inp == 'yes', increment_count) size.width = w size.height = h size.crop = c size.pre_cache = p size.increment_count = i size.save() print '\nA "%s" photo size has been created.\n' % name return size
class PhotologueBaseTest(TestCase): def setUp(self): self.s = PhotoSize(name='testPhotoSize', width=100, height=100) self.s.save() self.pl = _create_new_photo(name='Landscape', slug='landscape') def tearDown(self): self.pl.delete() self.s.delete()
class PhotologueBaseTest(TestCase): def setUp(self): self.s = PhotoSize(name='test', width=100, height=100) self.s.save() self.pl = _create_new_photo(name='Landscape', slug='landscape') def tearDown(self): path = self.pl.image.path self.pl.delete() os.remove(path) self.failIf(os.path.isfile(path)) self.s.delete()
def create_photosize_by_set(name, width=0, height=0, crop=False, pre_cache=False, increment_count=False): try: size = PhotoSize.objects.get(name=name) print 'photo size "%s" is already exist.' % name except PhotoSize.DoesNotExist: size = PhotoSize(name=name) print 'We will now define the "%s" photo size:' % size size.width = width size.height = height size.crop = crop size.pre_cache = pre_cache size.increment_count = increment_count size.save() print 'A "%s" photo size has been created.\n' % name return size
class PLTest(TestCase): """ Base TestCase class """ def setUp(self): self.s = PhotoSize(name='test', width=100, height=100) self.s.save() self.pl = TestPhoto(name='landscape') self.pl.image.save(os.path.basename(LANDSCAPE_IMAGE_PATH), ContentFile(open(LANDSCAPE_IMAGE_PATH, 'rb').read())) self.pl.save() def tearDown(self): path = self.pl.image.path self.pl.delete() self.failIf(os.path.isfile(path)) self.s.delete()
class PLTest(TestCase): """ Base TestCase class """ def setUp(self): self.s = PhotoSize(name='test', width=100, height=100) self.s.save() self.pl = TestPhoto(name='landscape') self.pl.image.save( os.path.basename(LANDSCAPE_IMAGE_PATH), ContentFile(open(LANDSCAPE_IMAGE_PATH, 'rb').read())) self.pl.save() def tearDown(self): path = self.pl.image.path self.pl.delete() self.failIf(os.path.isfile(path)) self.s.delete()
from django.conf import settings from whoosh import store, fields from whoosh.filedb.filestore import FileStorage from whoosh import index from os import environ import os environ["DJANGO_SETTINGS_MODULE"] = "settings" from settings import * from photologue.models import PhotoSize userSmallThumb = PhotoSize(name="userthumb", width=77, height=77, crop=True, pre_cache=False) userSmallThumb.save() slide = PhotoSize(name="slide", width=500, height=250, crop=True, pre_cache=False) slide.save() thumbnail = PhotoSize(name="thumbnail", width=75, height=75, pre_cache=True) thumbnail.save() display = PhotoSize(name="display", width=500, height=240, pre_cache=False) display.save()
}, 'settingsthumb' : { 'width': 50, 'height': 50, 'crop': True }, 'housesidebar' : { 'width': 160, 'height': 160, 'crop': True } } # now build 'em print "Setting up thumbnail sizes..." for ps, psettings in LIVEWITH_PHOTO_SIZES.iteritems(): thisps = LIVEWITH_PHOTO_SIZES[ps] try: t = PhotoSize.objects.get(name=ps) print "Image crop size %s already exists, skipping." % ps except PhotoSize.DoesNotExist: # create chat_sized_thumbnail p = PhotoSize(name=ps, width = psettings['width'], height = psettings['height'], crop = psettings['crop'] ) p.save() print "Setting up Utility settings..." print "Setup complete."