jonasundderwolf / django-image-cropping

Django helper application to easily and non-destructively crop arbitrarily large images in admin and frontend.
Other
553 stars 131 forks source link

Nothing works like the example application #65

Closed alsoicode closed 9 years ago

alsoicode commented 9 years ago

Installed django-image-cropping on an existing Django 1.7.4 / Python 3.4 project that had easy_thumbnails installed. Settings are verbatim to the docs for installed apps, processors, etc.

My model is defined as:

class Profile(models.Model):
    uuid = UUIDField(auto=True)

    image = ImageCropField(upload_to=get_profile_upload_to, blank=True, null=True,
        help_text='Must be jpg, png or gif.')
    image_cropping = ImageRatioField('image', '200x200')

my form is:

class ProfileForm(forms.ModelForm):

    class Meta:
        exclude = ('user', 'is_active',)
        model = Profile

When I:

print(form.media)

in my view:

@login_required
def preferences(request):
    profile = Profile.get_profile(request)
    form = ProfileForm(request.POST or None, request.FILES or None, instance=profile)

    if request.method == 'POST':
        if form.is_valid():
            form.save()
            messages.success(request, 'Your preferences have been updated.')
            return HttpResponseRedirect(reverse('accounts:profile_home'))

    return render(request, 'accounts/preferences.html',
        {'profile': profile, 'form': form, 'active_nav': 'edit'})

I do not get:

<link href="/static/image_cropping/css/jquery.Jcrop.min.css" type="text/css" media="all" rel="stylesheet" />
<link href="/static/image_cropping/css/image_cropping.css" type="text/css" media="all" rel="stylesheet" />
<script type="text/javascript" src="/static/js/jquery.min.js"></script>
<script type="text/javascript" src="/static/image_cropping/js/jquery.Jcrop.min.js"></script>
<script type="text/javascript" src="/static/image_cropping/image_cropping.js"></script>

as shown in the example application. Even when I add the CSS and JavaScript by hand, the cropping fields aren't being shown with their respective widgets. Instead when I save the form, my view is just redirecting as it did previously.

What am I missing here? Not to be rude, but literally nothing happens with this application installed. I can see no differences in my installed libraries, Django or Python version (virtualenv is identical), nor my models or forms, templatetags, etc, yet somehow the example application magically works.

anrie commented 9 years ago

From a distance and without a failing test, that demonstrates the issue, it's really hard to tell what's going on.

But it seems that the ImageCropWidget isn't set correctly, as the widget includes the media files AND sets some data attributes and without these attributes it's no wonder that even the manually included media files show no effect.

Usually the widget is set by the ImageCropField, so make sure you don't overwrite that widget somewhere in your code. Apart from that you could try setting the widget explicitly as described in the docs: https://github.com/jonasundderwolf/django-image-cropping#modelform