September 3, 2010

Stats on a larger Django project

diamond1 Stats on a larger Django projectA Django website that took (a lot) more than 20 minutes. Interesting writeup of a meta-forum app, including code samples and time breakdown.

Found via Django Forums.

[tags]django[/tags]

Zyons Forum for Django

HandshakeThis summer, I’ve been converting my biggest site, Invisible Castle, from Cheetah to straight Django. At the moment, Invisible Castle is run on straight CGI, using Cheetah to render the pages, so this is a rather big conversion.

I’m not just changing the template, that part is surprisingly simple, but the whole page flow logic. From stateless to a full web app. It is interesting, going quickly and the site will be much stronger when I’m done. It already gets 20-50K hits a month, and with my changes it will be able to take a lot more hits and handle them more quickly.

What’s the point?

Ah, but what’s the point? Why bother? Well, partially I just wanted to see how easy it would be, and because I find Cheetah templates annoying to maintain. But more importantly, after conversion, I’ll be able to use Zyons forums, and integrate them into the site. Zyons is a nice, full featured forum app, written using Django. So, I’ll be able to integrate my current app into a forum. How great is that?

Just try that with some hacky PHP forum. I dare you. I am absolutely certain it will work, and work smoothly. I can hardly wait to integrate and bring this dream to life.

[tags]django,cheetah,forum,zyons[/tags]

Pgrep and Pkill for OSX

HappyUsually I am satisfied by the commandline tools available in OSX. However, one itch that has been unfulfilled for quite a while since my permanent conversion to the Mac is the lack of “pgrep” and “pkill”, two of my favorite time savers from Linux.

Solution

sourceforge.net/projects/proctools/

Works like a dream.

[tags]osx,utilities[/tags]

A Django Killer App – Web Table Data

Light BulbYet another great use for Django is to make trivial the creation of shared tables & forms for internal projects. It is one of the most common needs in any size company, “Make me a web form to capture these data.” “Oh, and make sure to keep it locked down so that xxx dept can’t see it, and only you and I can modify it.”

Making these kind of web apps is one of the most boring tasks possible, yet they are both common and almost always poorly implemented. After all, they are just for internal use, right? And “they” rarely give you enough time to make a decent app anyway.

Well Django to the rescue. In four steps, you can have an app with far more functionality and usability than you’d ever have with some quick-hack up PHP page or ASP.

Step 1: Create the project directory and app directory

$ django_admin startproject projectbase
$ cd projectbase
$ ./manage.py startapp projectname

Step 2: Edit projectbase/settings.py
You can leave most everything default, at the simplest you can simply use a SQLite database, which requires no password or database setup. Be sure to enable the admin app, like so:


DATABASE_ENGINE = 'sqlite3'
DATABASE_NAME = '/path/to/your/project.db'
DATABASE_USER = ''
DATABASE_PASSWORD = ''
DATABASE_HOST = ''
DATABASE_PORT = ''

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'projectbase.projectname'
)

Step 3: edit projectbase/projectname. Models.py: Here you put the class or classes you want to track in your table. Here is an example taken from a simple migration tracking app I made at work.


from django.db import models

class Migration(models.Model):
    account = models.CharField(maxlength=30)
    email = models.EmailField(blank=True, null=True)
    prop = models.CharField(maxlength=30, null=True)
    requestor = models.EmailField()
    domains = models.TextField()
    target = models.CharField(maxlength=6)
    status = models.CharField(maxlength=20,
                              blank=True, null=True)
    created = models.DateField(null=True, blank=True)
    scheduled = models.DateField(null=True, blank=True)
    completed = models.DateField(null=True, blank=True)
    archived = models.DateField(null=True, blank=True)
    notes = models.TextField(null=True, blank=True)

    def __repr__(self):
        return self.account

    __str__ = __repr__

    class Meta:
        get_latest_by = "created"
        ordering = ("created",)

    class Admin:
        list_display = ("account", "email", "prop",
                        "requestor", "domains",
                        "target", "status", "notes",
                        "created", "scheduled",
                        "completed", "archived")
        search_fields = ("account", "domains")

Step 4: Create the database and tables

$ manage.py syncdb

At this point, you have a full fledged system available to you. Start Django however you please, add a few users and show off. You’ll have a full app available, with sorting of tables, updating, searching, and full authentication. All in a half hour of work.

[tags]django,killer app,python[/tags]