Tuesday, September 22, 2009

The excellent Mr. Haki blog

My morning routine has changed recently. I check out Mr. Haki, fire up the Groovy console and run the latest example.

I have been seriously impressed with the work Mr. Haki is doing.

Even if nobody reads this post, I want to at least help his search rankings!


Wednesday, September 16, 2009

jRecruiter presentation at AJUG

Gunnar Hillert gave an excellent presentation on his jRecruiter project at AJUG last night.

I will soon be downloading jRecruiter to check it out in more depth. Gunnar mentioned that the Maven build is a little wonky at the moment. He said he would fix it in the next week or two.

He has a lot of really cool stuff in the app:
  • Struts 2.1, which I have not used. I spent years using the Struts 1.* releases, but have been in the JSF camp for a while now.
  • Twitter integration, which I've wanting to check out.
  • GZip and minification.
Check out the project or his blog for a complete list.


Friday, September 11, 2009

"The processing instruction target matching "[xX][mM][lL]" is not allowed."

I often put the Xml I use for test cases inside of Groovy classes. This allows me to make use of multiline Strings.

String inputXml = '''
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<records>
<record>
<recordid>833432</recordid>
<name>Lorem ipsum dolor</name>
<parentid>0</parentid>
<link>http://consectetueradipiscingelit</link>
<date>9/10/2009</date>
<description>Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu.</description>
<category ID="48015"></category>
<category>In enim justo</category>
</record>
</records>
'''


I ran into this error today :

"The processing instruction target matching "[xX][mM][lL]" is not allowed."

I'm surprised I hadn't run into it before. The problem was that I had white space before the xml prolog.

There are two easy solutions :
  1. Remove the whitespace.
  2. Call "trim()" on the String.

Whitespace removed :
String inputXml = '''<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<records>
<record>
<recordid>833432</recordid>
<name>Lorem ipsum dolor</name>
<parentid>0</parentid>
<link>http://consectetueradipiscingelit</link>
<date>9/10/2009</date>
<description>Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu.</description>
<category ID="48015"></category>
<category>In enim justo</category>
</record>
</records>


trim() called :

String inputXml = '''
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<records>
<record>
<recordid>833432</recordid>
<name>Lorem ipsum dolor</name>
<parentid>0</parentid>
<link>http://consectetueradipiscingelit</link>
<date>9/10/2009</date>
<description>Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu.</description>
<category ID="48015"></category>
<category>In enim justo</category>
</record>
</records>
'''.trim()


Thursday, August 27, 2009

app-engine-patch Database problems

I've been using app-engine-patch to get some Django stuff running on Google AppEngine.

Several times my admin password has been reset or invalidated. On a couple of occasions I recreated the admin user from the link on the default page. After styling the site this wasn't possible.

I added the "create_admin_user" entry from the generated myapp/urls.py to the root level urls.py and manually entered the url. That worked.



Unexpected Groovy return value

I like Groovy's multiline Strings. I use them all the time in my test cases. Usually I have a utility class that returns whatever content I need.

Yesterday I decided to do the whole test in Groovy. Inside my TestNG test case I had a method that returned some xml :

    String createInputFile(){
return
'''
<xml><one>Hello</one><two>World!</two></xml>
'''
}


The output was null. Kind of silly of me. Adding a semicolon after the String didn't produce an output. Putting the opening quote on the same line as the return statement did.

I still don't miss semicolons though.

Thursday, July 16, 2009

Practical Django Projects, coltrane weblog app and django-tagging

I'm working through Practical Django Projects 2nd Edition.

There is a problem with Chapter 4's weblog application, "coltrane." I won't go into detail about the coltrane app, but in the event that you encounter the same problem I've posted a solution.

I downloaded django-tagging. The current version was 0.2.1.

I created a symlink from my projects directory to the downloaded directory.

I added "'taggigng'" to "INSTALLED_APPS" and tried to start the server. I got the following :
Validating models...
Unhandled exception in thread started by <function inner_run at 0x652c30>
Traceback (most recent call last):
File "/Library/Python/2.5/site-packages/django/core/management/commands/runserver.py", line 48, in inner_run
self.validate(display_num_errors=True)
File "/Library/Python/2.5/site-packages/django/core/management/base.py", line 246, in validate
num_errors = get_validation_errors(s, app)
File "/Library/Python/2.5/site-packages/django/core/management/validation.py", line 28, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "/Library/Python/2.5/site-packages/django/db/models/loading.py", line 128, in get_app_errors
self._populate()
File "/Library/Python/2.5/site-packages/django/db/models/loading.py", line 57, in _populate
self.load_app(app_name, True)
File "/Library/Python/2.5/site-packages/django/db/models/loading.py", line 72, in load_app
mod = __import__(app_name, {}, {}, ['models'])
File "/[path to django projects]/coltrane/models.py", line 6, in <module>
from tagging.fields import TagField
File "/[path to django projects]/tagging/fields.py", line 10, in <module>
File "/[path to django projects]/tagging/models.py", line 9, in <module>
File "/[path to django projects]/tagging/managers.py", line 6, in <module>
ImportError: cannot import name parse_lookup
Sweet!

Turns out a lot of people have had this problem.

I checked out the current version from svn and recreated the symlink. All was well.

Django syncdb and create/drop

Django's manage.py syncdb command doesn't drop/create. It is clearly stated in the documentation. Naturally it took me a while to figure that out.

There is an easy solution :


python ./Documents/DjangoWorkspace/cms/manage.py reset coltrane
I've used it a few times now.