Archive for the 'Websites' Category

-image-Django site comments and all!

I haven’t been posted that much here recently and thats because I have been doing other things and working on other sites. I have also built a new server for home, which will be detailed later, but first and foremost I am still playing with Django and build a site using it.

I have had enough with doing WordPress sites, and although I do know it fairly well I wanted to write something a bit more tailored to the application. And its a good test for the plans I have for other applications later on.

Django I am enjoying, but its not with out frustration. And although in parts it is amazingly well documented for a framework thats been in the public eye for a relatively shorttime it does miss out on the docs in some parts. I am finding that some things are overdocumented and its hard to find relatively simple bits of information and others such as the comment system just isn’t documented.

Although they are quite upfront about the comment system needing documents, it is an area that slows down the production pipeline quite alot, to the point where its as slow going as any other development. I suppose I can’t complain too much but still I hope this gets addressed reasonably quickly. I should put down my own experiences with the comment system at this point for others to use, but it should be noted that I don’t know much at all and this is only my findings and what I have so far:

  1. The Django comment system is broken up into three areas - Comments, Karma and Freecomment and if you are interested in what these contain then looking at the database should be your first port of call.
  2. Free comments and comments are different though in some cases if you are using a template or method using free_ then you can sometimes safely omit free_ and get the standard comment system.
  3. The standard comment system is based around logged on users, while freecomments seems to be open to all.
  4. At the moment due to the lack of documentation the two best places to find out information is from the django source itself /django/contrib/comments and in the sourcecode posted by Jeff Croft for his Lost-Theories website.

Here you can see the django comments tables in MySQL (my host doesn’t yet support PostGreSQL, so I develop in the same database I am going to host on).

MySQL view of the comments system

So this has lead me to get a working but rough comments module into my test site. I am using a mixture of my own views and generics like most, and I have created my own templates for the tables in my model.

In the details page for one model, I am pulling out some information from the post like so:

{% block content %}
{{ object.article_body|escape|linebreaks }}
{% endblock %}

Then I am referring to the comments. My model is called Post so that is what I am pulling the comments out for:

{% block metacontent %}
{% load comments.comments %}
{% get_comment_list for website.post object.id as comment_list %}
{% ifequal post.get_comment_count 0 %}
No one has posted any comments yet. Perhaps you'd like to be the first?
{% endifequal %}
{% for comment in comment_list %}
{{ comment.comment }}
{% endfor %}

Then I pull in the standard comment form:

{% comment_form for website.post object.id%}

In your templates directory you can then create a subdirectory called “comments” and the commenting system will search in here first for the comments templates before using its own.

I copied the form.html template in here and modified it, and then I also created templates for posted.html and preview.html. If you are looking for ideas for these two again Jeff Croft’s source code for Lost-Theories is very helpful.

And this is as far as I have got so far. In the future I would love to extend it with the Karma system but there is alot more to do to get this site up and running.


-image-Dreamhost backup plans

I have been looking at how I backup my data at home, and one thing that always comes to mind is how to get these backups of site, and preferrably into a different geographical area easily.

Well Amazon S3 storage was always on my mind, but recently Dreamhost have gone crazy with their storage offerings.  I know have over 400Gb of space with over 4Tb of transfer for a small outlay each month.

A cost comparison has been done here by Joseph Scott showing how the two compare:
http://joseph.randomnetworks.com/archives/2006/10/03/amazon-s3-vs-dreamhost/

I am going to be looking at implementing something with Dreamhost I think, I am not a major corporation, I am a home user with some data so I think Dreamhost will be fine.

Bacula and Backuppc are two projects that run on Debian that I will be checking out, and first and foremost I want to make sure that my data is encrypted quite strongly.  Though I am probably going to put up my photo archive just as is, to have easy access when needed.  More posts to come on this.


-image-Almost finished a site!

Along time ago I wrote a list of things that I need to complete, well I have managed to get one thing done on the list, and that was a site I was building for a friend.  Its almost complete from his designs, though I have yet to get feedback.  The site is in Norwegian, for a Norwegain company and it is:

http://www.nord-vesteiendom.as/

Screenshot of Nord-VestEiendom

Its a really simple site on the outside, showcasing new house builds, and all the import information will be uploaded in PDFs shortly.  As normal I built the whole thing on top of WordPress 2, with a custom template which actually contains quite a bit more custom PHP than the simplicity of the site actually reveals.  But Wordpress lets anyone update the site, add in pictures which are formatted properly and then attach PDFs.

I will be of course putting in more information about the build in my portfolio site.  Now on to build http://jeanettemagnussen.com


-image-django with apache2

One thing that I feel is harder than it should be with django is getting it working with Apache2. Sure the built in webserver is nice for development, but there comes a time when you need to step up and use a webserver for development that you can also deploy the site upon.

I have used Apache a lot in the past, but recently I have decided to move over to installing everything the Debian way, and this will reflect that. I am going to use python2.3, Apache2 and the version of mod_python that is in stable. You can follow the instructions if you have installed Apache2 and mod_python in otherways after this step if you wish.
To get Apache2 on debian with mod_python, simply:

  1. apt-get install apache2
  2. apt-get install libapache2-mod-python

For the rest of the tutorial, I am assuming that you have Django setup correctly, and working with your database. If not, I recommend installing the development version. It is easy to update using SVN and there are some features that are better than the stable version I find. Once you have done this you can start to build your site. From then on you can create your apache virtualhost file:

I have decided to run my django site on a different port, but of course you can run it on different ipaddresses, and with different hostheaders. All you need to do is follow the apache 2 documentation for this. I feel this is already well documented so I will just show how I did it by running on different ports:

  1. Edit the ports file for apache2 to tell it to listen on more than one port:
    vi /etc/apache2/ports.conf
  2. Add this line to tell it to listen on port 8000:
    Listen 8000
  3. Create a new sites file for this new virtual host:
    vi /etc/apache2/sites-available/djangosite
  4. Now we need to put in the configuration details:
    
    
    
    SetHandler mod_python
    PythonHandler django.core.handlers.modpython
    PythonPath “[’/home/tim/dev/projects/’] + sys.path”
    SetEnv DJANGO_SETTINGS_MODULE djangosite.settings
    PythonDebug On
    
    
    Alias /media “/var/www/djangosite/media”
    
    SetHandler None
    
    
    
    SetHandler None
    
    
    
    

    This gives us several things:

    • Sets up a virtualhost to listen on port 8000.
    • For the virtual host use mod_python.
    • PythonHandler is told to use Django.
    • Our PythonPath is updated with our site files, in my case my django projects are located in /home/tim/dev/projects/ so this is what I use. Point this to where your django files are kept.
    • Let django know to use the settings file for this project
    • The we setup an alias to serve the media files, as they don’t need to be served through mod_python we turn the handler off for the /media/ location. I will setup my media files in /var/www/djangosite/media
    • Finally tell apache2 not to use mod_python to serve image files.

  5. Now save this file, and enable the site:
    a2ensite djangosite
  6. Now create the webhosting directory, and the symbolic link for the admin directory, and check the permissions:
    mkdir /var/www/djangosite/
    CD /var/www/djangosite/
    ln -s /usr/lib/python2.3/site-packages/django/contrib/admin/media/
    chmod -R 755 /var/www/djangosite
    
  7. The stop and start apache2 on your server (this is for Debian using init.d scripts, but whatever you do stopping then starting is better than a simple reload).
    /etc/init.d/apache2 stop; /etc/init.d/apache2 start

Once you have done that, check your site by point a webbrowser to the the machine that you have apache2 running on, but at port 8000 for instance if it is a localhost, tryhttp://127.0.0.1:8000.

One thing that I haven’t talked about is where it is best to place all the files used in creating a django site, and I have yet to read any documentation about this. This is why in the above I am point it to a dev subdirectory from my home directory. I don’t think this is a good idea for a production site, and perhaps it should go in somewhere off /var.

One thing is for sure, creating seperate directories for media and the actual files is a good idea, and you if you follow the django instructions you can take them up on the recommendation of using a seperate lightweight webserver to just serve these files.


-image-hellahella on Apache 2

I have been using hellahella using paster serve and I must say the performance was terrible. I don’t think that it is mean’t to be run for any length of time which is at odds with hellahella, the web interface to hellanzb, which is.

I have documented before that I am using hellanzb to manage my nzb files, and hellahella makes it even easier and with integration with http://www.newzbin.com it is even better (how about one click downloads, unrar, par, and ready to view - yes I have it!)

So I wanted to run hellahella using Apache2 on my Debian box. Luckly just as I wanted to do this a new FAQ was put up on the Pylons web site on how to achieve this using mod_python (which I also wanted to use). Pylons is a web framework for python and it seems quite good too and I got alot of help from the very helpful pylons-discuss group on groups.google.com.
So I setup Apache2 or rather Debian did using apt-get, and I got a fairly normal install. If you haven’t used version2 of apache before the configuration has changed somewhat and all the config files are now split. At the same time I also installed mod_python using apt-get and as this is rather well documented I am not going to write it down here. Now all we need do is follow the first part of the instructions on the Pylons site:

  1. Install hellahella (I assume you are running hellanzb already otherwise go and download and install it) and make sure it works with paster serve hella.ini
  2. Make sure mod_python is installed and enabled.
  3. Save the http://projects.amor.org/misc/svn/modpython_gateway.py script as wsgi.py in your mod_python python directory which is /usr/lib/python2.3/site-packages/mod_python/ on my system.
  4. Create a project directory. I used /www/hellahella
  5. Create startup.py file in this directory with the following information:from paste.deploy import loadapp
    app = loadapp(”config:/www/hellahella/hella.ini”)
  6. Create a link to your hella.ini file: ln -s /etc/hella.ini hella.ini
  7. Go into your apache2 sites directory: CD /etc/apache2/sites-available/
  8. Create a new site: vi hellahellaSite
  9. And input the following information:

    VirtualHost 127.0.0.1
    ServerAdmin tim@timc3.com
    DocumentRoot /www/hellahella/
    SetHandler mod_python
    PythonHandler mod_python.wsgi
    PythonPath "['/www/hellahella/'] + sys.path"
    PythonOption wsgi.application startup::app
    PythonOption SCRIPT_NAME /
    ErrorLog /var/log/apache2/error.log
    Alias /stylesheets/ "/www/hellahellaMedia/stylesheets/"
    Alias /javascripts/ "/www/hellahellaMedia/javascripts/"
    Alias /images/ "/www/hellahellaMedia/images/"
    LogLevel warn
    CustomLog /var/log/apache2/access.log combined
    /VirtualHost
  10. Remember to change the ipaddress 127.0.0.1 to whatever ipaddress or domain name you need.
  11. The to a level above your doc root: CD /www
  12. Then create a link from the public media files for hellahella to a directory here: ln -s /usr/lib/python2.3/site-packages/hellahella-0.1dev_r782-py2.3.egg/hellahella/public
  13. Rename public: mv public hellahellaMedia
  14. You might need to chgrp and chown the files under this directory.
  15. Then enable this site: a2ensite hellahellaSite
  16. Restart apache2: /etc/init.d/apache2 stop; /etc/init.d/apache2 start
  17. Then test.
  18. And it should work aslong as hellanzb.py is running and hellahella is setup correctly.

And I must say it is looking good!


-image-Django setup

Over the last few days I have been playing with Django quite alot, installing it on a couple of machines and on Dreamhost. The Dreamhost configuration is now well documented by Jeff Croft in his post: http://www2.jeffcroft.com/2006/may/11/django-dreamhost/ and the on Dreamhost Wiki here: http://wiki.dreamhost.com/index.php/Django

I did seem to use a few different settings on the file:

django.fcgi:
#!/usr/bin/env python import sys sys.path += ['/home/timc3/django/django_src'] sys.path += ['/home/timc3/django/django_projects'] from fcgi import WSGIServer from django.core.handlers.wsgi import WSGIHandler import os os.environ['DJANGO_SETTINGS_MODULE'] = 'drunkonpetrol.settings' WSGIServer(WSGIHandler()).run()

Which seemed to help no end in getting it working.

On my own development machines I have had to set the PYTHONPATH environmental variable in .profile which is what python uses to search along when doing its imports. This is also set when using Mod_Python in the VirtualHost settings of Apache.

DJANGO_SETTINGS_MODULE is another env var that can be set this time for django itself. I haven’t yet configured it on my machines at the moment but I will do no doubt.

The base configuration that django gives via its admin tools is very good, but it has been extended by this project: Nesh DjangoUtils , which helps when setting up a djangoproject to do everything from creating the directories to creating the fcgi and modpython entries.  I haven’t needed to use it yet as I already started my django project before using it, but it is one to try in the future for sure.

So far I am finding django quite rapid in development, but I am spending alot of time looking for documentation on things, but the IRC channel is proving invaluable for help.  I will be putting up alot more articles as I go forward.


-image-To Do list

Speaking about the To Do list, there actually seems to be quite a lot on there at the moment. So as a note to myself and in no particular order I need to build:

  • Finish off our EveryMetric.com marketing site. This was something a group of us formed to fill a particular hole in the market place. All the backend and the framework is in place, we have some more work to do on the extranet and I need to finish off our marketing site.
  • Extranet for EveryMetric. This is quite a big job, probably taking a few months of evenings but I think that it might be worth it.
  • DrunkOnPetrol.com. This is the pseudonym that I record under. I was going to build a site with downloads etc.. Probably take 2 weeks, and a good candidate for some light Django action.
  • JeanetteMagnussen.com. My girlfriends site for her acting, I will probably base this around WordPress.com as I have done with others. 2 weeks maximum.
  • timc3.com redesign. Doesn’t need much. 2 days.
  • blog.timc3.com redesign. This needs some cleaning up. 4 days.
  • norsk.timc3.com addition of features. Those I talked about in the earlier post. Shouldn’t take more than 5 days.
  • Aldateateret.com design changes. This is my girlfriends theatre company, and I created the site in about 3 days and its based around WordPress so has almost a complete CMS and lots of nice features. I need to add the new logo which I have designed for them and update the graphics somewhat. Another 2 days.
  • A site that I am working on with Lars in the next few months. This shouldn’t take long but should be a nice little project but its still an unknown amount of time.
  • Site for the London Olympics. Still might not bother, but I do have the domains.
  • share.timc3.com > Where I put all my pictures. I am using this less and less and using flickr more and more, but its still nice to have somewhere to put up alot of rubbish. Either change it to a new system or implement a new style sheet (I accidently deleted the old one, then overwrote my backups!).
  • RSS feed site. This is a small project that I have been thinking of building. 2 weeks. Say no more!
  • Also been thinking about building a forum for Non-natives in Norway. Not sure of the need.
  • Password application site. Another small project that I have done the docs for. 2-3 weeks.
  • musictech.timc3.com. I haven’t updated this in months, so I should consider trashing it, or at least doing something nice with Wordpress and spinning it out of blog.timc3.com

So thats probably enough on my plate, and my work at Vizrt comes first, so I might get those things done by the end of the year. Yeah Right.

I just counted, I have over 14 sites that I admin over at the moment. Thats crazy. I got fed up of that when I was doing this stuff full time, 16 hours a day. Modern CMSs, frameworks and blogging engines are the only way that this is possible but as EveryMetric has shown me properly designed frameworks take time to build.


-image-Keeping the wheel - Norsk Test

I was thinking about redoing this in Django on it or something, but then I thought; what is the point of redoing this?  Although it only took me 4 hours to build in the first place, there is not really much point in rebuilding something that works.

So Norsk Test is back and still a multiple choice test that I was using to test myself on Norwegian words, either from Norwegian to English or English to Norwegian.  All the words have been taken from the book “Klar for Norge” and as I mentioned above it was done rather quickly, but I need the practice.  I am sure there are some errors in it, even though a Norwegian teacher has looked over it and my Norwegian girlfriend.
On the ToDo list is an admin interface for it so I can easily add words, more classification types, I freeform type test, word search and tidying up the oh so horrid interface!  Perhaps look at the SQL it is using because I am sure its quite nasty.

Now I need to find something to get those Django skills up!


-image-django and python

At Vizrt there is alot of python, and although I wish I could have jumped on the bandwagon and started messing around more with Ruby, I am enjoying working with python where the scripts are properly authored.

So I was looking for a nice framework that would give me Rails style speed of prototyping web applications whilst using Python and after looking at the usual suspects (Turbogears, pylons, zope & plone) I am again playing around with Django again.

Django

Django is nice, not too heavy weight, seems flexible and uses the best parts of python - its go anywhere sensibilities coupled to only write things once, to a semi - MVC style of creation (well it has models and views - thats a start).

Its not quite as mature as Rails, but in these days of million user Beta & Gamma web applications thats hardly going to put anyone off, I can host it on Dreamhost with the help of the excellent tutorial from Jeff Croft here: http://www2.jeffcroft.com/2006/may/11/django-dreamhost/ (and his site is powered by Django, and is quite a stunning showcase).

I also like the fact in Django that it has a web admin interface plus a shell interface, that the web admin can be completely transformed and then rolled out into the application.

The only wonder that I had was whether I could build something using PostgreSQL (I much prefer using PostgreSQL, and have it on all my dev machines at home) and then publish it to Dreamhost and use MySQL.  There is one cmd,

manage.py syncdb

that setups the database access layer and looking at the examples if I don’t write any custom SQL statements then I might be able to get away with it.  I really wish Dreamhost would support PostgreSQL.

Django could also do with a nice webforum for support, but the IRC channel has many users on, and I take my hat off to them for supplying the code for the actual support website - Well done.  I suppose I will have to wait until some creates a forum - or maybe they could install vanilla.  Created by me old man Neven, and one of the nicest bits of forum software I have seen.

For a  quick overview of Django take a look at: http://www.djangoproject.com/documentation/overview/


-image-Upgrade to Wordpress 2.2

Well I did a quick upgrade yesterday to Wordpress 2.2 after restoring this old theme back (not sure why I did that other one, but I looked at it again and though it was even more terrible than this one) but it looks like I forgot to put in the code for google analytics into the footer. I wondered why nothing was happening on the site!

Wordpress upgrading was easier that I first though after reading the upgrade instructions.


Bad Behavior has blocked 677 access attempts in the last 7 days.