/kb

personal knowledgebase

Archive for March, 2009

Removing info bubble from Google Map, and keeping placemark

with one comment

UPDATE: Apparently this solution does not work anymore. I did a quick search, and it seems this could be a working solution.

Default behavious is to show the information bubble when embedding a Google Map in your web page. Some times this is not a desired behaviour, and you only want to show the placemark. After a little digging this Google Groups thread provided a very simple solution to the problem.

Add the iwloc-parameter with value near. Here’s an example:
View Larger Map
View Larger Map

So the string to insert is

&iwloc=near

somewhere in between. Take a look at my source code if you’re unsure.

Written by hgrimelid

March 26th, 2009 at 11:05 am

Posted in General

Tagged with , , ,

Chapter 7 in “Python Web Development with Django” – some notes

with 2 comments

I am currently in the process of learning Django and have just finished chapter 7 in Python Web Development with Django. Here are some notes on how I got it working (except for the index page which still isn’t completely as expected) on an ubuntu hardy installation.

The photo gallery example assumes an apache2 + mod_python setup. I didn’t really find it straightforward to get this running from the description in the appendix, so here is how I got it to work (after installation of apache2 and mod_python, of course):

In /etc/apache2/sites-available/default, change lines:

        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>

To:

        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride AuthConfig
                Order allow,deny
                allow from all

                AddHandler mod_python .py
                PythonHandler mod_python.publisher
                PythonDebug On
        </Directory>

Then I did the changes in /etc/apache2/httpd.conf, but slightly different from the book by adding a PythonOption django.root (didn’t work for me with the setup in the book):

<Location "/gallery/">
      SetHandler python-program
      PythonHandler django.core.handlers.modpython
      SetEnv DJANGO_SETTINGS_MODULE gallery.settings
      PythonOption django.root /gallery
      PythonDebug On
      PythonPath "['/path/to/django/root', '/home/user/django-stuff'] + sys.path"
</Location>

With an additional entry for media files:

<Location "/gallery/media">
      SetHandler none
</Location>

Now, I created a directory /var/www/gallery and a /var/www/gallery/media like explained in “Preparing for File Uploads” and edited settings.py:

MEDIA_ROOT = '/var/www/gallery/media/'
MEDIA_URL = 'http://localhost/gallery/media/'
ADMIN_MEDIA_PREFIX = 'http://localhost/gallery/media/admin/'

Where admin is a symbolic link (/var/www/gallery/media/admin) to the admin media directory in the Django installation. The two last entries where not mentioned in the book, but they made it work…

With the settings described above and the PythonOption django.root in httpd.conf, I didn’t need the section about DRY URLs. And it worked – as opposed to the stuff in the book.

With all the configuration stuff in place I typed the code outlined in the chapter and to begin with I couldn’t see any photos, except for the thumb_url in items_list.html (typo: items_listing.html in the last paragraph page 175). I managed to get it working by changing some lines in items_detail.html and photos_detail.html though:

22                 <img src="{{ photo.image.thumb_url }}" />

instead of

22                 <img src="{{ photo.get_image_thumb_url }}" />

and

8 <img src="{{ object.image.url }}" />

instead of:

8 <img src="{{ object.get_image_url }}" />

The alternatives that worked seems more intuitive to me.

I also imported list_detail from django.views.generic in urls.py, but am not sure if this was needed. The photo gallery seems to work fine except for the thumbnails in index.html. I’ve noticed that the code in urls.py for that template is different from the others, using simple.direct_to_template, but I haven’t managed getting that part to work.

Thanks to this thread for getting mod_python up and running: Python and Apache2

Written by Morten Wergeland Hansen

March 8th, 2009 at 8:08 pm

Posted in Programming

Tagged with , , , ,

#1064 – You have an error in your SQL syntax

without comments

When exporting and importing from and to different MySQL databases with diferent version numbers this error message might show up:

#1064 – You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ‘ENGINE=MyISAM DEFAULT CHARSET=utf8′

I got the message when exporting from a MySQL 5.x database and importing to a MySQL 4.x database. The solution came to me from the following blog post comment and is very easy. Just add the --compatible option:

mysqldump -u username -ppassword –compatible=mysql40 database_name > FILENAME.sql

Written by Håvard Grimelid

March 4th, 2009 at 11:28 am

Posted in Server

Tagged with ,