際際滷

際際滷Share a Scribd company logo
Developing Software As A
          Service with Python &
          Django
          Allan Spartacus Mangune, CPA, MsCIS




Friday, January 18, 13
Allan Spartacus Mangune
                Certi鍖ed Public Accountant
                MSCIS - University of Phoenix
                Certi鍖ed Scrum Master
                Certifed Ethical Hacker
                Microsoft MVP for ASP.NET
                6 years in public accounting
                13 years in software development and consulting


Friday, January 18, 13
Taughtworks, Inc.


                Microsoft Certi鍖ed Partner for Learning Solutions
                2/F Liberty Plaza Building, H. V. Dela Costa Street,
                Makati City




Friday, January 18, 13
Our New Of鍖ce




                5/F 6784 Ayala Avenue corner V.A. Ru鍖no Street, Makati City

Friday, January 18, 13
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 Maintenance

Friday, January 18, 13
Primogul

                                                                                    Customer
                  Procurement   Inventory        Sales Order        Sales Invoice
                                                                                     Relation



                                              Cost    Revenue
                                                                      200
                                                                      150
                                                                     100
                                                                     50
                                            2007 2008                0
                                                      2009   2010
                                      Reports and Analytics Engines




Friday, January 18, 13
Procurement

                Maintain information about vendors
                Use purchase orders to order inventory items
                Manage receipts of goods
                Manage billings from vendors




Friday, January 18, 13
Inventory

                Manage inventory information, location and movements
                Physical inventory count
                Inventory worksheets
                Inventory adjustments
                Inventory valuation




Friday, January 18, 13
Sales Order

                Create quotations for customers
                Convert quotations to sales invoice or order
                Create sales orders
                Allocate inventory items to sales orders




Friday, January 18, 13
Sales Invoice



                Invoice customers for delivered goods or services




Friday, January 18, 13
Software As A Service


                Software on-demand
                Multi-tenant environment
                Pricing is based on number of seats and usage
                parameters




Friday, January 18, 13
Technologies

                Python
                Django
                Postgresql
                Memcache




Friday, January 18, 13
Python 101




Friday, January 18, 13
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 Windows




Friday, January 18, 13
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
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
                it



Friday, January 18, 13
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 88

Friday, January 18, 13
Control Flow


                while statement
                if statement
                for statement




Friday, January 18, 13
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
                  8
Friday, January 18, 13
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 zero

Friday, January 18, 13
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 5




Friday, January 18, 13
Functions
             De鍖ne
              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
                 5
Friday, January 18, 13
Classes
                Blueprint of an object
                Provide the fundamental features of Object-Oriented
                Programming
                Can inherit from multiple base classes
                An instance can be modi鍖ed 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 private
Friday, January 18, 13
Class De鍖nition/Instance
                Simplest form:
                 class Foo:
                     <statement_1>
                     .
                     .
                     .
                     <statement_2>

                Statements inside a class are usually method
                de鍖nitions
                 class Foo:
                    def bar(num):
                      x, y = 0, 1
                          while y < num:
                             print y
                             x, y = y, x+y




Friday, January 18, 13
Django 101




Friday, January 18, 13
Django


                Web framework for for perfectionists with deadlines -
                djangoproject.com
                High-level Python Web framework




Friday, January 18, 13
Django Framework

                Object-relational mapper - De鍖ne 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.com

Friday, January 18, 13
Sites that Use Django

                Disqus
                Instagram
                Mozilla
                OpenStack
                Pinterest
                PolitiFact.com
                Rdio
                                  Source: djangoproject.com

Friday, January 18, 13
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 speci鍖c operating system
                Get the of鍖cial release
                Latest version is 1.4.3
                         python > import django
Friday, January 18, 13
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.py




Friday, January 18, 13
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/


                Dont use this server in the production




Friday, January 18, 13
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
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_site




Friday, January 18, 13
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 application


Friday, January 18, 13
Models
                De鍖ne 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 API


Friday, January 18, 13
Model activation
                Edit the settings.py 鍖le 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
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 found

Friday, January 18, 13
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(/slideshow/developing-software-as-a-service-app-with-python-django/16048083/r&),

                # Uncomment the next line to enable the admin:
                url(/slideshow/developing-software-as-a-service-app-with-python-django/16048083/r&)),
          )




Friday, January 18, 13
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 鍖le
                                                        {% 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
Q and A




Friday, January 18, 13
Allan Spartacus Mangune
                  allan@taughtworks.com
                 facebook.com/mangune


Friday, January 18, 13
THANK YOU




Friday, January 18, 13

More Related Content

Developing Software As A Service App with Python & Django

  • 1. Developing Software As A Service with Python & Django Allan Spartacus Mangune, CPA, MsCIS Friday, January 18, 13
  • 2. Allan Spartacus Mangune Certi鍖ed Public Accountant MSCIS - University of Phoenix Certi鍖ed Scrum Master Certifed Ethical Hacker Microsoft MVP for ASP.NET 6 years in public accounting 13 years in software development and consulting Friday, January 18, 13
  • 3. Taughtworks, Inc. Microsoft Certi鍖ed Partner for Learning Solutions 2/F Liberty Plaza Building, H. V. Dela Costa Street, Makati City Friday, January 18, 13
  • 4. Our New Of鍖ce 5/F 6784 Ayala Avenue corner V.A. Ru鍖no Street, Makati City Friday, 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 Maintenance Friday, 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 Engines Friday, January 18, 13
  • 7. Procurement Maintain information about vendors Use purchase orders to order inventory items Manage receipts of goods Manage billings from vendors Friday, January 18, 13
  • 8. Inventory Manage inventory information, location and movements Physical inventory count Inventory worksheets Inventory adjustments Inventory valuation Friday, 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 orders Friday, January 18, 13
  • 10. Sales Invoice Invoice customers for delivered goods or services Friday, January 18, 13
  • 11. Software As A Service Software on-demand Multi-tenant environment Pricing is based on number of seats and usage parameters Friday, January 18, 13
  • 12. Technologies Python Django Postgresql Memcache Friday, 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 Windows Friday, 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 it Friday, 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 88 Friday, January 18, 13
  • 18. Control Flow while statement if statement for statement Friday, 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 8 Friday, 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 zero Friday, 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 5 Friday, January 18, 13
  • 22. Functions De鍖ne 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 5 Friday, 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 modi鍖ed 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 private Friday, January 18, 13
  • 24. Class De鍖nition/Instance Simplest form: class Foo: <statement_1> . . . <statement_2> Statements inside a class are usually method de鍖nitions class Foo: def bar(num): x, y = 0, 1 while y < num: print y x, y = y, x+y Friday, January 18, 13
  • 26. Django Web framework for for perfectionists with deadlines - djangoproject.com High-level Python Web framework Friday, January 18, 13
  • 27. Django Framework Object-relational mapper - De鍖ne 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.com Friday, January 18, 13
  • 28. Sites that Use Django Disqus Instagram Mozilla OpenStack Pinterest PolitiFact.com Rdio Source: djangoproject.com Friday, 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 speci鍖c operating system Get the of鍖cial release Latest version is 1.4.3 python > import django Friday, 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.py Friday, 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/ Dont use this server in the production Friday, 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_site Friday, 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 application Friday, January 18, 13
  • 35. Models De鍖ne 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 API Friday, January 18, 13
  • 36. Model activation Edit the settings.py 鍖le 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 found Friday, 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(/slideshow/developing-software-as-a-service-app-with-python-django/16048083/r&), # Uncomment the next line to enable the admin: url(/slideshow/developing-software-as-a-service-app-with-python-django/16048083/r&)), ) 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 鍖le {% 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 A Friday, January 18, 13
  • 41. Allan Spartacus Mangune allan@taughtworks.com facebook.com/mangune Friday, January 18, 13