Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 7b79971
Showing
17 changed files
with
203 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
tests/MEDIA/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Copyright (c) 2012, Caffeinehit Ltd. | ||
Copyright (c) 2012, Alen Mujezinovic <alen@caffeinehit.com> | ||
|
||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: | ||
|
||
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. | ||
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. | ||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from django.db import models | ||
from django.core.serializers.json import DjangoJSONEncoder | ||
from django.db.models.fields.files import ImageField, ImageFieldFile | ||
|
||
import json | ||
import jsonfield | ||
|
||
class Crop(object): | ||
pass | ||
|
||
class CropsDescriptor(object): | ||
def __init__(self, data): | ||
self.data = data | ||
self._post_init() | ||
|
||
def create(self, name, (x, y, width, height)): | ||
self._create_accessor(name, 'asdf') | ||
self.data[name] = 'asdf' | ||
|
||
def _post_init(self): | ||
for (key, value) in self.data.iteritems(): | ||
self._create_accessor(key, value) | ||
|
||
def _create_accessor(self, name, value): | ||
setattr(self, name, Crop()) | ||
|
||
|
||
class CropsField(jsonfield.JSONField): | ||
__metaclass__ = models.SubfieldBase | ||
|
||
def __init__(self, image_field, *args, **kwargs): | ||
self.image_field = image_field | ||
super(CropsField, self).__init__(*args, **kwargs) | ||
|
||
def to_python(self, value): | ||
data = super(CropsField, self).to_python(value) | ||
return CropsDescriptor(data) | ||
|
||
def get_db_prep_value(self, value, connection, prepared=False): | ||
return super(CropsField, self).get_db_prep_value(value.data, connection, prepared = False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.db import models | ||
|
||
# Create your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
""" | ||
This file demonstrates writing tests using the unittest module. These will pass | ||
when you run "manage.py test". | ||
Replace this with more appropriate tests for your application. | ||
""" | ||
|
||
from django.test import TestCase | ||
|
||
|
||
class SimpleTest(TestCase): | ||
def test_basic_addition(self): | ||
""" | ||
Tests that 1 + 1 always equals 2. | ||
""" | ||
self.assertEqual(1 + 1, 2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Create your views here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
nose | ||
sphinx | ||
pillow |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from setuptools import setup, find_packages | ||
|
||
|
||
with open('README.rst') as f: | ||
readme = f.read() | ||
|
||
with open('LICENSE') as f: | ||
license = f.read() | ||
|
||
with open('requirements.txt') as f: | ||
install_requires = f.read().split('\n') | ||
|
||
setup( | ||
name='django-croppy', | ||
version='0.0.1', | ||
description='Image library for creating user-croppable media', | ||
long_description=readme, | ||
author='Alen Mujezinovic', | ||
author_email='me@kennethreitz.com', | ||
url='https://github.com/caffeinehit/django-ilib', | ||
license=license, | ||
install_requires=install_requires, | ||
packages=find_packages(exclude=('tests', 'docs')) | ||
) | ||
|
Empty file.
Empty file.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from django.db import models | ||
from croppy.fields import CropsField | ||
|
||
# Create your models here. | ||
|
||
|
||
class Image(models.Model): | ||
image = models.ImageField(upload_to = 'images') | ||
crops = CropsField('image') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
""" | ||
This file demonstrates writing tests using the unittest module. These will pass | ||
when you run "manage.py test". | ||
Replace this with more appropriate tests for your application. | ||
""" | ||
|
||
from django.core.files import File | ||
from django.test import TestCase | ||
|
||
from .models import * | ||
|
||
import os | ||
|
||
def get_image(filename): | ||
path = os.path.join( | ||
os.path.dirname(__file__), | ||
'assets', | ||
filename) | ||
|
||
image = Image() | ||
|
||
with open(path) as f: | ||
image.image.save(filename, File(f)) | ||
|
||
return image | ||
|
||
|
||
|
||
class SimpleTest(TestCase): | ||
def test_basic_addition(self): | ||
""" | ||
Tests that 1 + 1 always equals 2. | ||
""" | ||
self.assertEqual(1 + 1, 2) | ||
|
||
class CropsFieldTest(TestCase): | ||
def setUp(self): | ||
self.image = get_image('test.tiff') | ||
self.crop = (0,0,100,100) | ||
|
||
def test_save_image(self): | ||
image = Image.objects.get(id = self.image.id) | ||
self.assertTrue(os.path.isfile(self.image.image.path)) | ||
|
||
def test_create_crop(self): | ||
self.image.crops.create('square', self.crop) | ||
self.assertTrue(self.image.crops.square) | ||
#self.assertTrue(os.path.isfile(self.image.crops.square.path)) | ||
|
||
# def test_delete_crop(self): | ||
# self.test_create_crop() | ||
# path = self.image.crops.square.path | ||
# self.image.crops.square.delete() | ||
# self.assertRaises(AttributeError, lambda: self.image.crops.square.path) | ||
# self.assertFalse(os.path.isfile(path)) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Create your views here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import os | ||
|
||
DEBUG = True | ||
TEMPLATE_DEBUG = DEBUG | ||
|
||
ADMINS = ( | ||
('Tester', 'test@example.com'), | ||
) | ||
|
||
MEDIA_ROOT = os.path.join( | ||
os.path.dirname(__file__), | ||
'MEDIA') | ||
|
||
DATABASES = { | ||
'default': { | ||
'ENGINE': 'django.db.backends.sqlite3', | ||
'NAME': 'test.db', | ||
}, | ||
} | ||
|
||
INSTALLED_APPS = [ | ||
'django.contrib.auth', | ||
'django.contrib.contenttypes', | ||
'croppy', | ||
'tests.app', | ||
] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/bash | ||
|
||
export PYTHONPATH=$PWD/../:$PYTHONPATH | ||
|
||
django-admin.py test app --settings tests.settings |