Novel Study

It’s been a while since I’ve updated this. But here’s to trying again!

I’ve been slowly meandering back to writing in general. Indeed, I’ve undertaken the vast project of going on a reading spree — I’ve put together a list of nearly one hundred books to read, the goal being to expand my experiences. The idea here is to read a wide variety of material, refraining from limits in any way. don’t plan on waiting until this immense feat is complete before I begin writing. I could be at this for up to a year. But even the simple act of reading is causing the metaphorical pot to simmer. The ideas are churning, the desire and urge is creeping up on me. I can feel it.

In the meantime, I thought it would be insightful to reverse engineer a novel. I’m currently reading Axis by Robert Charles Wilson, the sequel to the 2005 Hugo Award-winning Spin. As I read, I pause after each scene, and jot down a brief summary of that scene. In a single sentence, what happened? What vital plot information was revealed? What purpose did this scene serve? I’m quickly gaining a deeper overall understanding of the structure of the novel. Much more than if I had just immersed myself in the story, as I usually do with fiction. Once I’m finished reading, I plan to take the resulting plot outline, and work backwards. From the list of scene summaries, what are the minor plot points? From that, what are the major plot points? I think this will provide insight in to the process of working from a single idea, all the way to a full novel.

There’s also another aspect of the story that I haven’t even mentioned — characters. I plan to write up simple character profiles at the end of the novel, paying attention to who the characters are, what their motivations and goals are, some major personality traits, and how all of these things conflict and contrast with the other characters.

While this project is definitely not complete by any definition, I’m finding it very informative and fascinating so far. If you’re a budding writer like myself, who is stuck on figuring out the process of going from idea to plot outline, try breaking down and analyzing a novel like this. It might just be the insight you need to get started.

Object Level Permissions with Django

Since the release of 1.2, Django has supported — to the extent of having an API for it — object level permissions. They leave it up to the developer to write their own implementation.

Object level permissions are something that have been long missing from Django. The ability to limit access to specific records, rather than entire tables, is a very common requirement of today’s web applications and the lack of such support in Django has been quite limiting in my experience. After doing some reading on the methods other developers are using to implement the new object permission API, I decided to write my own.

My implementation leverages any existing data you have and doesn’t require you to create new tables. It also doesn’t require you to create a set of permission records for every object in the database. It’s fairly simple and flexible, and works for both users and groups.

First, we need to extend the link tables that are part of Django’s auth package. We need to add an object_id field to both the auth_user_user_permissions and auth_group_permissions tables, like so:

ALTER TABLE `auth_user_user_permissions` ADD `object_id` integer NULL;
ALTER TABLE `auth_group_permissions` ADD `object_id` integer NULL;

Now, we need to create models to reference these tables, so we can filter on them. Put these in any models.py file you see appropriate for your application:

from django.contrib.auth.models import User, Group, Permission
class UserPermission(models.Model):
    user = models.ForeignKey(User)
    permission = models.ForeignKey(Permission)
    object_id = models.PositiveIntegerField(null=True)
    class Meta:
        db_table = 'auth_user_user_permissions'<
class GroupPermission(models.Model):
    group = models.ForeignKey(Group)
    permission = models.ForeignKey(Permission)
    object_id = models.PositiveIntegerField(null=True)<
    class Meta:
        db_table = 'auth_group_permissions'

There. Seem simple enough? Now all that's left is to write a custom authentication backend that handles object-level permissions using these modified tables. Create a new file in any of the apps in your project called 'objperm.py' (or whatever you choose to call it). In that file, import the UserPermission and GroupPermission models. The backend looks like so:

class ObjectPermBackend:
    support_object_permissions = True
    def authenticate(self, username=None, password=None):
        return None
    def has_perm(self, user_obj, perm, obj=None):
        (app_label, codename) = perm.split('.')
        u_kwargs = dict(user=user_obj, permission__content_type__app_label=app_label, permission__codename=codename)
        g_kwargs = dict(group__user=user_obj, permission__content_type__app_label=app_label, permission__codename=codename)
        if obj is not None:
            u_kwargs.update(dict(object_id=obj.id))
            g_kwargs.update(dict(object_id=obj.id))
        has_user_perms = UserPermission.objects.filter(**kwargs).count() > 0
        has_group_perms = GroupPermission.objects.filter(**kwargs).count() > 0
        return has_user_perms or has_group_perms

And there you have it! This authentication backend will support model-level permissions as well as object-level permissions, leveraging the existing permissions link tables that Django's auth package creates. Now all that's left is to add this new backend to your settings.py. If you don't have any custom authentication backends already, it's as simple as adding the following to your settings.py:

AUTHENTICATION_BACKENDS = (
    'django.contrib.auth.backends.ModelBackend',
    'path.to.your.backend.ObjectPermBackend'
)

…Or Maybe It’s the Salt?

Last time I talked about my Irish Cream bread not turning out so well. No matter how much I kneaded it, the gluten didn’t seem to develop. The next day, I decided to bake some fresh French baguettes for dinner according to a recipe I had. Last time I made them, they turned out delicious and crispy.

This time, just for the sake of experimentation, I decided to omit the salt from the recipe. I must say up front, the baguette recipe is stupid simple to begin with. It’s literally just flour, yeast, water, and salt. What difference would it make if I omitted a teaspoon of salt? A big one, apparently.

As I began kneading the dough, I worked in additional flour, as I normally do. The dough remained sticky — sticky enough that the dough would stick to my hands and the counter. I ended up adding about 1/2 to 2/3 of a cup more flour than the recipe calls for, and the dough remained sticky and lacked the elasticity which suggests proper gluten development. I kneaded for almost 30 minutes, and still no luck.

I decided to bake it anyway, and in the end, it turned out much better than my Irish Cream bread. But I found one commonality: there’s no salt in my Irish Cream bread recipe, either. I wondered if the combination of alcohol + no salt led to the less than ideal results in that recipe.

I decided to do some research again, and indeed, this is exactly what I found.

Unsalted dough mixes faster, has little resistance to extension and feels sticky. Bakers who delay the salt addition during mixing find that once salt is added, the dough tightens, becoming more difficult to stretch, but also becomes stronger, and is thus capable of stretching farther without ripping. (Found here)

It seems that salt strengthens gluten, creating a less sticky, more stretchy and elastic dough. Next time I make the Irish Cream dough, I’m going to add a teaspoon of salt and see what happens. Rest assured I’ll be posting the results!

You can find the French baguette recipe I used here.

Adding Liquor to Bread Dough

To the left is a picture of my latest original creation, Irish Cream Bread. This was a completely experimental idea I had, and I wasn’t exactly sure how it would turn out. As you can see, the dough is very uneven and bumpy, which (I think) is caused by lack of water and too much alcohol.

Some more experienced bakers, at first glance and not considering the alcohol content, might say “hey, you’re not done kneading yet!” I kneaded this dough for nearly half an hour, adding a total of 3.5 cups of flour. The dough had, for the most part, lost its stickiness, which is usually a good indication of when its done. Why, then, did it turn out this way? I’m not entirely sure, but I’m guessing its caused by not enough water and too much alcohol.

Without getting too deep in to it, kneading dough creates gluten, which, like its name suggests, provides the ‘glue’ which holds your dough together and gives it it’s elasticity. I did a little bit of reading after having my dough turn out this way. Apparently, gluten forms best with water, and not so great with alcohol. Some forum conversations suggested replacing some of the water in a pie crust recipe with alcohol. The result being a softer dough you can work with, but less gluten due to the alcohol content, creating a flakier crust.

The last time I tried this recipe, I used a smaller amount of Irish Cream, thus it’s effect on the gluten formation was not as pronounced. At the same time, the resulting bread had no trace of the Irish Cream taste, which is what I was going for. So this time, I increased the amount of Irish Cream, and decreased the amount of milk.

Even though I suspected that the alcohol was indeed inhibiting the gluten formation, I went ahead and baked it anyway. The image on the right is the end result: a big, gaping hole in the middle, with doughy parts around it. For the most part, it turned out excellent! The crumb is fine and moist, and it tastes incredible. I’m guessing the giant hole is caused by lack of gluten: on the second rise, with the dough in the loaf pan, the gluten didn’t keep the dough together in the middle, creating a hole in the middle. As for the doughy part, I’m not sure what caused that. I baked this at 350F for about 30 minutes.

In any case, I ended up with a mostly awesome loaf of bread, and a lesson learned: water is an important part of gluten formation. If you’re going to add liquor to your bread recipes, be sure there’s enough water to complement it. My recipe had very little water to begin with — just enough to proof the yeast — so that was not a good place to begin.

So, what’s next? I’m considering experimenting with various liqueurs. Even with the 1/4 cup of Irish Cream in this version of the recipe, the taste is still eluding me. Perhaps the extra long rise is masking the flavour of the Irish Cream? I’m not sure. Other interesting ideas I’ve had are substituting the Irish Cream with a Hazelnut liqueur (such as Frangelico) or an almond liqueur (such as Amaretto). Of course, almond extract would probably add the same flavour.

Tomorrow, I’m baking fresh baguettes for dinner. I’ve made these once before, and that recipe is where I got the inspiration for the extra long rise time in my Irish Cream recipe. Stay tuned for more adventures in baking…

You can find the current version of my Irish Cream Bread recipe here.

And here we go again…

So, here I go again. Maybe I’ll be able to come up with enough content to keep this thing up to date more than twice a year. After all, I’ve been baking a lot lately, and writing about my baking experiments and experiences is probably not a bad idea.

Stay tuned….