[Next entry: "Urgent Care and 2 Hospitals"]
Home » Archives » January 2009 » Django 1.0 Patch for Flatpage files
[Previous entry: "Django patch to use emails, not usernames"]
Home » Archives » January 2009 » Django 1.0 Patch for Flatpage files
[Previous entry: "Django patch to use emails, not usernames"]
Django 1.0 Patch for Flatpage files
11 January 2009 @ 09:01 PM MST
11 January 2009 @ 09:01 PM MST
Current Music: None
Current Mood: Good
Current Mood: Good
Django's built in Flatpages module allows you to store flatpage content into the database and then display it using the built in template system. Unfortunately this means you have to load a bunch of flatpage content into the database. I decided this would be a pain for the setup I need so I modified the Flatpage module to check the content string of a flatpage object, if that strings ends in ".html" it attempts to open a file at the location of flatpage.content. If it is successful, then it dumps that file into the page. If it is not successful it gracefully fails and will just display whatever was found in flatpage.content.
The reason I wanted this was so that the actual flatpage content could be created and edited by others then merged to the server using a version control system. Also, since the site is being developed on a development machine it would be a pain to then copy and paste all the content onto the live machine. This way it's only necessary to setup the flatpage objects that point to the actual files. Still a pain, but much less so overall.
The filename you specify should be an absolute path. Since Flatpages marks the content as "safe" upon display you are also responsible for ensuring that the HTML contained in the included file is properly escaped, etc.
Also, upon doing this work I realized that rather than patching the core files on your system you could simply copy them to your project directory, patch the copies, then make sure your project settings.py specifies the local copies instead of the core files. This may be a better option for some people, however since the project I'm working on is going to be large, I find it easier to just patch the core and not add more mess to my project directory. Mind that if you ever upgrade Django you'll probably clobber your patched files and things will break. So, it's probably a bit safer to do the local copies if you intend to upgrade Django, however, you can always copy the altered core files to the project directory and update settings.py later down the road.
So, without further ado. Here's the patch. It is quite small, just a few lines.
django_flatpages_files.patch
See my previous post for instructions on how to apply the patch.
[This Entry]
The reason I wanted this was so that the actual flatpage content could be created and edited by others then merged to the server using a version control system. Also, since the site is being developed on a development machine it would be a pain to then copy and paste all the content onto the live machine. This way it's only necessary to setup the flatpage objects that point to the actual files. Still a pain, but much less so overall.
The filename you specify should be an absolute path. Since Flatpages marks the content as "safe" upon display you are also responsible for ensuring that the HTML contained in the included file is properly escaped, etc.
Also, upon doing this work I realized that rather than patching the core files on your system you could simply copy them to your project directory, patch the copies, then make sure your project settings.py specifies the local copies instead of the core files. This may be a better option for some people, however since the project I'm working on is going to be large, I find it easier to just patch the core and not add more mess to my project directory. Mind that if you ever upgrade Django you'll probably clobber your patched files and things will break. So, it's probably a bit safer to do the local copies if you intend to upgrade Django, however, you can always copy the altered core files to the project directory and update settings.py later down the road.
So, without further ado. Here's the patch. It is quite small, just a few lines.
django_flatpages_files.patch
See my previous post for instructions on how to apply the patch.
[This Entry]