Linux Server Diary

The trials and tribulations of a Linux newbie trying to setup a home server.

Monday, December 29, 2008

Custom Admin Templates in Django

(Those who are experienced Django developers, or even anyone beyond beginner stage, will find the follow points obvious, but I'm documenting here for my future reference.)

I've been experimenting with custom admin templates in Django, in preparation for a project I'm working on. I quickly found some help on the subject, mainly in the Django book. Chapter 6 lays it out pretty well:
As we explained in Chapter 4, the TEMPLATE_DIRS setting specifies a list of directories to check when loading Django templates. To customize Django’s admin templates, simply copy the relevant stock admin template from the Django distribution into your one of the directories pointed-to by TEMPLATE_DIRS.

The admin site finds the “Django administration” header by looking for the template admin/base_site.html. By default, this template lives in the Django admin template directory, django/contrib/admin/templates, which you can find by looking in your Python site-packages directory, or wherever Django was installed. To customize this base_site.html template, copy that template into an admin subdirectory of whichever directory you’re using in TEMPLATE_DIRS. For example, if your TEMPLATE_DIRS includes "/home/mytemplates", then copy django/contrib/admin/templates/admin/base_site.html to /home/mytemplates/admin/base_site.html. Don’t forget that admin subdirectory.

Then, just edit the new admin/base_site.html file to replace the generic Django text with your own site’s name as you see fit.

Note that any of Django’s default admin templates can be overridden. To override a template, just do the same thing you did with base_site.html: copy it from the default directory into your custom directory and make changes to the copy.

Here's where my beginner status gets in the way. I didn't know where in the directory structure to put the custom template. After a little playing around, I figured out that it should be in the directory pointed to by my TEMPLATE_DIRS setting in settings.py. Mine reads:
TEMPLATE_DIRS = (
os.path.join(os.path.dirname(__file__), 'templates').replace ('\\','/'),
)
So, with my project called 'mysite' and application called 'books', the custom change template for the publisher entity lands in /mysite/books/templates/admin/books/publisher/. Kind of long, but keeps the logic encapsulated with the application.

Next, I wanted to try changing the look of the admin screens. These templates have to be located in a templates directory found in the project directory. This is a little frustrating for me, since I'd like to keep these changes with the application. However, that's not how Django works, so I'll just go with it.

(Unrelated note, I tried out my app using lynx as the browser, and found it works pretty well. I think that as long as I strive for full lynx compatibility, I'll have better luck working with different browsers.)

Labels:

Saturday, December 20, 2008

Python on Dreamhost

A question for all of the Linux heads out there:

I'm hosting with Dreamhost, and I'm working on setting up a Django devlopement site. DH's Python version is 2.3, but I'd like to use 2.5. Following these instructions, compiled a 2.5 version.

Now, I need to set the PATH so that this new version will be used. How should I do that?

UPDATED:

Never mind!  I found it:

export PATH="$HOME/bin:$PATH"
source ~/.bash_profile
 
Plus, I added the export line to ./bash_profile so it is executed each time.

Labels: , ,

Saturday, November 08, 2008

Development Machine

I'm in the beginning stages of a new software project, so I've been experimenting with various tools and services.

To start with, I looked into building a development environment. Since I had decided on using the Python/Django platform for the project, I needed something to take me beyond using GEdit to monkey with text files.

I've heard of Eclipse quite a bit, but I was not familiar with the extent of its extensibility and how developers have taken advantage to extend the platform in all directions. It wasn't until I found PyDev, an Eclispe add in for Python, that I considered using the tool.

Installs of both Eclipse and PyDev were quick and easy, and I'm already liking the results. Once I get more comfortable with Python and get more experience with Eclipse, I feel that I will be happy with the environment.

Something else that I needed for the project was a version control system. I've never used a formal tool, but I've used backups and strict procedures to simulate the process. Since my internet hosting company, Dreamhost, offers quick and easy setup of Subversion respositories, I decided to give it a shot.

Before Eclipse came on the scene, I was using the command line SVN tools to communicate with the repository, and I'm pretty comfortable with the process. However, on a whim I decided to search for a Subversion add-in for Eclispe, and I found Subclipse almost right away. After I installed it and tweaked the connectors for a bit, it is working without issue. Very nice.

Since Python comes with the SQLite dbms included, I haven't thought much about database yet. An advantage of SQLite is that it runs on the client with no additional software to install. Very portable. I can setup MySQL on Dreamhost when testing multi-user, but I'm hoping for a connector to SQL Server or Oracle at some point. That's probably 6 months away.

Finally, I've been looking for a way to organize my thoughts. I'm a notebook guy at work, but I don't want to mix notes on my extra-curricular projects with work related things. Dreamhost also offers Mediawiki installs, so I'm trying it out. It's not the best for taking notes, but it's easy to use. We'll see.

At some point, I may involve others in this project, so the version control tool and wiki will help us share notes and source code. I could also setup a Google Apps domain for email and calendaring.

With all of the tools I'm using, all but one are open source, and even Google Apps is no charge. Imagine trying to do this 10 or 15 years ago, when much expensive Microsoft software would be required to even get off the ground. This modern economic model is great for start ups and small projects. My only cost is for the hosting service, and I set that up more for family use.

I'll report back on the progress in a few months.

Labels: , , ,