Poutine in Tokyo

I had a house party yesterday. Smashing success with more than 13 people attending; the main attraction seemed to be a disgusting Montreal specialty called Poutine.

For those wondering, making Poutine involved:

a) Creating Beef Stock (12$)
4$ / 1kg of beef bones. 8-9$ for the vegetables used

b) Creating Veloute Sauce (~.25c)
Butter + Flour + Beef Stock (1 L) plus simmering for an hour.

c) Making fresh cottage cheese curds (~6-7$)
4 L of milk plus vinegar

d) Fries (9$) + Oil ($1.50)
3 kg of fries

The main limiting agent was the beef stock and the veloute sauce. It wasn’t in sufficient quantity for the sheer amount of cheese and French fries I had available. Next time it’s going to be double the stock, and much less cheese / Fries.

Django, Fixtures and Character Encoding Bugs

I was having a hard time importing fixtures to my DB and kept getting bugs like this:

Warning: Incorrect string value: '\xE5\xA4\x89\xE3\x81\xAA...' for column 'request' at row 1

I tracked down the issue; it turns out that the MySQL connection is automatically set to swedish-latin on my Ubuntu box. As a result, the tables are all in that swedish-latin version that is set as the default character encoding. :/

You can confirm this yourself; try this at the MySQL commandline or in PHPmyadmin
SHOW VARIABLES LIKE 'character_set%';
If you find that there are some values that are not properly set to UTF8, you can make necessary changes as follows:


% stop mysql
% mysqld --character-set-server=utf-8

Try now. It should work.

Sadly, the only way for you to _fix_ this is to recompile mysql. I don’t have the time to do that right now, but you can read a bit about it here:

http://dev.mysql.com/doc/refman/5.0/en/charset-server.html

Hope this helps you.

Django: Auto-Creating/Importing Comments using the built-in comments system

While working on a ticket system for a client, I realized it probably would make most sense (for various reasons) to leave certain auto-generated information directly in the comment thread itself.  Code reuse and a single loci of focus for real-time feedback sounded like a winning proposition to me.

Unfortunately, running a Google search for anything in regards to directly using the comments model turned up nothing at all.  I suspected it was because no one dared abuse Django in a likewise manner; or because it was trivial.  Having seen the answer, I’m guessing it’s a bit of both.

The main clue that makes it easy is in the django / contribs / comments / forms file.


def get_comment_create_data(self):
"""
Returns the dict of data to be used to create a comment. Subclasses in
custom comment apps that override get_comment_model can override this
method to add extra fields onto a custom comment model.
"""
return dict(
content_type = ContentType.objects.get_for_model(self.target_object),
object_pk = force_unicode(self.target_object._get_pk_val()),
user_name = self.cleaned_data["name"],
user_email = self.cleaned_data["email"],
user_url = self.cleaned_data["url"],
comment = self.cleaned_data["comment"],
submit_date = datetime.datetime.now(),
site_id = settings.SITE_ID,
is_public = True,
is_removed = False,
)

The first two values are for the item you want to have the comment applied against.  In my case:

# obj = the object we want to save.
from django.contrib import comments
from django.contrib.contenttypes.models import ContentType
from datetime import datetime

auto_comment = comments.models.Comment()
auto_comment.content_type = ContentType.objects.get_for_model(obj)
auto_comment.object_pk = unicode(obj.id) # I don't need force_unicode for my case, but you may.
auto_comment.user_name = 'system comment'
auto_comment.user_email = 'jawaad.mahmood@example.com'
auto_comment.user_url = 'http://it_website/'
auto_comment.submit_date = datetime.now()
auto_comment.site_id = 1 # This may be differently configured in your settings.SITE_ID file
auto_comment.save()

This should save your comment in the appropriate thread.