SlideShare une entreprise Scribd logo
1  sur  42
Télécharger pour lire hors ligne
Developing Software As A
          Service with Python &
          Django
          Allan Spartacus Mangune, CPA, MsCIS




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


Friday, January 18, 13
Taughtworks, Inc.


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




Friday, January 18, 13
Our New Office




                5/F 6784 Ayala Avenue corner V.A. Rufino 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
             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
                 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 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 private
Friday, January 18, 13
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+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 - 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.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 specific operating system
                Get the official 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/


                Don’t 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
                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 API


Friday, January 18, 13
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
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(r'^entries/$', 'entries.views.index'),

                # Uncomment the next line to enable the admin:
                url(r'^admin/', include(admin.site.urls)),
          )




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 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
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

Contenu connexe

En vedette

The Best (and Worst) of Django
The Best (and Worst) of DjangoThe Best (and Worst) of Django
The Best (and Worst) of DjangoJacob Kaplan-Moss
 
2012 07 making disqus realtime@euro python
2012 07 making disqus realtime@euro python2012 07 making disqus realtime@euro python
2012 07 making disqus realtime@euro pythonAdam Hitchcock
 
Visdjango presentation django_boston_oct_2014
Visdjango presentation django_boston_oct_2014Visdjango presentation django_boston_oct_2014
Visdjango presentation django_boston_oct_2014jlbaldwin
 
Dev/Test Scenarios in the DevOps World
Dev/Test Scenarios in the DevOps WorldDev/Test Scenarios in the DevOps World
Dev/Test Scenarios in the DevOps WorldPranav Ainavolu
 
LCNUG 2015 - what's new for agile teams in TFS 2015
LCNUG 2015 -  what's new for agile teams in TFS 2015LCNUG 2015 -  what's new for agile teams in TFS 2015
LCNUG 2015 - what's new for agile teams in TFS 2015Angela Dugan
 
Data visualization in python/Django
Data visualization in python/DjangoData visualization in python/Django
Data visualization in python/Djangokenluck2001
 
Global Windows Azure Bootcamp : Samuel et Emilien Pécoul, Florent Pelet Legac...
Global Windows Azure Bootcamp : Samuel et Emilien Pécoul, Florent Pelet Legac...Global Windows Azure Bootcamp : Samuel et Emilien Pécoul, Florent Pelet Legac...
Global Windows Azure Bootcamp : Samuel et Emilien Pécoul, Florent Pelet Legac...MUG-Lyon Microsoft User Group
 
Package and distribute your Python code
Package and distribute your Python codePackage and distribute your Python code
Package and distribute your Python codeSanket Saurav
 
Sofware Fora de Séria 2016 - Implementando realtime no frontend
Sofware Fora de Séria 2016 - Implementando realtime no frontendSofware Fora de Séria 2016 - Implementando realtime no frontend
Sofware Fora de Séria 2016 - Implementando realtime no frontendWilliam Seiti Mizuta
 
Driven Development - Closing the Loop on Scrum
Driven Development - Closing the Loop on ScrumDriven Development - Closing the Loop on Scrum
Driven Development - Closing the Loop on ScrumAdam Englander
 
S.O.L.I.D. - Павел Кохан, Python Meetup 26.09.2014
S.O.L.I.D. - Павел Кохан, Python Meetup 26.09.2014S.O.L.I.D. - Павел Кохан, Python Meetup 26.09.2014
S.O.L.I.D. - Павел Кохан, Python Meetup 26.09.2014Python Meetup
 
Best Practices for Front-End Django Developers
Best Practices for Front-End Django DevelopersBest Practices for Front-End Django Developers
Best Practices for Front-End Django DevelopersChristine Cheung
 
Como DDD e Strategic Design estão nos ajudando a modernizar um Legado
Como DDD e Strategic Design estão nos ajudando a modernizar um LegadoComo DDD e Strategic Design estão nos ajudando a modernizar um Legado
Como DDD e Strategic Design estão nos ajudando a modernizar um LegadoLuiz Costa
 
Hexagonal Design in Django
Hexagonal Design in DjangoHexagonal Design in Django
Hexagonal Design in Djangomvschaik
 

En vedette (18)

The Best (and Worst) of Django
The Best (and Worst) of DjangoThe Best (and Worst) of Django
The Best (and Worst) of Django
 
2012 07 making disqus realtime@euro python
2012 07 making disqus realtime@euro python2012 07 making disqus realtime@euro python
2012 07 making disqus realtime@euro python
 
Visdjango presentation django_boston_oct_2014
Visdjango presentation django_boston_oct_2014Visdjango presentation django_boston_oct_2014
Visdjango presentation django_boston_oct_2014
 
Intro django
Intro djangoIntro django
Intro django
 
Dev/Test Scenarios in the DevOps World
Dev/Test Scenarios in the DevOps WorldDev/Test Scenarios in the DevOps World
Dev/Test Scenarios in the DevOps World
 
LCNUG 2015 - what's new for agile teams in TFS 2015
LCNUG 2015 -  what's new for agile teams in TFS 2015LCNUG 2015 -  what's new for agile teams in TFS 2015
LCNUG 2015 - what's new for agile teams in TFS 2015
 
Why Django
Why DjangoWhy Django
Why Django
 
Data visualization in python/Django
Data visualization in python/DjangoData visualization in python/Django
Data visualization in python/Django
 
Global Windows Azure Bootcamp : Samuel et Emilien Pécoul, Florent Pelet Legac...
Global Windows Azure Bootcamp : Samuel et Emilien Pécoul, Florent Pelet Legac...Global Windows Azure Bootcamp : Samuel et Emilien Pécoul, Florent Pelet Legac...
Global Windows Azure Bootcamp : Samuel et Emilien Pécoul, Florent Pelet Legac...
 
Package and distribute your Python code
Package and distribute your Python codePackage and distribute your Python code
Package and distribute your Python code
 
Sofware Fora de Séria 2016 - Implementando realtime no frontend
Sofware Fora de Séria 2016 - Implementando realtime no frontendSofware Fora de Séria 2016 - Implementando realtime no frontend
Sofware Fora de Séria 2016 - Implementando realtime no frontend
 
Driven Development - Closing the Loop on Scrum
Driven Development - Closing the Loop on ScrumDriven Development - Closing the Loop on Scrum
Driven Development - Closing the Loop on Scrum
 
S.O.L.I.D. - Павел Кохан, Python Meetup 26.09.2014
S.O.L.I.D. - Павел Кохан, Python Meetup 26.09.2014S.O.L.I.D. - Павел Кохан, Python Meetup 26.09.2014
S.O.L.I.D. - Павел Кохан, Python Meetup 26.09.2014
 
Best Practices for Front-End Django Developers
Best Practices for Front-End Django DevelopersBest Practices for Front-End Django Developers
Best Practices for Front-End Django Developers
 
Como DDD e Strategic Design estão nos ajudando a modernizar um Legado
Como DDD e Strategic Design estão nos ajudando a modernizar um LegadoComo DDD e Strategic Design estão nos ajudando a modernizar um Legado
Como DDD e Strategic Design estão nos ajudando a modernizar um Legado
 
Organise a Code Dojo!
Organise a Code Dojo!Organise a Code Dojo!
Organise a Code Dojo!
 
Hexagonal Design in Django
Hexagonal Design in DjangoHexagonal Design in Django
Hexagonal Design in Django
 
Python SOLID
Python SOLIDPython SOLID
Python SOLID
 

Plus de Allan Mangune

From the Trenches: Effectively Scaling Your Cloud Infrastructure and Optimizi...
From the Trenches: Effectively Scaling Your Cloud Infrastructure and Optimizi...From the Trenches: Effectively Scaling Your Cloud Infrastructure and Optimizi...
From the Trenches: Effectively Scaling Your Cloud Infrastructure and Optimizi...Allan Mangune
 
Crafting high quality code
Crafting high quality code Crafting high quality code
Crafting high quality code Allan Mangune
 
Software design with Domain-driven design
Software design with Domain-driven design Software design with Domain-driven design
Software design with Domain-driven design Allan Mangune
 
DDD and CQRS for .NET Developers
DDD and CQRS for .NET DevelopersDDD and CQRS for .NET Developers
DDD and CQRS for .NET DevelopersAllan Mangune
 
Object-oriented Analysis, Design & Programming
Object-oriented Analysis, Design & ProgrammingObject-oriented Analysis, Design & Programming
Object-oriented Analysis, Design & ProgrammingAllan Mangune
 
Configuring SQL Server Reporting Services for ASP.NET Running on Azure Web Role
Configuring SQL Server Reporting Services for ASP.NET Running on Azure Web RoleConfiguring SQL Server Reporting Services for ASP.NET Running on Azure Web Role
Configuring SQL Server Reporting Services for ASP.NET Running on Azure Web RoleAllan Mangune
 
Agile planning and iterations with Scrum using Team Foundation Server 2013
Agile planning and iterations with Scrum using Team Foundation Server 2013Agile planning and iterations with Scrum using Team Foundation Server 2013
Agile planning and iterations with Scrum using Team Foundation Server 2013Allan Mangune
 
Game Development with Windows Phone 7
Game Development with Windows Phone 7Game Development with Windows Phone 7
Game Development with Windows Phone 7Allan Mangune
 

Plus de Allan Mangune (10)

From the Trenches: Effectively Scaling Your Cloud Infrastructure and Optimizi...
From the Trenches: Effectively Scaling Your Cloud Infrastructure and Optimizi...From the Trenches: Effectively Scaling Your Cloud Infrastructure and Optimizi...
From the Trenches: Effectively Scaling Your Cloud Infrastructure and Optimizi...
 
Crafting high quality code
Crafting high quality code Crafting high quality code
Crafting high quality code
 
Software design with Domain-driven design
Software design with Domain-driven design Software design with Domain-driven design
Software design with Domain-driven design
 
DDD and CQRS for .NET Developers
DDD and CQRS for .NET DevelopersDDD and CQRS for .NET Developers
DDD and CQRS for .NET Developers
 
Agile Tools
Agile ToolsAgile Tools
Agile Tools
 
Object-oriented Analysis, Design & Programming
Object-oriented Analysis, Design & ProgrammingObject-oriented Analysis, Design & Programming
Object-oriented Analysis, Design & Programming
 
Agile methodologies
Agile methodologiesAgile methodologies
Agile methodologies
 
Configuring SQL Server Reporting Services for ASP.NET Running on Azure Web Role
Configuring SQL Server Reporting Services for ASP.NET Running on Azure Web RoleConfiguring SQL Server Reporting Services for ASP.NET Running on Azure Web Role
Configuring SQL Server Reporting Services for ASP.NET Running on Azure Web Role
 
Agile planning and iterations with Scrum using Team Foundation Server 2013
Agile planning and iterations with Scrum using Team Foundation Server 2013Agile planning and iterations with Scrum using Team Foundation Server 2013
Agile planning and iterations with Scrum using Team Foundation Server 2013
 
Game Development with Windows Phone 7
Game Development with Windows Phone 7Game Development with Windows Phone 7
Game Development with Windows Phone 7
 

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 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 consulting Friday, January 18, 13
  • 3. Taughtworks, Inc. Microsoft Certified Partner for Learning Solutions 2/F Liberty Plaza Building, H. V. Dela Costa Street, Makati City Friday, January 18, 13
  • 4. Our New Office 5/F 6784 Ayala Avenue corner V.A. Rufino 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 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 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 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 private Friday, 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+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 - 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.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 specific operating system Get the official 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/ Don’t 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 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 API Friday, 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 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(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 A Friday, January 18, 13
  • 41. Allan Spartacus Mangune allan@taughtworks.com facebook.com/mangune Friday, January 18, 13