Monday, April 11, 2011

TurboGears 2.1 Admin System Plural Name

I really do not like the way TG2.1 Admin System force developer to use plural name. Because in my language we do not use the same grammar. Totally different, so it's a terrible idea to put 's's on every model/table name.

To solve this issue, there are two major area that we need to change. The first one is the genshi template, and the other one is the class that is responsible to parse the model/table REST urls.

Fortunately the issue resides on one class tgext.crud.controller.CrudRestController. There are some methods which use genshi templates located in tgext.admin.templates. So, you might want to copy the templates and make appropriate changes. Done with one area.

Next is to change the way CrudRestController uses the template and perform lookup for the model/table REST urls. The way to change the template is to change the value of @expose decorator.
Another thing to do is to override _lookup method.
Inside, you can see code like the following:
model_name = model_name[:-1]
The code above assumes that the model/table REST url is in plurals. No good. Don't like it at all. Simply remove that particular line of code and we're done.

No comments:

Post a Comment