Wednesday, November 30, 2011

Creating an app for recurring features


I have made several projects now for internal use and some of the functionality keeps coming back.
For instance, language selection, user authentication, ad syncronization of users.

I want to put these in seperate apps that I can easily install in a project. All projects use virtualenv.
My first try is with the language stuff as this is only some settings and a view.
I've put the, views and so on in a seperate dir and then copied this dir in my current project.
Made a file to install the app with "python develop".

This works, and I can access the view from the project. So far so good.
I'm however not sure this is the right way to put some recurring functionality in a reusable app.
Some questions that arise:

- For the language selection view, I use small flags to make the language selection nicer.
These images are installed in the static directory of the application.
I then "installed" them in my project by including the correct dir in STATICFILES_DIRS
in the projec settings and then collected them with "python collectstatic --link"
I know I could have linked to the files but this seemed more Django like, yet, I'm not
sure this is the right way.

- I would like to be able to test the application. I thought that I could get away with a
minimal system (virtualenv + django) but it seems I need a rather complete
file and a typical project/app structure setup. I don't have that, so testing doesn't work.
How can I test the application code? Is there another way besides creating a full django project?

The settings file of the application (comments etc. left out)
ugettext = lambda s: s
('nl', ugettext('Dutch')),
('fr', ugettext('French')),
('en', ugettext('English')),

USE_I18N = True
USE_L10N = True

In my testproject, I made these changes to load the app succesfully.

1. I enabled- the LocaleMiddleware
2. I add the app to the INSTALLED_APPS
3. I load the language app settings file at the end of the projecs
This feels kind of hackish.
4. I add the path with the app static files to STATICFILES_DIRS
5. Add the app urls to the test project urls.

As I said, this is for local projects only, not meant to be distributed to the outside world.


You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

No comments:

Post a Comment