Skip to content

Commit

Permalink
More test coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
jayvarner committed Feb 20, 2020
1 parent 56adc87 commit 4e715ca
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 95 deletions.
1 change: 0 additions & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
omit =
*tests.py
apps/cms/*
apps/users/*
apps/contrib/*
*migrations*
*__init__.py
Expand Down
29 changes: 3 additions & 26 deletions apps/iiif/kollections/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,24 @@
from import_export.admin import ImportExportModelAdmin
from import_export.widgets import ForeignKeyWidget, ManyToManyWidget
from apps.iiif.kollections.models import Collection
from apps.iiif.manifests.models import Manifest, Note
from apps.iiif.manifests.models import Manifest, Note

#class ManifestModelChoiceField(forms.ModelChoiceField):
# def label_from_instance(self, obj):
# """
# This method is used to convert objects into strings; it's used to
# generate the labels for the choices presented by this object. Subclasses
# can override this method to customize the display of the choices.
# """
# # Then return what you'd like to display
# return "%s " % (self.manifest.label)

#class MyForm(forms.ModelForm):
# collection = ManifestModelChoiceField(
# queryset=Manifest.objects.all()
# )
#
# class Meta:
# model = Manifest
# fields = ['label',]
#def formfield_for_manytomany(self, db_field, request, **kwargs):
# if db_field.name == 'Manifest_collections':
# return ManifestModelChoiceField(queryset=Manifest.collections.through.objects.all())
# return super().formfield_for_foreignkey(db_field, request, **kwargs)

class CollectionResource(resources.ModelResource):
class Meta:
model = Collection
fields = ('id', 'label','summary', 'pid', 'attribution', 'metadata', 'original', 'collection_image_title', 'collection_image_creator', 'collection_image_summary')

class ManifestInline(admin.TabularInline):
# form = MyForm
model = Manifest.collections.through
fields = ('manifest', 'manifest_pid')
# filter_horizontal = ('manifest',)
autocomplete_fields = ('manifest',)
readonly_fields = ('manifest_pid',)
verbose_name_plural = 'Manifests in this Collection'

# TODO: Test this
def manifest_pid(self, instance):
return instance.manifest.pid

manifest_pid.short_description = 'Manifest Local ID'

class CollectionAdmin(ImportExportModelAdmin, admin.ModelAdmin):
Expand Down
65 changes: 0 additions & 65 deletions apps/iiif/kollections/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ def save(self, *args, **kwargs):
super(Collection, self).save(*args, **kwargs)

def make_thumbnail(self):

# THUMB_SIZE = (400, 500)
# image = Image.open(self.original)
# image.thumbnail(THUMB_SIZE, Image.ANTIALIAS)
# If height is higher we resize vertically, if not we resize horizontally
size = (400, 500)
image = Image.open(self.original)
Expand Down Expand Up @@ -109,15 +105,6 @@ def make_thumbnail(self):

thefilename = thename + '_header' + theextension

# if thumb_extension in ['.jpg', '.jpeg']:
# FtTYPE = 'JPEG'
# elif thumb_extension == '.gif':
# FtTYPE = 'GIF'
# elif thumb_extension == '.png':
# FtTYPE = 'PNG'
# else:
# return False # Unrecognized file type

header_io = BytesIO()
cropped_image.save(header_io, format=FTYPE)
header_io.seek(0)
Expand All @@ -127,55 +114,3 @@ def make_thumbnail(self):
temp_thumb.close()

return True

# @property
# def thumbnail_crop_volume(self):
# if self.height > self.width:
# # portrait
# return "%s/%s/pct:15,15,70,70/,600/0/default.jpg" % (self.IIIF_IMAGE_SERVER_BASE, self.pid)
# else:
# # landscape
# return "%s/%s/pct:25,15,50,85/,600/0/default.jpg" % (self.IIIF_IMAGE_SERVER_BASE, self.pid)


# def make_header(self):
# x = (0)
# y = (0)
# w = (1000)
# h = (200)
#
# images = Image.open(self.original)
# images = images.crop((x, y, w+x, h+y))
#
# header_io = BytesIO()
# if thumb_extension in ['.jpg', '.jpeg']:
# FtTYPE = 'JPEG'
# elif thumb_extension == '.gif':
# FtTYPE = 'GIF'
# elif thumb_extension == '.png':
# FtTYPE = 'PNG'
# else:
# return False # Unrecognized file type
#
# thename, theextension = os.path.splitext(self.original.name)
# theextension = theextension.lower()
#
# thefilename = thename + '_header' + theextension
#
# images.save(header_io, format=FtTYPE)
# header_file = InMemoryUploadedFile(header_io, None, thefilename, FtTYPE, header_io.len, None)
# self.header.save(thefilename, ContentFile(header_io.read()), save=False)
# header_io.close()
#
# return True
#upload = models.FileField(upload_to='uploads/', null=True)
#created_at = models.DateTimeField()
#
# def __str__(self):
# return self.label
#
# def save(self, *args, **kwargs):
# ''' On create, set create time '''
# if not self.id:
# self.created_at = timezone.now()
# return super(User, self).save(*args, **kwargs)
5 changes: 5 additions & 0 deletions apps/iiif/kollections/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,8 @@ def test_serialize_list_of_collections(self):
collection = json.loads(serialize('kollection', Collection.objects.all(), is_list = True))
assert collection[0]['@type'] == 'sc:Collection'
assert isinstance(collection, list)

def test_serialize_single_object(self):
collection = json.loads(serialize('kollection', [Collection.objects.all().first()]))
assert collection['@type'] == 'sc:Collection'
assert isinstance(collection, dict)
6 changes: 3 additions & 3 deletions apps/iiif/serializers/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ def get_dump_object(self, obj):

return data

elif (self.version == 'v3'):
# TODO: write serializer for v3 of the IIIF Presentation API.
return None
# TODO: write serializer for v3 of the IIIF Presentation API.
# elif (self.version == 'v3'):
# return None

def handle_field(self, obj, field):
super().handle_field(obj, field)
Expand Down

0 comments on commit 4e715ca

Please sign in to comment.