Developing Software As A Service App with Python & Django
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share

Developing Software As A Service App with Python & Django

  • 5,488 views
Uploaded on

 

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
5,488
On Slideshare
5,488
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
114
Comments
0
Likes
4

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Developing Software As A Service with Python & Django Allan Spartacus Mangune, CPA, MsCISFriday, January 18, 13
  • 2. Allan Spartacus Mangune Certified Public Accountant MSCIS - University of Phoenix Certified Scrum Master Certifed Ethical Hacker Microsoft MVP for ASP.NET 6 years in public accounting 13 years in software development and consultingFriday, January 18, 13
  • 3. Taughtworks, Inc. Microsoft Certified Partner for Learning Solutions 2/F Liberty Plaza Building, H. V. Dela Costa Street, Makati CityFriday, January 18, 13
  • 4. Our New Office 5/F 6784 Ayala Avenue corner V.A. Rufino Street, Makati CityFriday, January 18, 13
  • 5. Agenda Software As A Service For Small Businesses Procurement and Inventory Management Sales Order and Invoicing Management Customer Relationship Management Technologies Python, Django, Memcache, & Postgresql Deployment and MaintenanceFriday, January 18, 13
  • 6. Primogul Customer Procurement Inventory Sales Order Sales Invoice Relation Cost Revenue 200 150 100 50 2007 2008 0 2009 2010 Reports and Analytics EnginesFriday, January 18, 13
  • 7. Procurement Maintain information about vendors Use purchase orders to order inventory items Manage receipts of goods Manage billings from vendorsFriday, January 18, 13
  • 8. Inventory Manage inventory information, location and movements Physical inventory count Inventory worksheets Inventory adjustments Inventory valuationFriday, January 18, 13
  • 9. Sales Order Create quotations for customers Convert quotations to sales invoice or order Create sales orders Allocate inventory items to sales ordersFriday, January 18, 13
  • 10. Sales Invoice Invoice customers for delivered goods or servicesFriday, January 18, 13
  • 11. Software As A Service Software on-demand Multi-tenant environment Pricing is based on number of seats and usage parametersFriday, January 18, 13
  • 12. Technologies Python Django Postgresql MemcacheFriday, January 18, 13
  • 13. Python 101Friday, January 18, 13
  • 14. Python Powerful and easy to learn programming language Requires an interpreter to run Python interpreter and libraries can be downloaded from python.org Runs on Mac OS X, Unix, and WindowsFriday, January 18, 13
  • 15. Invoking the Interpreter Allan-Spartacus-Mangunes-MacBook-Pro:~ allan$ python Python 2.7.2 (default, Jun 20 2012, 16:23:33) [GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>>Friday, January 18, 13
  • 16. Variables The equal (‘=’) sign is used to assign a value length = 40 A value can be assigned to several variables a=b=c=d=6 A variable must be assigned with a value prior to using itFriday, January 18, 13
  • 17. Lists Expressed a list of values separated by a comma Placed between square brackets [ ] Can be of different types x = [‘hello’, ‘world’, 101, 88] Indices begins at 0 x[0] equals ‘hello’ x[3] equals 88Friday, January 18, 13
  • 18. Control Flow while statement if statement for statementFriday, January 18, 13
  • 19. while Statement while loop executes while the condition is true while {condition}: {run the code} {have it indented} Example >>> x, y = 0, 1 >>> while y < 12: ... print y ... x, y = y, x+y ... 1 1 2 3 5 8Friday, January 18, 13
  • 20. if Statement If the condition is true, the code block is executed if {condition}: {run the code} {have it indented} Example >>> a = int(raw_input(Please enter a number: )) >>> a = int(raw_input(Please enter a number: )) Please enter a number: 24 Please enter a number: 0 >>> if a < 0: >>> if a < 0: ... print "You entered a number lower than zero" ... print "You entered a number lower than zero" ... else: ... elif a == 0: ... print "You entered a number greater than zero" ... print "You entered a number zero" ... ... else: You entered a number greater than zero ... print "You entered a number greater than zero" ... You entered a number zeroFriday, January 18, 13
  • 21. for Statement Iterates over the items for {i in list}: {run the code} {have it indented} Example >>> list = [dog, cat, mouse] >>> for i in list: ... print i, len(i) ... dog 3 cat 3 mouse 5Friday, January 18, 13
  • 22. Functions Define def foo(arguments): {run the code} {have it indented} Example >>> def foo(num): ... x, y = 0, 1 ... while y < num: ... print y ... x, y = y, x+y ... >>> foo(20) 1 1 2 3 5Friday, January 18, 13
  • 23. Classes Blueprint of an object Provide the fundamental features of Object-Oriented Programming Can inherit from multiple base classes An instance can be modified during runtime Data members and member methods are public. Member methods are virtual Conventions tells us that member that begins with an underscore ‘_’ shall be treated as privateFriday, January 18, 13
  • 24. Class Definition/Instance Simplest form: class Foo: <statement_1> . . . <statement_2> Statements inside a class are usually method definitions class Foo: def bar(num): x, y = 0, 1 while y < num: print y x, y = y, x+yFriday, January 18, 13
  • 25. Django 101Friday, January 18, 13
  • 26. Django “Web framework for for perfectionists with deadlines” - djangoproject.com High-level Python Web frameworkFriday, January 18, 13
  • 27. Django Framework Object-relational mapper - Define data models entirely in Python Automatic admin interface - Production-ready user interface to add/update contents Elegant URL design - cruft-free URL Template system - Extensible template language Cache system - Hooked into memcache Internalization - Multi-language support Source: djangoproject.comFriday, January 18, 13
  • 28. Sites that Use Django Disqus Instagram Mozilla OpenStack Pinterest PolitiFact.com Rdio Source: djangoproject.comFriday, January 18, 13
  • 29. Installing Django Requires Python python.org Usually installed on Mac OS X, Other Unix system You may need to set up your database engine like Postgresql, Mysql or Oracle Install a version for specific operating system Get the official release Latest version is 1.4.3 python > import djangoFriday, January 18, 13
  • 30. Creating Django app Auto-generate the code to establish the project Create a project directory django-admin.py startproject blog Project structure demo/ manage.py blog/ __init__.py settings.py urls.py wsgi.pyFriday, January 18, 13
  • 31. Django Development Server Lightweight web server written in Python You can use this during development Allan-Spartacus-Mangunes-MacBook-Pro:blog allan$ python manage.py runserver Validating models... 0 errors found Django version 1.4.1, using settings blog.settings Development server is running at http://127.0.0.1:8000/ Don’t use this server in the productionFriday, January 18, 13
  • 32. Setting up Database Edit the blog/settings.py Python module that contains Django settings Change the keys in the DATABASES DATABASES = { default: { ENGINE: django.db.backends.sqlite3, # Add postgresql_psycopg2, mysql, sqlite3 or oracle. NAME: /Users/allan/demo/blog/blog.db, # Or path to database file if using sqlite3. USER: , # Not used with sqlite3. PASSWORD: , # Not used with sqlite3. HOST: , # Set to empty string for localhost. Not used with sqlite3. PORT: , # Set to empty string for default. Not used with sqlite3.Friday, January 18, 13
  • 33. INSTALLED_APPS Holds the names of activated applications INSTALLED_APPS = ( django.contrib.auth, django.contrib.contenttypes, django.contrib.sessions, django.contrib.sites, django.contrib.messages, django.contrib.staticfiles, ) Each app holds one database table Allan-Spartacus-Mangunes-MacBook-Pro:blog allan$ python manage.py syncdb Creating tables ... Creating table auth_permission Creating table auth_group_permissions Creating table auth_group Creating table auth_user_user_permissions Creating table auth_user_groups Creating table auth_user Creating table django_content_type Creating table django_session Creating table django_siteFriday, January 18, 13
  • 34. Models Project vs App An App is a web application that contains functionalities A Project is a collection of Apps To create an App Allan-Spartacus-Mangunes-MacBook-Pro:blog allan$ python manage.py startapp entries Allan-Spartacus-Mangunes-MacBook-Pro:blog allan$ ls entries __init__.py! models.py! tests.py!views.py The entries/ directory holds the blog entries applicationFriday, January 18, 13
  • 35. Models Define models database layouts with metadata Edit entries/models.py from django.db import models class Entry(models.Model): text = models.CharField(max_length=2000) pub_date = models.DateTimeField(date published) The model tells Django to create the db schema and database-access APIFriday, January 18, 13
  • 36. Model activation Edit the settings.py file and add ‘entries’ INSTALLED_APPS = ( django.contrib.auth, django.contrib.contenttypes, django.contrib.sessions, django.contrib.sites, django.contrib.messages, django.contrib.staticfiles, entries ) Create the tables Allan-Spartacus-Mangunes-MacBook-Pro:blog allan Allan-Spartacus-Mangunes-MacBook-Pro:blog allan $ python manage.py sql entries $ python manage.py syncdb BEGIN; Creating tables ... CREATE TABLE "entries_entry" ( Creating table entries_entry "id" integer NOT NULL PRIMARY KEY, Installing custom SQL ... "text" varchar(2000) NOT NULL, Installing indexes ... "pub_date" datetime NOT NULL Installed 0 object(s) from 0 fixture(s) ) Allan-Spartacus-Mangunes-MacBook-Pro:blog allan ; $ COMMIT;Friday, January 18, 13
  • 37. Activating Admin Site Not activated by default To activate: Uncomment ‘django.contrib.admin’ in the INSTALLED_APPS INSTALLED_APPS = ( django.contrib.auth, Allan-Spartacus-Mangunes-MacBook-Pro:blog django.contrib.contenttypes, allan$ python manage.py syncdb django.contrib.sessions, Creating tables ... django.contrib.sites, Creating table django_admin_log django.contrib.messages, Installing custom SQL ... django.contrib.staticfiles, Installing indexes ... django.contrib.admin, Installed 0 object(s) from 0 fixture(s) ) Edit the blog/urls.py Allan-Spartacus-Mangunes-MacBook-Pro:blog # Uncomment the next two lines to enable allan$ python manage.py runserver the admin: Validating models... from django.contrib import admin admin.autodiscover() 0 errors foundFriday, January 18, 13
  • 38. Setting up Views Represented by a Python function Requires you to set up the URL in the URLconf module ROOT_URLCONF setting ROOT_URLCONF = blog.urls Edit blog/urls.py urlpatterns = patterns(, url(r^entries/$, entries.views.index), # Uncomment the next line to enable the admin: url(r^admin/, include(admin.site.urls)), )Friday, January 18, 13
  • 39. Setting up Views Write a view function on entries/views.py from django.template import Context, loader from entries.models import Entry from django.http import HttpResponse def index(request): latest_entry_list = Entry.objects.all().order_by(-pub_date)[:5] t = loader.get_template(entries/index.html) c = Context({ latest_entry_list: latest_entry_list }) return HttpResponse(t.render(c)) Create a template file {% if latest_entry_list %} <ul> {% for entry in latest_entry_list TEMPLATE_DIRS = ( %} /Users/allan/demo/blog/templates, <li><a href="/entries/ ) {{entry.id}}">{{entry.text}}</a></li> {% endfor %} </ul> {% endif %}Friday, January 18, 13
  • 40. Q and AFriday, January 18, 13
  • 41. Allan Spartacus Mangune allan@taughtworks.com facebook.com/manguneFriday, January 18, 13
  • 42. THANK YOUFriday, January 18, 13