Giter Site home page Giter Site logo

padawan's Introduction

Padawan is a "training wheels" library for learning how to build database-driven web applications. It is meant to be an educational tool and is designed primarily with pegadogical goals in mind. It was written to be used in a database course that aims to understand how a database fits within the context of a web application without spending too much time on the elements of web development that have little to do with databases. Padawan assumes that the web application will be written in a subset of Python, by students with limited familiarity with the language.

Padawan assumes use of CGI and MySQL, via Python's cgi and MySQLdb modules.

There are two main files: padawan.py and padawan. Each is described below.

padawan.py (a Python module)

padawan.py is a python module that serves as a wrapper around Python's cgi and MySQLdb modules, adding the following features:

  • Code can be written using just a subset of Python. In particular, the application can avoid use of methods (using only functions instead), "%" operator. Use of list subscripts can also be avoided, if desired.
  • Common errors are checked more rigorously with additional (and friendlier) error messages.
  • Values can be retrieved by field names rather than field positions.
  • Additional functions are provided.

padawan (a CGI wrapper)

padawan is a wrapper around the python executable that provides an additional level of support, aiming to avoid "Internal Server Error" Messages.

An example

Here is an example of a Padawan script. More complete examples are available in the examples directory.

#!/usr/bin/padawan
print "Content-Type: text/html; encoding=utf8"
print

if not form_has_field("species") :
    print "A value for <b>species</b> specify you must!"
    exit()
    
species = get_form_field_value("species")
species = escape_string(species)

query_template = """
select * from species where species='%s';
"""

query = fill_template(query_template, species)

execute_query(query)

if get_row_count() == 0 :
    print "This species in our database exists not!"
    print "Good-bye and may the force be with you!"
    exit()

rows = fetch_all_rows()
first_row = rows[0]

homeworld = get_row_value(first_row, "homeworld")

if homeworld!=None :  # Notice that in Python it's "None", not "NULL".
    print "<p>This species originally from planet <b>" +  homeworld + "</b> is.</p>"
else :
    print "<p>The homeworld of this species we know not.</p>"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.