Categories: , ,
Posted by: bjb

Running django under wsgi wasn’t hard … You make a script called xxx.wsgi, and it has a function called ‘application’ that is the entry point to your application. Django supplies an entry point called @django.core.handlers.wsgi.WSGIHandler()@, so you just have to:

application = django.core.handlers.wsgi.WSGIHandler()

(with a little setup beforehand)

You also should configure Apache to handle the appropriate URL location with mod wsgi:

    WSGIScriptAlias /cp /home/bjb/work/credil-bjb/clientportal/wsgi/clientportal.wsgi

There was a little more stuff so that apache would serve some files statically (what django calls the “media” files and “static” files), but that was standard apache config. The other thing is to enable the wsgi module, and (because I’m using django auth) ensure that all the right modules are loaded and all the wrongs ones are disabled.

I started with this documentation (found a pointer to a parent page in the django docs):

Categories: ,
Posted by: bjb

To get rid of all the data in your database (but keep the tables):

./ flush

That is pretty much equivalent to:

sudo -u postgres dropdb appdb
sudo -u postgres createdb -O me appdb
./ syncdb

I even got asked the questions about creating the superuser after running the ./ flush command.

Categories: ,
Posted by: bjb

Another error made at the same time as the previous one was to call the model constructors with positional args:

mm = MyModel ('name', 'description')

This resulted in creating a MyModel instance like this: = 'name' = 'description'
mm.description = None

I should have called them with keyword args so the passed values would be assigned to the right attributes:

mm = MyModel (name = 'name', description = 'description')
Categories: , ,
Posted by: bjb

I made a new django app. First I made a few models, then some unit tests for the models. I could not save newly created model instances in the database, the error was something about there not being an attribute id.

It turned out that although I inherited the models.Model class into each of my models, I was overriding the __init__ function. I should have called super from the derived class’s __init__ method … This is what the model class should have looked like:

from django.db import models

class MyModel (models.Model):

    name = CharField (max_length = 64)
    description = CharField (max_length = 512)

    def __unicode__ (self):

and if i was going to declare an __init__ method, it should have looked like this:

    def __init__(self, *args, **kwargs):
        super(MyClass, self).__init__(self, *args, **kwargs)
        # my own customization code goes here
Categories: , ,
Posted by: bjb

I was learning about repo, and noted that repo can use a “list of projects” to narrow down the scope of its actions. It will operate on the list of projects you give it, and not the others. But, as a newish member of the team, I didn’t know what the list of projects was. I knew there was a manifest file. It is in xml format.

I was never very successful with xml. However, I thought that time has passed, and maybe there is a newer easier to use tool out there. I looked again and found xmlstarlet. Maybe my previous attempts at xml have softened me up so I can understand xmlstarlet, or maybe it really is easier than previous xml tools.

I wanted an xmlgrep:

xmlstarlet sel -t -m "//project" -v "@path" -n default.xml
 continue reading
Categories: , ,
Posted by: bjb
My co-worker encouraged me to post this ….

Our nightly builds started failing a while ago, and we wanted to know why. Nothing was immediately obvious so, as a new member to the team, I wanted to see what was different between “day that it worked” and “day that it failed”. Or rather, as the builds fixed themselves after a few days, what was the difference between “day that it failed” and “day that it worked”.

Well the android build is made up of a bunch of subprojects, each with its own git repository. I wasn’t going to be cd into each directory and running “git log” to see if something changed there lately. So I learned about the “forall” subcommand in repo:
repo forall -c "pwd; git log | grep '^[dD]ate' | head -1" > /tmp/repo-last-update-16 
and again in the other build directory.

A little massaging of the outputs allowed me to compare them with diff and find a differing project.
Categories: , ,
Posted by: bjb

It seems I’m going to be changing some mailing lists for oclug soon. I also ended up offering to help maintain the oclug django code that displays the oclug web site. Yikes! What was I thinking?!? Anyway, it’s written in python/django so at least I’ll be improving in areas I want to improve in. And Ian says he’ll help me out when I need it. Whew.

Posted by: bjb

Tonight I’m going to make “Unstuffed Cabbage” for dinner. It has the elements of cabbage rolls in a casserole, but without having to stuff the cabbage leaves and roll them up.