Leitrim and Cavan county borders were broken in Open Street Map for about 2 days just now, and it caused the townlands to break. I've updated the code to break when this happens (it means those counties aren't in the DB now), but the border has been fixed. Those counties should appear tomorrow.
Oops. Turns out I had a bug in my "detect if this user is a bot" part, where my site would have an internal error if a bot when to it (and I'd get an error email from django obviously). I've fixed that now (hopefully).
And I wondered why there was like 1 or 2 pages coming up in the google search results for this site.... :P
Django comes with a handy template tag to turn any string into a nice 'slug', which you can use in URLs. If you ever need to use this in python, you can do this:
from django.template.defaultfilters import slugify
and then call the slugify function, e.g. slugify('My string here')
You can migrate a django south app to a specific version with this command: python manage.py migrate $APPNAME $NUMBER, i.e. to migrate it to the one that starts with 0002_…, enter this command: python manage.py migrate $APPNAME 0002.
You can undo all the migrations by giving using zero, i.e. python manage.py migrate $APPNAME zero. I initially tried 0000, but that doesn't work. This will 'remove' all the migrations done for an app. (The migrations will still be there as files, but the models won't be there)
When you have a ManyToMany field in Django and use the Django Admin, it by default uses a <select> widget. It's easy to change this to be a list of checkboxes (i.e. <input type=checkbox>).
Checkboxes, in the default Django Admin style/CSS are easier to read than a multiple select box.
If you have a Post object, with a tags ManyToMany field, then this code in your admin.py will turn the tags field into checkboxes.
class PostAdminForm(forms.ModelForm):
class Meta:
widgets = {
'tags': forms.CheckboxSelectMultiple
}
class PostAdmin(admin.ModelAdmin):
form = PostAdminForm
admin.site.register(Post, PostAdmin)
Sometimes you only want to distribute a single python file as a module. It might just be a few simple functions, and rather than have a whole directory, it's much easier to have a single python file that can be imported and used.
Assuming your python file is called name_of_file.py, then make a file setup.py with this content in the same directory as name_of_file.py:
If you're using git to manage you files, and you have some changes to some files, and you want to throw away the changes (i.e. revert to the previous checked in version), then you can do it with this:
git checkout path/to/myfile.ext
(replace the path/to/my/file.ext with the path/filename of the file you want to 'revert')
This is the git equivalent of svn's svn revert path/to/myfile.ext
I was doing some work on a git project, on the master branch, and made 2 commits. Then I thought I should really do this on a separate branch, instead of master. But I've already committed twice to master!
Luckily git is great.
Firstly, you want to move to your feature branch, so do git checkout -b name-of-new-branch, tis'll create a new branch with the 2 new commits.
Then switch to master with git checkout master, and look at the logs, with git log. You'll see your 2 new commits that you want to 'get rid of'. Look for the commit just before the 2 commits, and look at the commit: … line. Copy & paste the part after the :, it'll look something like: 09c171332d969c55bceb80db58c70a710be994e3.
This is the id of a commit, (and tree of files), and it can act like a branch. You can checkout that 'branch' with git checkout 09c171332d969c55bceb80db58c70a710be994e3, which will give you a few lines message about how it's a "detached HEAD". Once it's checked out, give this a name, with git checkout -b master2. We are calling this new branch, master2. It's got everything in master, but without the 2 commits which want to have on the feature branch. Then just delete the old master branch (git branch -d master), and rename master2 to master (git branch -m master2 master).
master will now have everything but without the last 2 commits, and name-of-new-branch will have master and the 2 commits, so you can continue work there.
Obviously things get a bit more complicated if you've pushed master somewhere or if you have a lot of local changes. Best to not do it in that case.
My Django application appeared to just freeze. When I open a webpage, it just hangs. There is no noticable high load or CPU or memory usage on my server. There is no apache access log or error log messages. Other static apache websites I have hosted on the same machine, with the same apache instance, work fine. It's just the Django… hanging.
This is a weird problem, and is caused by scipy being a python library that's written in C, and there's some complication with the python GIL and mos_wsgi, which means it'll hang.
Luckily, there's a simple fix. You have to add this line to your Apache configuration file.
distutils & pip is a great way to install python (incl. Django) packages. Django has lots of installable apps. This is the barebones setup.py that you need for your django app:
Let's pretend you have an app called appname. (i.e. you started it with django-admin.py startapp appname). In the same directory as your appname folder, create a file setup.py and put this in:
Installing Django with pip is quite easy, but I wanted to install Django from SVN to get the latest and greatest (and because they fixed a bug. This is how you do it:
If you want to resize a window on the Ubuntu command line you can use the cool tool wmctrl, and it works with the new Unity Desktop from Ubuntu. You can install wmctrl with sudo aptitude install wmctrl or click on this link
List Windows
List all the windows currently open with this command: wmctrl -l, you'll get some output like this:
As should be obvious, Celtic Knot Creator is back. I intent to blog a lot about the progress of this project/business.
About a year ago I made an online celtic knot page, that's not live now, but I'll put it back later. At the moment I'm setting some clip art, which you can find on the home page.