bradleyg / django-ajaximage Goto Github PK
View Code? Open in Web Editor NEWUpload images via ajax. Images are optionally resized.
License: MIT License
Upload images via ajax. Images are optionally resized.
License: MIT License
Please, help me to implement the Ajaximage, it seems that is cant find the url, the file is stored in the proper folder, but the admin and the view cant find the image...
INSTALLED_APPS = (
....
'ajaximage',
.....
MEDIA_URL = 'media/'
MEDIA_ROOT = 'media/'
STATIC_URL = '/static/'
STATIC_ROOT = 'staticfiles'
AJAXIMAGE_DIR = 'media/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
urlpatterns = patterns('',
url(r'^ajaximage/', include('ajaximage.urls')),
urlpatterns = patterns('',
url(r'^$', views.index, name='index'),
from django.contrib import admin
from Images.models import Image
from ajaximage.fields import AjaxImageField
admin.site.register(Image)
from django.db import models
from ajaximage.fields import AjaxImageField
class Image(models.Model):
titulo = models.CharField(max_length=200)
data_publicacao = models.DateTimeField('date published')
thumbnail = AjaxImageField(upload_to='thumbnails',
max_height=200, #optional
max_width=200, # optional
crop=True) # optional
def unicode(self): # Python 3: def str(self):
return self.titulo
def was_published_recently(self):
return self.data_publicacao >= timezone.now() - datetime.timedelta(days=1)
def get_absolute_url(self):
return reverse('Image:detail', kwargs={'pk': self.pk})
Thanks!
Hi when i syncdb i get error:
ajaximage\fields.py", line 34, in contribute_to_class
super(AjaxImageField, self).contribute_to_class(cls, name, virtual_only)
TypeError: Error when calling the metaclass bases
contribute_to_class() takes exactly 3 arguments (4 given)
then I remove virtual_only from 34 line and i get now error when I try save model:
"ajaximage\widgets.py in render, line 57"
"Error during template rendering
In template C:\Python27\lib\site-packages\django\contrib\admin\templates\admin\includes\fieldset.html, error at line 19"
If anyone have the same problem, please help me.. a try:
Replace (ajaximage\widgets.py in render, line 57):
file_url = value.url if value else ''
with:
file_url = value.url if value else str('')
I DO IT!!! But when i save model without name I get error about file_url = value.url if value else ''
I remove virtual_only=False and virtual_only from contribute_to_class in fields.py. THe results:
ajaximage\fields.py line 33- 35:
def contribute_to_class(self, cls, name):
super(AjaxImageField, self).contribute_to_class(cls, name)
setattr(cls, self.name, self.descriptor_class(self))
I try :
#12
Hi, I need to validate the size of the photo I'm uploading, how can I do it? Thank you.
Thanks for the app, it's very handy, and works well on its own. The problem that I'm having is that when it saves the filename, it prepends the MEDIA_URL
from settings, and always expects that to be included. This creates problems for other apps (e.g. sorl-thumbnail), which expect a path relative to MEDIA_URL
, following the standard FileField behavior. It also creates problems if you were to switch between ImageField and AjaxImageField in an existing project (or change your MEDIA_URL
).
I would suggest a boolean setting for prepending MEDIA_URL
to the filename so as not to break existing projects (defaults to True). I can do a pull request for this if you agree with this solution.
In ajaximage/views.py
return HttpResponse(json.dumps({'url': url, 'filename': path}))
should be changed to
from django.http import JsonResponse
return JsonResponse( {'url': url, 'filename': path} )
for Django 1.7+ This fixed my project.
I am saying about width_field and height_field.
https://docs.djangoproject.com/en/1.9/ref/models/fields/#imagefield
This line throws error with django 1.4
https://github.com/bradleyg/django-ajaximage/blob/master/ajaximage/fields.py#L34
This is resolved for example here: estuans@fbf9f33
by removing the 3rd parameter from call to super(AjaxImageField, self).contribute_to_class(cls, name, virtual_only)
If there is a way to do this so that it would support Django 1.4 -> 1.8 this would be nice!
I'm not sure if it does work without Grappelli, but here are the errors I see in console when ajaximage-enabled fields are loaded:
Uncaught TypeError: Cannot call method 'ajaxTransport' of undefined jquery.iframe (transport.js:38)
Uncaught TypeError: Cannot read property 'cleanData' of undefined (jquery.ui.widget.js:24)
Uncaught TypeError: Cannot read property 'support' of undefined (jquery.fileupload.js:33)
Uncaught TypeError: Property '$' of object [object Object] is not a function (ajaximage.js:1)
The fields are completely gone, so there is not even graceful degradation.
Like the Imagefield it replaces, upload_to could take a callable so that we can easily use directory names or filenames that contain the pk of the model.
I've tried to upload an image three times and now there are three copies of it in the media folder.
As I presume a lot of the code would be similar?
Ideally - the field could still display a thumbnail if the file was a recognised file format...
I want to use multiple widgets but when I pass more than one AjaxImageUploadForm into my template their input names have the same value ( ). I checked your widgets.py and tried to change the render method's name parameter but couldn't figure out where is this function called. Is there a way to do it or if my approach is not correct how can i use multiple forms?
I have tried many times, with the general instruction. but I confuse with the example. it using django-ajaximage 29 but when I using pypi to install, it just take the 28 version. The problem is with that version it makes when I try to upload image through admin page, upload proccess just stuck on load file and terminal keeps warn about "CSRF token missing or incorrect". I don't know why, but I really appreciate if you can help me
ajaximage / widgets.py
Import not used and deprecated:
line 5: from django.utils import simplejson as json
Change for compatibility with Pillow/Python3 on file: ajaximage/image.py
try:
from StringIO import StringIO as IO
except ImportError:
from io import BytesIO as IO
....
temp = IO()
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.