jonasundderwolf/django-image-cropping — pull request #3 by joshkersey (2012-03-30 20:34:27+00:00)
Title: fix Django 1.4 compatibility issue

```
Django Version:	1.4
Exception Type:	TypeError
Exception Value: __init__() takes at least 3 arguments (3 given)
Exception Location: /image_cropping/widgets.py in __init__, line 60
super(CropForeignKeyWidget, self).__init__(*args, **kwargs)
```

The signature for `ForeignKeyRawIdWidget.__init__()` in Django 1.4 is:

```python
class ForeignKeyRawIdWidget(forms.TextInput):
def __init__(self, rel, admin_site, attrs=None, using=None):
```

The required argument `admin_site` is new to Django 1.4. The `formfield` method of `CropForeignKey` in fields.py doesn't include the `admin_site` argument:

```python
def formfield(self, *args, **kwargs):
kwargs['widget'] = CropForeignKeyWidget(self.rel, field_name=self.field_name,
using=kwargs.get('using'))
return super(CropForeignKey, self).formfield(*args, **kwargs)
```

This patch inspects the arguments of `ForeignKeyRawIdWidget.__init__()` to see if `admin_site` is a required argument and patches it into the `__init__` kwargs for `CropForeignKeyWidget`. If admin_site is required it uses django.contrib.admin.sites.site as the value.

```python
class CropForeignKeyWidget(ForeignKeyRawIdWidget, CropWidget):
def __init__(self, *args, **kwargs):
if 'admin_site' in inspect.getargspec(ForeignKeyRawIdWidget.__init__)[0]: # Django 1.4
kwargs['admin_site'] = site
self.field_name = kwargs.pop('field_name')
super(CropForeignKeyWidget, self).__init__(*args, **kwargs)
```

Could be argued whether this belongs in the Widget init or the CropForeignKey formfield.