Easy Web Project Development & Management with Django & Mercurial

50 %
50 %
Information about Easy Web Project Development & Management with Django & Mercurial
How-to & DIY

Published on June 4, 2009

Author: widoyo

Source: slideshare.net

Easy Web Project Development and Management with Django & Mercurial Widoyo <widoyo@gmail.com>

Why? MVC = Model View Controller Django > MTV = Model Template View Many software developer does not track their code

MVC = Model View Controller

Django > MTV = Model Template View

Many software developer does not track their code

The Project Human Resource Management Software (simplified) Web base application 100% using Open Source Software Source Code are well Manage

Human Resource Management Software (simplified)

Web base application

100% using Open Source Software

Source Code are well Manage

HRM Data to Cover HR Data {Nama, Alamat, Hp, Lahir, email, masuk} Training {judul, mulai, akhir, kota}

HR Data {Nama, Alamat, Hp, Lahir, email, masuk}

Training {judul, mulai, akhir, kota}

Open Source Software Ubuntu Desktop + Server 8.04.2 Python 2.5.2 Django 1.0.final Sqlite 3.4.2 Mercurial DSCM 0.9.5

Ubuntu Desktop + Server 8.04.2

Python 2.5.2

Django 1.0.final

Sqlite 3.4.2

Mercurial DSCM 0.9.5

Ubuntu Linux for human being LTS = Long Term Support (5 year) Latest = 9.04 (9 means 2009, 04 means April) Varian Desktop Server Netbook Remix

Linux for human being

LTS = Long Term Support (5 year)

Latest = 9.04 (9 means 2009, 04 means April)

Varian

Desktop

Server

Netbook Remix

Python Python is a dynamic object-oriented programming language that can be used for many kinds of software development. ... and can be learned in a few days . Many Python programmers report substantial productivity gains and feel the language encourages the development of higher quality, more maintainable code . &quot; Python has been an important part of Google since the beginning, and remains so as the system grows and evolves. ...”

Python is a dynamic object-oriented programming language that can be used for many kinds of software development. ... and can be learned in a few days . Many Python programmers report substantial productivity gains and feel the language encourages the development of higher quality, more maintainable code .

&quot; Python has been an important part of Google since the beginning, and remains so as the system grows and evolves. ...”

Django The web framework for perfectionists with deadline Python base web framework http://djangoproject.com http://djangobook.com http://djangoinstant.com

The web framework for perfectionists with deadline

Python base web framework

http://djangoproject.com

http://djangobook.com

http://djangoinstant.com

SQlite SQLite is a software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine. SQLite is the most widely deployed SQL database engine in the world. http://sqlite.org

SQLite is a software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine. SQLite is the most widely deployed SQL database engine in the world.

http://sqlite.org

Mercurial a fast, lightweight Source Control Management system designed for efficient handling of very large distributed projects. http://selenic.com/mercurial

a fast, lightweight Source Control Management system designed for efficient handling of very large distributed projects.

http://selenic.com/mercurial

Install Come with Ubuntu: Python 2.5.2 (default), Sqlite3 Mercurial $sudo apt-get install mercurial Django Download django-<ver>.tar.gz $tar -vzxf django-<ver>.tar.gz $cd django-ver $sudo python setup.py install

Come with Ubuntu:

Python 2.5.2 (default), Sqlite3

Mercurial

$sudo apt-get install mercurial

Django

Download django-<ver>.tar.gz

$tar -vzxf django-<ver>.tar.gz

$cd django-ver

$sudo python setup.py install

Let's Start Project skeleton $django-admin.py startproject hrapp $cd hrapp $python manage.py runserver (test It Worked!) $chmod 755 manage.py $gvim settings.py (for Database & django.contrib.admin) $./manage.py syncdb (populate database & create super user)

Project skeleton

$django-admin.py startproject hrapp

$cd hrapp

$python manage.py runserver (test It Worked!)

$chmod 755 manage.py

$gvim settings.py (for Database & django.contrib.admin)

$./manage.py syncdb (populate database & create super user)

Creating Application Creating Application $./manage.py startapp apps Creating Models Person {Nama, Alamat, Hp, Lahir, email, masuk} $gvim apps/models.py Activating application & generating table $gvim settings.py (install 'apps' into INSTALLED_APPS) $./manage.py syncdb

Creating Application

$./manage.py startapp apps

Creating Models

Person {Nama, Alamat, Hp, Lahir, email, masuk}

$gvim apps/models.py

Activating application & generating table

$gvim settings.py (install 'apps' into INSTALLED_APPS)

$./manage.py syncdb

Files apps/models.py from django.db import models class Person(models.Model): nama = models.CharField(max_length=50) alamat = models.CharField(max_length=200) hp = models.CharField(max_length=35, blank=True, null=True) lahir = models.DateField() masuk = models.DateField() settings.py DATABASE_ENGINE = 'sqlite3' DATABASE_NAME = '/tmp/hrapp.db' . . . INSTALLED_APPS = ( . 'django.contrib.admin', 'hrapp.apps', )

apps/models.py

from django.db import models

class Person(models.Model):

nama = models.CharField(max_length=50)

alamat = models.CharField(max_length=200)

hp = models.CharField(max_length=35, blank=True, null=True)

lahir = models.DateField()

masuk = models.DateField()

settings.py

DATABASE_ENGINE = 'sqlite3'

DATABASE_NAME = '/tmp/hrapp.db'

.

.

.

INSTALLED_APPS = (

.

'django.contrib.admin',

'hrapp.apps',

)

Activating 'admin' Interface $gvim urls.py from django.contrib.admin import admin admin.autodiscover() . . (r'^admin/(.*)', admin.site.root), $gvim apps/admin.py (to manage Person Data) from hrapp.apps.models import Person from django.contrib import admin class PersonAdmin(admin.ModelAdmin): list_display = ['nama', 'alamat','hp','masuk','lahir'] admin.site.register(Person, PersonAdmin)

$gvim urls.py

from django.contrib.admin import admin

admin.autodiscover()

.

.

(r'^admin/(.*)', admin.site.root),

$gvim apps/admin.py (to manage Person Data)

from hrapp.apps.models import Person

from django.contrib import admin

class PersonAdmin(admin.ModelAdmin):

list_display = ['nama', 'alamat','hp','masuk','lahir']

admin.site.register(Person, PersonAdmin)

Check-in Into Repository $hg init $hg add $hg commit –m -'Initial project'

$hg init

$hg add

$hg commit –m -'Initial project'

Creating Training Data Model apps/models.py class Training(models.Model): person = models.ForeignKey(Person) judul = models.CharField(max_length=200) mulai = models.DateField() akhir = models.DateField() kota = models.CharField(max_length=35) $./manage.py syncdb Check-in repository $hg commit

apps/models.py

class Training(models.Model):

person = models.ForeignKey(Person)

judul = models.CharField(max_length=200)

mulai = models.DateField()

akhir = models.DateField()

kota = models.CharField(max_length=35)

$./manage.py syncdb

Check-in repository

$hg commit

Creating 'admin' for Training Training inline to Person $gvim apps/admin.py from hrapp.apps.models import Person, Training ... class TrainingInline(admin.StackedInline): model = Training extra = 3 class PersonAdmin(admin.ModelAdmin): list_display = ['nama', 'alamat','hp','masuk','lahir'] inlines = [TrainingInline] ...

Training inline to Person

$gvim apps/admin.py

from hrapp.apps.models import Person, Training

...

class TrainingInline(admin.StackedInline):

model = Training

extra = 3

class PersonAdmin(admin.ModelAdmin):

list_display = ['nama', 'alamat','hp','masuk','lahir']

inlines = [TrainingInline]

...

Customize Admin Adding 'search' Adding 'filter' apps/admin.py search_fields = ['nama'] list_filter = ['kota'] $hg commit

Adding 'search'

Adding 'filter'

apps/admin.py

search_fields = ['nama']

list_filter = ['kota']

$hg commit

Public Interface: Homepage Homepage $gvim urls.py from hrapp.apps.views import homepage (r'^$', homepage) $gvim apps/views.py from django.http import HttpResponse def homepage(request): return HttpResponse(“Hello RICE Expo”) $hg commit

Homepage

$gvim urls.py

from hrapp.apps.views import homepage

(r'^$', homepage)

$gvim apps/views.py

from django.http import HttpResponse

def homepage(request):

return HttpResponse(“Hello RICE Expo”)

$hg commit

Public Interface: Person Data List $gvim urls.py from django.shortcuts import render_to_response from hrapp.apps.views import homepage, person_list (r'^person/', person_list) $gvim apps/views.py from django.http import HttpResponse def person_list(request): person_list = Person.objects.all() return render_to_response('person_list.html', {'person_list': person_list}) $gvim templates/person_list.html <table> {% for person in person_list %} <tr><td>{{ person.nama }}</td><td>{{ person.alamat }}</td></tr> {% endfor %} </table>

List

$gvim urls.py

from django.shortcuts import render_to_response

from hrapp.apps.views import homepage, person_list

(r'^person/', person_list)

$gvim apps/views.py

from django.http import HttpResponse

def person_list(request):

person_list = Person.objects.all()

return render_to_response('person_list.html', {'person_list': person_list})

$gvim templates/person_list.html

<table>

{% for person in person_list %}

<tr><td>{{ person.nama }}</td><td>{{ person.alamat }}</td></tr>

{% endfor %}

</table>

Person Data Detail $gvim urls.py from hrapp.apps.views import homepage, person_list, person_detail (r'^person/', person_list), (r'^person/(?P<object_id>)/$', person_detail ), $gvim apps/views.py def person_detail(request, object_id): person = Person.objects.get(id=object_id) return render_to_response('person_detail.html', {'person': person}) $gvim templates/person_detail.html <h1>{{ person.nama }}</h1> <i>{{ person.alamat }}</i> {% if person.training_set.all %}<ol> {% for training in person.training_set.all %}<li>{{ training.judul }}<li>{% endfor %}</ol> {% else %} <p>Belum ada riwayat training</p> {% endif %}

Detail

$gvim urls.py

from hrapp.apps.views import homepage, person_list, person_detail

(r'^person/', person_list),

(r'^person/(?P<object_id>)/$', person_detail ),

$gvim apps/views.py

def person_detail(request, object_id):

person = Person.objects.get(id=object_id)

return render_to_response('person_detail.html', {'person': person})

$gvim templates/person_detail.html

<h1>{{ person.nama }}</h1>

<i>{{ person.alamat }}</i>

{% if person.training_set.all %}<ol>

{% for training in person.training_set.all %}<li>{{ training.judul }}<li>{% endfor %}</ol>

{% else %}

<p>Belum ada riwayat training</p>

{% endif %}

Django Pattern Urls >> View (method) >> Template URLConf Loose coupling Mapping between url and method to execute

Urls >> View (method) >> Template

URLConf

Loose coupling

Mapping between url and method to execute

Better Page Layout Creating

Creating

Add a comment

Related presentations

Related pages

Django Packages : Project Management

Project management web ... new django projects Project management application with task tracker and repository backend integration ... Mercurial. Git ...
Read more

ProjectsUsingMercurial - Mercurial

Some Projects that Use Mercurial. ... Zine blogging system and other Python web projects . ... project localization platform with an easy to use web ...
Read more

Django

Django is an open source project, ... "Easy Pickings" Tickets: ... The current branch under active development is Django 1.11.
Read more

DjangoSuccessStoryBitbucket – Django

Bitbucket is a hosting service for projects using Mercurial or Git. It is built almost entirely on Django. ... The tedious stuff of web development is ...
Read more

django-projector 0.2.0 : Python Package Index

Project management Django application with task tracker and repository ... Mercurial repository integration; Easy repositories ... Repository web browser;
Read more

Django documentation | Django documentation | Django

... Django or Web application development. ... Web framework. Its goal is to make it as easy as ... development process for the Django project ...
Read more

Python Web Development with Django® [Book] - Safari

... Selection from Python Web Development with Django® ... Easy Install; IPython; ... Version Control for Your Project; Project Management Software. Trac ...
Read more

Mercurial SCM

... distributed source control management tool. It efficiently handles projects of any size and offers an easy ... Mercurial efficiently handles projects ...
Read more