Archive for the ‘Django’ Category

Making a Django POST mutable

July 9, 2010

For good reasons, the Django Request object’s POST attribute is immutable. No one wants anyone mucking around with important data there. But I had a case where I wanted to re-use some view code and it would involve using a POST object again, but with a few added parameters.

You can copy the POST data into a QueryDict, but I found that if you want to forward the actual request, you have to copy.copy() the request using the python standard copy library. Maybe this is obvious but it might save someone(like me) an hour of searching and trial/error.

def my_view(request)
    req_copy = copy.copy(request)
    req_copy.POST = request.POST.copy()
    req_copy.POST.update({'added_param':'my_value'})
    my_DRY_view(req_copy)

def my_DRY_view(req_copy)
        cool_stuff()

Django polymorphism: Mixins vs Inheritance Models

January 15, 2010

Relational databases are not the greatest storage destination for polymorphic data structures (stack overflow). Polymorphism allows you to have heirarchies of objects that perform similar actions. By defining this action once, you can re-use it for its subclasses. It makes code cleaner and easier to maintain. I experimented with a few different ways of doing some of my subclassing and came away with an approach involving mixins that I really like so far.

(more…)

Parsing HL7 with Python

January 7, 2010

Boy, do I love Python. Coding in Python is like making chocolate chip cookies with your hands… and being able to lick the bowl, too. So smooth, so sugary, and once in a while, you find a chocolate chip.

Well, the most recent chocolate chip I found is an open-source HL7 parser. We are not quite to the total interoperability phase yet, but those goals are scheduled for the near future.

Question, in the HL7 store, they offer to sell you the HL7 specification. Does this mean it is illegal to even attempt to parse a file labeled as HL7 without purchasing a license?  Maybe I will parse an extra character and call it HL7++.

Design Decision: Python and Django

December 25, 2009

Python is one of the leading professional programming languages in use today. It was the official programming language of my previous employer and, boy, am I glad I had the chance to learn it! C++ is not much of a web language these days. Many people use Java, PHP and Perl for their web programming. These are all fine languages but it is my personal opinion that they are all inferior to Python for this project.

(more…)


Follow

Get every new post delivered to your Inbox.