Formatting source code

How embarrassing! WordPress has what seems to be a nice source code formatter, meaning the stuff with pygments was probably unnecessary; although it may be I like its results better after all. I’ll try the wp one for now. For starters, here’s the function from earlier today:

def getdate(obj, addition):
    """
    Look at the logs to find creation/modfication dates.
    """
    model = type(obj)
    # we need the contenttype
    ct = ContentType.objects.get_for_model(model)
    # now we can look up the logs for this object
    logs = LogEntry.objects.filter(content_type=ct,
            object_id=obj.id).order_by('-action_time')
    dates = [l.action_time.date() for l in logs \
                if not addition or l.is_addition() ]
    try:
        return dates[0]
    except IndexError:
        return None 
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: