Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: jonasundderwolf/django-image-cropping
...
head fork: jonasundderwolf/django-image-cropping
  • 5 commits
  • 5 files changed
  • 0 commit comments
  • 1 contributor
View
12 example/templates/form.html
@@ -7,10 +7,14 @@
</head>
<body>
<p><b>Preview only! Add/Edit Images in Admin.</b></p>
+ {% if not image or not imagefk %}
+ <p style="color: #cc0000;"><b>Please upload an Image in Admin.</b></p>
+ {% endif %}
<table>
<thead>
- <th>Form</th>
- <th>Result</th>
+ <th>example form</th>
+ <th>cropped image</th>
+ <th>crop fk-image</th>
</thead>
<tbody>
<tr>
@@ -22,7 +26,9 @@
<td>
<img src="{% thumbnail image.image_field 120x100 box=image.cropping crop detail %}" />
</td>
- </tr>
+ <td>
+ <img src="{% thumbnail imagefk.image.image_field 120x100 box=imagefk.cropping crop detail %}" />
+ </td>
</tbody>
</table>
</body>
View
17 example/views.py
@@ -1,10 +1,19 @@
from django.shortcuts import render
from forms import ImageForm
-from models import Image
+from models import Image, ImageFK
def form(request):
- image = Image.objects.all()[0]
- form = ImageForm(instance=image)
+ try:
+ image = Image.objects.all()[0]
+ form = ImageForm(instance=image)
+ except (Image.DoesNotExist, IndexError,):
+ image = None
+ form = ImageForm
- return render(request, 'form.html', {'form': form, 'image': image})
+ try:
+ imagefk = ImageFK.objects.all()[0]
+ except (ImageFK.DoesNotExist, IndexError,):
+ imagefk = None
+
+ return render(request, 'form.html', {'form': form, 'image': image, 'imagefk': imagefk})
View
2  image_cropping/admin.py
@@ -7,6 +7,6 @@ def formfield_for_dbfield(self, db_field, **kwargs):
formfield = super(ImageCroppingAdmin, self).formfield_for_dbfield(db_field, **kwargs)
if hasattr(db_field, 'related') and db_field.name in self.model.crop_fk_fields:
- formfield.widget = CropForeignKeyWidget(db_field.rel, field_name=db_field.name,
+ formfield.widget = CropForeignKeyWidget(db_field.rel, field_name=db_field.field_name,
admin_site=self.admin_site)
return formfield
View
4 image_cropping/fields.py
@@ -19,7 +19,7 @@ def south_field_triple(self):
args, kwargs = introspector(self)
return (field_class, args, kwargs)
-#deprecated, as we now set the widget in the ModelAdmin
+
class CropForeignKey(models.ForeignKey):
'''
A croppable image field contained in another model. Only works in admin
@@ -59,7 +59,7 @@ def contribute_to_class(self, cls, name):
cls.crop_fk_fields.append(self.image_field)
def formfield(self, *args, **kwargs):
- kwargs['widget'] = forms.TextInput(attrs={
+ kwargs['widget'] = forms.TextInput(attrs={
'data-width': int(self.width),
'data-height': int(self.height),
'data-image-field': self.image_field,
View
6 image_cropping/static/image_cropping/image_cropping.js
@@ -7,14 +7,14 @@ var image_cropping = {
image_cropping.$("<style type='text/css'>" + style_img_warning + "</style>").appendTo('head');
image_cropping.$('input.image-ratio').each(function() {
- var $this = image_cropping.$(this),
+ var $this = image_cropping.$(this);
// find the image field corresponding to this cropping value
// by stripping the last part of our id and appending the image field name
- field = $this.attr('name').replace($this.data('my-name'), $this.data('image-field')),
+ field = $this.attr('name').replace($this.data('my-name'), $this.data('image-field'));
// there should only be one file field we're referencing but in special cases
// there can be several. Deal with it gracefully.
- $image_input = image_cropping.$('input.crop-thumb[data-field-name=' + field + ']:first');
+ $image_input = image_cropping.$('input.crop-thumb[data-field-name=' + field + ']:first');
// skip this image if it's empty and hide the whole field
if (!$image_input.length || $image_input.data('thumbnail-url') == undefined) {

No commit comments for this range

Something went wrong with that request. Please try again.