Showing posts with label django. Show all posts
Showing posts with label django. Show all posts

Thursday, July 31, 2008

Planing and designing a Google App Engine application

Last time, if you remember, we sent a mail with Google App Engine, using the mail function. This time we need to think again on the Mass Mailer project.
It should contain
  • A simple web form
  • Textboxes, text editor and a button to send
  • Ajax platform to make it easy
  • Some animation like rotating arrows
  • Limiting mails to 50 per user
So there will be a total of 40 user every day, that's few, also sending 50 email is so few! So why not use an SMTP Server.

If the user have an SMTP server, so he can use it, then there won't be any quota problems.
The usage should be simple, like that
  • Enter the receivers addresses (50 or unlimited if he uses SMTP)
  • Enter the title and the reply address
  • Write the body with a tiny MCE editor
  • Enter the SMTP details if needed
  • Click the button, the form is hidden, but the page don't reload (as we are going to use AJAX)
  • Show a message, success or failure
Things we should now
  • Working with AJAX
  • Working with Django
  • Working with the mail API
  • some design
Things we should go through
  • Designing the user interface (HTML)
  • Coding the mass mail class with django
  • relying between the Django class and the HTML with Ajax
Should we start?

Sunday, July 27, 2008

Python and Django code editors

Now we enter the development phase, so an editor is needed. We are going to focus on a Python editor, but we also prefer that it's a django one, so things will be more easier.
To not search the web, Python official website, published a list of editors. You can check this list of Python editors.

If we are going to search for a simple editor, so why not only use note pad. There's many editors on the Python editors list, some don't create .py files even; but the most are simple editors that just highlight your code and this is really stupid and won't help us.

What we need exactly is an IDE (Integrated Dev elopement Environment). It's possible to find a high quality and free IDE on the web, so the quest is to search. I find many, but no one was good and helpful. I don't really know how to find it.

Perhaps, because I'm searching a very advanced one, like Visual Studio. Ohh, I have read a thread in Reddit, the guy asks what text editor do you use with Django. The good users didn't give a link, so I had to search every term they put; I focus on the editors but they were awful!

Ok, you are searching for an advanced, professional, IDE for pyhton and Django. Don't search I already had done it.
Wing IDE is good, many features are in. It's advanced and for professional use. You can check out the screen shots. But what can I say, it's paying. And we are working Open Source for the community. It really sucks to pay $179 and additional $30 for a cover and also shipping costs :p

Waak, yet another Pyhton, ruby, php IDE. It's called Aptana Studio. It looks smart and pro, but sucks $99, oh no that's only for Pro edition. There's the community edition. (it's free).
It works on Mac, windows and linux. So joy for all Python programmers.
You should ask, why there's two version, one free and one not! Ok, those version aren't different, the pro just inlcude a support and pro plug-ins. Which may be not necessary so much. If it's then you must pay :)
Ok, let's quit those money suckers. Here's the Open Source IDE for Python and Django!
NetBeans, that's it! But I would prefer Aptana. Ok, download them both and decide what to choose.

Hope it helps! Know an IDE? Let me hear from you!

Django Platform for Google App Engine

I was surfing those days Google App Engine websites and found that the most popular and used platform to work with Google App Engine is Django. Luckily, it's already included on Google App Engine SDK in the lib folder. But I always give a hit for the official website and so you can do and visit the Django website.

The website documentation is so cool, more than that I found free book, you can get it here.
But what's Django and how it works?
As I said Django is a python Framework, written in pure python, then the matter is to know python and then Django will only accelerate your work
At its core, Django is simply a collection of libraries written in the Python programming language. To develop a site using Django, you write Python code that uses these libraries. Learning Django, then, is a matter of learning how to program in Python and understanding how the Django libraries work.
From the Django book
Ok, so we have to come back to Python, oh yes, here's a small comparision between python and django.
The example (found it in the django book) displays the ten most recently published books from a database.
The sample written in Pure Python

#!/usr/bin/python

import MySQLdb

print "Content-Type: text/html"
print
print "<html><head><title>Books</title></head>"
print "<body>"
print "<h1>Books</h1>"
print "<ul>"

connection = MySQLdb.connect(user='me', passwd='letmein', db='my_db')
cursor = connection.cursor()
cursor.execute("SELECT name FROM books ORDER BY pub_date DESC LIMIT 10")
for row in cursor.fetchall():
print "<li>%s</li>" % row[0]

print "</ul>"
print "</body></html>"

connection.close()

The sample written in Django

# models.py (the database tables)

from django.db import models

class Book(models.Model):
name = models.CharField(maxlength=50)
pub_date = models.DateField()


# views.py (the business logic)

from django.shortcuts import render_to_response
from models import Book

def latest_books(request):
book_list = Book.objects.order_by('-pub_date')[:10]
return render_to_response('latest_books.html', {'book_list': book_list})


# urls.py (the URL configuration)

from django.conf.urls.defaults import *
import views

urlpatterns = patterns('',
(r'latest/$', views.latest_books),
)


# latest_books.html (the template)

<html><head><title>Books</title></head>
<body>
<h1>Books</h1>
<ul>
{% for book in book_list %}
<li>{{ book.name }}</li>
{% endfor %}
</ul>
</body></html>


I know that most of you will see that the django code is harder. Yes, it's longer and harder but smarter to use. I will prefer to use long code, then easily type book.name to display the latest books. The framework aims to make easy long and big application development.
Interested on Microsoft Technologies? Read Visual Studio Dot Net