Sie sind auf Seite 1von 23

Sharing

technology VOC

Bambang Puji Haryo Wicaksono

Tehnology Utilisation

Python

Developed in 1991, for riset and academics


Easy to learn, clean syntax, high level data structure
Used by NASA
https://www.python.org/about/success/usa/
Interpreted, not compiled
Machine code makes script running faster, than
bytecode
Example:
>>> a,b = 10,1
>>> print i for i in range(a)

Django Framework

Python based
Mature. Developed in 2004
No need raw SQL
Clean development OOP or procedural
High level programming focus on business
Example:

a = Orang(nama=Denisya Aulia,umur=22)
b = Orang(nama=Heksa Tri Dirgantara)
b.umur = 22
x = Orang.objects.get(nama=Denisya)
x = Orang.objects.filter(nama__contains=nisya)

Postgresql

Open source, means free to use


ORDBMS object relational DBMS
Close to Oracle character (atomic)
Most of hosting nowadays offering Postgres as
MySQL alternative

Benchmark

VOC v.1 dan v.2 (B2B)


PHP
MySQL
Costly maintenance

Traveloka (B2C)

Scala
Play framework
Oracle maybe
Continuous development will change depends on technology

Other travel-commerce (B2C)


Java and MySQL

Blibli (B2C)
RoR
Hybrid SQL MongoDB and Oracle/Postgres and/or AmazonAWS

Preparations

Internet connections
Coding tools:
Minimum requirements: 32bit Windows XP, 2GB RAM

Editor: Sublime (recommended)


http://www.sublimetext.com/download

Pyhton 2.7 and Postgresql 9.2 preinstalled:


http://www.python.org/download
http://www.postgresql.org/download

Internet explorer only


Filezilla and putty

First time Python

Open your cmd.exe


Type python
If apps is not recognized, means you have to
setup python installation directory to the PATH
on environment variables
Three chevron means youre in
Just type: print Hello world

Python library

Pip 7.1.0 https://pypi.python.org/pypi/pip /


Easy Install (setuptools 16.0) https://pypi.python.org/pypi/setuptools
BeautifulSoup 4 pip install BeautifulSoup
Django 1.9 pip install django
Html5lib 0.9 pip install html5lib
Lxml 3.4.4 pip install lxml
PIL http://pythonware.com/products/pil /
Pillow 2.9.0 pip install pillow
Pyscopg2 2.6.1 pip install psycopg2 or http://initd.org/psycopg/download /
pymemcache 1.3.3 pip install pymemcache
pyOpenSSL 0.15.1 pip install pyopenssl
pytz pip install pytz
requests pip install requests
Suds pip install suds
Urllib3 pip install urllib3

PostgreSQL

Install PostgreSQL using official Windows installer


.msi or .exe
Set database name to voc3 (biar sama)
Set your postgres password, but remember when
deploy, change this with the same name with
production
Create table, name up to you, eg: person. Create
column, eg: name, dob. Fill it with your family data
Install psycopg2, test using connection script
If everythings well, you could go to the next slide
(Django)

PostgreSQL (contd)

Connection script:
1. import psycopg2
2. try:
3.
conn = psycopg2.connect("dbname='test' user='postgres'
host='localhost' password='bambang'")
4. except:
5.
print "I am unable to connect to the database"
6. cur = conn.cursor()
7. cur.execute("""SELECT satu from test""")
8. rows = cur.fetchall()
9. print "\nShow me the databases:\n"
10.for row in rows:
11.
print "
", row[0]

Your first Django


shoot

Open cmd.exe
Go to your d:\
Type django-admin startproject myvoc
Type cd myvoc
Type python manage.py runserver
Open browser and type http://localhost:8000
on URL bar
Should you see your first apps run

Localhost should like

Django directory
structure

myvoc
manage.py
myvoc

__init__.py
settings.py
urls.py
wsgi.py

Django DB
connection

Open settings.py
Change DATABASES into something like this:

>>> python manage.py migrate


New default security table from Django will
generated

Playing with data

>>> python manage.py startapp engine


Open models.py

Generate table

>>> python manage.py makemigrations


>>> python manage.py migrate

Create Data

>>> python manage.py shell


>>> from engine.models import Negara, Kota
>>> n = Negara(nama=Indonesia)
>>> n.save()
>>> n.id
>>> k = Kota(negara=n, nama=Jakarta,
bandara=Soekarno-Hatta)
>>> k.save()

Add Column

Change your models.py


Add kode_iata and save

>>> python manage.py makemigrations


>>> python manage.py migrate

Retrieve Data

>>> n = Negara.objects.get(id=1)
>>> n.nama
>>> k =
Kota.objects.filter(nama__startswith=Jakarta)
>>> k =
Kota.objects.filter(negara__nama__exact=Indon
esia)
Bedakan get dan filter:
Get hanya 1 row
Filter list

Update and Delete

>>> k = Kota.objects.get(nama=Solo)
>>> k.nama = Surakarta
>>> k.save()
>>> k.nama
Surakarta
>>> k.delete()

Problems?

Re-check you installation


Incompatible version
Incompatible OS
Last option: try using Linux distribution (not
recommended, harder than windows)

Das könnte Ihnen auch gefallen