A module of django components that give you picasa storage, picasa fileds and admin fields.
Project description
How to use djgoogle.picasa
--------------------------
I'm pretty useless at documentation so I will just guide you through
how I use these components in my web site.
Prerequisites
------------
Before you start you will need to install google's python api.
easy_install will do that for you.
Installing
--------
Okay lets go. Either do::
easy_install django-picasa
Or download the distribution file into your temp or just check out the
picassa module into your project's directory. Run python setup.py::
C: emp>
C: emp>python setup.py install --install-purelib="C:\your_project"
running install
running build
running build_py
creating build
creating build\lib
creating build\lib\picasa
copying picasaields.py -> build\lib\picasa
copying picasa\storage.py -> build\lib\picasa
copying picasa\__init__.py -> build\lib\picasa
running install_lib
creating C:\your_project_root\picasa
copying build\lib\picasaields.py -> C:\your_project\picasa
copying build\lib\picasa\storage.py -> C:\your_project\picasa
copying build\lib\picasa\__init__.py -> C:\your_project\picasa
byte-compiling C:\your_project\picasaields.py to fields.pyc
byte-compiling C:\your_project\picasa\storage.py to storage.pyc
byte-compiling C:\your_project\picasa\__init__.py to __init__.pyc
running install_egg_info
Writing C:\your_project_root\djgoogle-1.0-py2.5.egg-info
settings.py
-----------
Add the framework to the INSTALLED_APPS tuple of your projects
settings.py file::
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.admin',
'your_project.cms',
'your_project.picasa'
)
Then add to the settings.py file your PICASA_STORAGE_OPTIONS::
PICASA_STORAGE_OPTIONS = {
'email':'thanosv@gmail.com',
'source':'thanos',
'password':'mypassword',
'user':'thanosv',
'cache': True}
Where:
email is your Picasa account id.
source is a string you will use to identify how the images where added
to your Picasa account.
user is the actual Picassa account that the images will stored in. It
doesn't have to be your account just any account you have the access to.
cache is weather you want to use Django's caching back-end. Usually
it's worth it.
If you have set cache to true they you might want to add something like
this::
CACHE_BACKEND = "locmem://?timeout=30&max_entries=400"
models.py
---------
Now you are done with the settings.py file you can replace the
ImageFields? with the picasa field in your models::
from picasa import PicasaField
class Image(models.Model):
photo = PicasaField( )
Try it out by uploading an image through your admin page and then visit
your Picasa account. You will see the uploaded image in your Drop Box. Added a
upload_to='media'::
photo = PicasaField( upload_to='media')
and it will upload the file into an album called media, if the album
doesn't exist it will be created.
admin.py
--------
The default admin representaion of your image will be handled by the
AdminFileWidget which will just show the value of PicasaField.url of the
containing web page in your Picasa account. It's useful but would be better to
see a linked thumbnail. To do that you need to override the PicasaField with
PicasaAdminImageWidget. To do that import the widget in your admin.py module
and add it to an formfield_overrides dictionary: :
By default PicasaAdminImageWidget? generates a 64 pixel icon. The sizes
available are::
class PicasaFieldFile(ImageFieldFile):
SIZES = (32, 48, 64, 72, 94, 104, 110, 128, 144, 150, 160, 200, 220,
288, 320, 400, 512, 576, 640, 720, 800, 912, 1024, 1152, 1280, 1440, 1600)
You can override the class attribute SIZE to change the thumbnail's
size::
class ImageWidget(PicasaAdminImageWidget):
SIZE='48'
class ImageAdmin(admin.ModelAdmin):
formfield_overrides = {PicasaField: {'widget': ImageWidget},}
views.py
--------
Using the above demo model here is a quick view::
def images(request):
return render_to_response('cms/images.html', {'images':Image.objects})
Here is its corresponding template (templates/cms/images.html) ::
<h2>Image List</h2>
{% for image in images.all %}
<a href="{{image.photo.url}}"><img src="{{image.photo.src}}"
width="300"/></a><br/>
{% endfor %}
and the html it produces::
<h2>Image List</h2>
<a href="http://picasaweb.google.com/thanosv/
Media04#5434869420740374642"><img src="http://lh6.ggpht.com/_w0eENG7V9Qg/
S2yI8Wfc8HI/AAAAAAAAAdQ/xrYdkgQF8r0/itunesscreenshot.jpg" width="300"/></a><br/>
<a href="http://picasaweb.google.com/thanosv/
Media04#5435910379245055122"><img src="http://lh3.ggpht.com/_w0eENG7V9Qg/
S3A7sHHCrJI/AAAAAAAAAdw/QMY9OIviHB0/thanos.jpg" width="300"/></a><br/>
Different Sizes
--------------
Although this HTML saves your site a lot of bandwidth your images are
at the mercy of the browsers resizes and when the original images are large
will still be slow to download.
Changing the image source variables to indicate the size they need by
using image.photo.src_300 instead of image.photo.src gets Picasa to do the
resizing and greatly speeds up the download. requesting an image of the width
300 will in fact get you 320, which is the next available size up::
<h2>Image List</h2>
{% for image in images.all %}
<a href="{{image.photo.url}}"><img src="{{image.photo.src_300}}"
width="300"/></a><br/>
{% endfor %}
And its HTML::
<h2>Image List</h2>
<a href="http://picasaweb.google.com/thanosv/
Media04#5434869420740374642"><img src="http://lh6.ggpht.com/_w0eENG7V9Qg/
S2yI8Wfc8HI/AAAAAAAAAdQ/xrYdkgQF8r0/s320/itunesscreenshot.jpg" width="300"/></
a><br/>
<a href="http://picasaweb.google.com/thanosv/
Media04#5435910379245055122"><img src="http://lh3.ggpht.com/_w0eENG7V9Qg/
S3A7sHHCrJI/AAAAAAAAAdw/QMY9OIviHB0/s320/thanos.jpg" width="300"/></a><br/>
Possible Problems
----------------
If you are behind a proxy and you get the following error when you try
an upload an image::
gaierror at /admin/cms/image/add/
(11001, 'getaddrinfo failed')
Check that you have set both HTTP_PROXY and HTTPS_PROXY. HTTPS_PROXY
can usually be set to the same host as HTTP_PROXY.
--------------------------
I'm pretty useless at documentation so I will just guide you through
how I use these components in my web site.
Prerequisites
------------
Before you start you will need to install google's python api.
easy_install will do that for you.
Installing
--------
Okay lets go. Either do::
easy_install django-picasa
Or download the distribution file into your temp or just check out the
picassa module into your project's directory. Run python setup.py::
C: emp>
C: emp>python setup.py install --install-purelib="C:\your_project"
running install
running build
running build_py
creating build
creating build\lib
creating build\lib\picasa
copying picasaields.py -> build\lib\picasa
copying picasa\storage.py -> build\lib\picasa
copying picasa\__init__.py -> build\lib\picasa
running install_lib
creating C:\your_project_root\picasa
copying build\lib\picasaields.py -> C:\your_project\picasa
copying build\lib\picasa\storage.py -> C:\your_project\picasa
copying build\lib\picasa\__init__.py -> C:\your_project\picasa
byte-compiling C:\your_project\picasaields.py to fields.pyc
byte-compiling C:\your_project\picasa\storage.py to storage.pyc
byte-compiling C:\your_project\picasa\__init__.py to __init__.pyc
running install_egg_info
Writing C:\your_project_root\djgoogle-1.0-py2.5.egg-info
settings.py
-----------
Add the framework to the INSTALLED_APPS tuple of your projects
settings.py file::
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.admin',
'your_project.cms',
'your_project.picasa'
)
Then add to the settings.py file your PICASA_STORAGE_OPTIONS::
PICASA_STORAGE_OPTIONS = {
'email':'thanosv@gmail.com',
'source':'thanos',
'password':'mypassword',
'user':'thanosv',
'cache': True}
Where:
email is your Picasa account id.
source is a string you will use to identify how the images where added
to your Picasa account.
user is the actual Picassa account that the images will stored in. It
doesn't have to be your account just any account you have the access to.
cache is weather you want to use Django's caching back-end. Usually
it's worth it.
If you have set cache to true they you might want to add something like
this::
CACHE_BACKEND = "locmem://?timeout=30&max_entries=400"
models.py
---------
Now you are done with the settings.py file you can replace the
ImageFields? with the picasa field in your models::
from picasa import PicasaField
class Image(models.Model):
photo = PicasaField( )
Try it out by uploading an image through your admin page and then visit
your Picasa account. You will see the uploaded image in your Drop Box. Added a
upload_to='media'::
photo = PicasaField( upload_to='media')
and it will upload the file into an album called media, if the album
doesn't exist it will be created.
admin.py
--------
The default admin representaion of your image will be handled by the
AdminFileWidget which will just show the value of PicasaField.url of the
containing web page in your Picasa account. It's useful but would be better to
see a linked thumbnail. To do that you need to override the PicasaField with
PicasaAdminImageWidget. To do that import the widget in your admin.py module
and add it to an formfield_overrides dictionary: :
By default PicasaAdminImageWidget? generates a 64 pixel icon. The sizes
available are::
class PicasaFieldFile(ImageFieldFile):
SIZES = (32, 48, 64, 72, 94, 104, 110, 128, 144, 150, 160, 200, 220,
288, 320, 400, 512, 576, 640, 720, 800, 912, 1024, 1152, 1280, 1440, 1600)
You can override the class attribute SIZE to change the thumbnail's
size::
class ImageWidget(PicasaAdminImageWidget):
SIZE='48'
class ImageAdmin(admin.ModelAdmin):
formfield_overrides = {PicasaField: {'widget': ImageWidget},}
views.py
--------
Using the above demo model here is a quick view::
def images(request):
return render_to_response('cms/images.html', {'images':Image.objects})
Here is its corresponding template (templates/cms/images.html) ::
<h2>Image List</h2>
{% for image in images.all %}
<a href="{{image.photo.url}}"><img src="{{image.photo.src}}"
width="300"/></a><br/>
{% endfor %}
and the html it produces::
<h2>Image List</h2>
<a href="http://picasaweb.google.com/thanosv/
Media04#5434869420740374642"><img src="http://lh6.ggpht.com/_w0eENG7V9Qg/
S2yI8Wfc8HI/AAAAAAAAAdQ/xrYdkgQF8r0/itunesscreenshot.jpg" width="300"/></a><br/>
<a href="http://picasaweb.google.com/thanosv/
Media04#5435910379245055122"><img src="http://lh3.ggpht.com/_w0eENG7V9Qg/
S3A7sHHCrJI/AAAAAAAAAdw/QMY9OIviHB0/thanos.jpg" width="300"/></a><br/>
Different Sizes
--------------
Although this HTML saves your site a lot of bandwidth your images are
at the mercy of the browsers resizes and when the original images are large
will still be slow to download.
Changing the image source variables to indicate the size they need by
using image.photo.src_300 instead of image.photo.src gets Picasa to do the
resizing and greatly speeds up the download. requesting an image of the width
300 will in fact get you 320, which is the next available size up::
<h2>Image List</h2>
{% for image in images.all %}
<a href="{{image.photo.url}}"><img src="{{image.photo.src_300}}"
width="300"/></a><br/>
{% endfor %}
And its HTML::
<h2>Image List</h2>
<a href="http://picasaweb.google.com/thanosv/
Media04#5434869420740374642"><img src="http://lh6.ggpht.com/_w0eENG7V9Qg/
S2yI8Wfc8HI/AAAAAAAAAdQ/xrYdkgQF8r0/s320/itunesscreenshot.jpg" width="300"/></
a><br/>
<a href="http://picasaweb.google.com/thanosv/
Media04#5435910379245055122"><img src="http://lh3.ggpht.com/_w0eENG7V9Qg/
S3A7sHHCrJI/AAAAAAAAAdw/QMY9OIviHB0/s320/thanos.jpg" width="300"/></a><br/>
Possible Problems
----------------
If you are behind a proxy and you get the following error when you try
an upload an image::
gaierror at /admin/cms/image/add/
(11001, 'getaddrinfo failed')
Check that you have set both HTTP_PROXY and HTTPS_PROXY. HTTPS_PROXY
can usually be set to the same host as HTTP_PROXY.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
django-picasa-1.3.zip
(22.4 kB
view details)
django-picasa-1.3.tar.gz
(13.8 kB
view details)
Built Distribution
django_picasa-1.3-py2.5.egg
(11.8 kB
view details)
File details
Details for the file django-picasa-1.3.zip
.
File metadata
- Download URL: django-picasa-1.3.zip
- Upload date:
- Size: 22.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ffd9e34f7cc498b104502fea135c8c56ed292204859c6d57014e1c32217fcbb |
|
MD5 | 9e7bd6430db39a3deb8227dae9859daa |
|
BLAKE2b-256 | 041afbf7ebd50343edd2c5465580fd65dc209fca7b240a5872e2766a92403bd4 |
File details
Details for the file django-picasa-1.3.tar.gz
.
File metadata
- Download URL: django-picasa-1.3.tar.gz
- Upload date:
- Size: 13.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a716797668ba50d5a3746b53f88dfbe3e70289e555514d186e7b6e97571923ea |
|
MD5 | 3e1349488f7854c1e1d97f221fe5a2ca |
|
BLAKE2b-256 | 25f3eb68557f0ff6b5aeb727e5d83bd75103234f7b386487767e7fadb1a3a9f0 |
File details
Details for the file django_picasa-1.3-py2.5.egg
.
File metadata
- Download URL: django_picasa-1.3-py2.5.egg
- Upload date:
- Size: 11.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bace545313c956528f3f8204262556981a393ffa95b01a76ba888675b95f085d |
|
MD5 | 76e7348b2c972524a8d884d555bb287f |
|
BLAKE2b-256 | 69f235c5d76bdd38612d4b3a2b564de7efac753c3bd1724bee97cc907ffcf378 |