コード例 #1
0
ファイル: tests.py プロジェクト: bltravis/django-imageresize
class TemplatesRepositoryTest(unittest.TestCase):
    
    def setUp(self):
        self.templateRepo = TemplateRepository()
        
    def test_get_template_returns_expected_value(self):
        self.assertEquals('arg1  arg2', self.templateRepo.getTemplate('TEST'))
コード例 #2
0
ファイル: tests.py プロジェクト: bltravis/django-imageresize
 def setUp(self):
     self.templateRepo = TemplateRepository()
コード例 #3
0
class TemplatesRepositoryTest(unittest.TestCase):
    def setUp(self):
        self.templateRepo = TemplateRepository()

    def test_get_template_returns_expected_value(self):
        self.assertEquals('arg1  arg2', self.templateRepo.getTemplate('TEST'))
コード例 #4
0
 def setUp(self):
     self.templateRepo = TemplateRepository()
コード例 #5
0
from django.http import HttpResponse, Http404
from imageservice.template_repository import TemplateRepository
import imagemagick
from django.conf import settings

templatesRepo = TemplateRepository()

def execute_template(request, file_name_without_extension, template_name, file_extension):
    try:
        command  = templatesRepo.getTemplate(template_name)
    except Exception, e:
        raise Http404(e)
    
    source_file = "%s/%s" % (settings.MEDIA_ROOT, file_name_without_extension)
    target_file = "%s/%s.%s%s" % (settings.MEDIA_CACHE_ROOT, file_name_without_extension, template_name, file_extension)   
    
    try:
        imagemagick.execute(command, source_file, target_file)    
    except Exception, e:
        raise Http404(e)
        
    return render_image_to_response(target_file)
 
    
def resize_image(request, file_name_without_extension, width, height, file_extension):
    width = int(width)
    height = int(height)
    
    if height > settings.RESIZE_MAX_HEIGHT or width > settings.RESIZE_MAX_WIDTH:
        raise Http404