Commits

Anonymous committed 1655624

Chart drawing application using django

Comments (0)

Files changed (12)

+application: chart-app
+version: 1
+runtime: python
+api_version: 1
+
+handlers:
+- url: /static
+  static_dir: static
+- url: /.*
+  script: main.py
+
+
+
+# Standard Python imports.
+import os
+import sys
+import logging
+import __builtin__
+
+# Google App Hosting imports.
+from google.appengine.ext.webapp import util
+
+#import pickle
+#sys.modules['cPickle'] = pickle
+
+# Enable info logging by the app (this is separate from appserver's
+# logging).
+#logging.getLogger().setLevel(logging.INFO)
+
+# Force sys.path to have our own directory first, so we can import from it.
+sys.path.insert(0, os.path.abspath(os.path.dirname(__file__)))
+
+# Must set this env var *before* importing any part of Django.
+os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
+
+# Make sure we can import Django.  We may end up needing to do this
+# little dance, courtesy of Google third-party versioning hacks.  Note
+# that this patches up sys.modules, so all other code can just use
+# "from django import forms" etc.
+try:
+  from django import v0_96 as django
+except ImportError:
+  pass
+
+# Import the part of Django that we use here.
+import django.core.handlers.wsgi
+
+def main():
+  # Create a Django application for WSGI.
+  application = django.core.handlers.wsgi.WSGIHandler()
+
+  # Run the WSGI CGI handler with that application.
+  util.run_wsgi_app(application)
+
+if __name__ == '__main__':
+  main()
+# Django settings for chartapp project.
+import os
+DEBUG = True
+TEMPLATE_DEBUG = DEBUG
+
+ADMINS = (
+    # ('Your Name', 'your_email@example.com'),
+)
+
+MANAGERS = ADMINS
+
+DATABASES = {
+    'default': {
+        'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
+        'NAME': '',                      # 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.
+    }
+}
+
+# Local time zone for this installation. Choices can be found here:
+# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
+# although not all choices may be available on all operating systems.
+# On Unix systems, a value of None will cause Django to use the same
+# timezone as the operating system.
+# If running in a Windows environment this must be set to the same as your
+# system time zone.
+TIME_ZONE = 'America/Chicago'
+
+# Language code for this installation. All choices can be found here:
+# http://www.i18nguy.com/unicode/language-identifiers.html
+LANGUAGE_CODE = 'en-us'
+
+SITE_ID = 1
+
+# If you set this to False, Django will make some optimizations so as not
+# to load the internationalization machinery.
+USE_I18N = True
+
+# If you set this to False, Django will not format dates, numbers and
+# calendars according to the current locale
+USE_L10N = True
+
+# Absolute filesystem path to the directory that will hold user-uploaded files.
+# Example: "/home/media/media.lawrence.com/media/"
+MEDIA_ROOT = ''
+
+# URL that handles the media served from MEDIA_ROOT. Make sure to use a
+# trailing slash.
+# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
+MEDIA_URL = ''
+
+# Absolute path to the directory static files should be collected to.
+# Don't put anything in this directory yourself; store your static files
+# in apps' "static/" subdirectories and in STATICFILES_DIRS.
+# Example: "/home/media/media.lawrence.com/static/"
+STATIC_ROOT = ''
+
+# URL prefix for static files.
+# Example: "http://media.lawrence.com/static/"
+STATIC_URL = '/static/'
+
+# URL prefix for admin static files -- CSS, JavaScript and images.
+# Make sure to use a trailing slash.
+# Examples: "http://foo.com/static/admin/", "/static/admin/".
+ADMIN_MEDIA_PREFIX = '/static/admin/'
+
+# Additional locations of static files
+STATICFILES_DIRS = (
+    # Put strings here, like "/home/html/static" or "C:/www/django/static".
+    # Always use forward slashes, even on Windows.
+    # Don't forget to use absolute paths, not relative paths.
+)
+
+# List of finder classes that know how to find static files in
+# various locations.
+STATICFILES_FINDERS = (
+    'django.contrib.staticfiles.finders.FileSystemFinder',
+    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
+#    'django.contrib.staticfiles.finders.DefaultStorageFinder',
+)
+
+# Make this unique, and don't share it with anybody.
+SECRET_KEY = '5@%xj8osm@e^5gze0l6@ywc4fj4$(h_(hmf*h6^ms4ob(ai-33'
+
+# List of callables that know how to import templates from various sources.
+TEMPLATE_LOADERS = (
+'django.template.loaders.filesystem.load_template_source',
+   # 'django.template.loaders.filesystem.Loader',
+    #'django.template.loaders.app_directories.Loader',
+#     'django.template.loaders.eggs.Loader',
+)
+
+MIDDLEWARE_CLASSES = (
+    'django.middleware.common.CommonMiddleware',
+    'django.contrib.sessions.middleware.SessionMiddleware',
+    #'django.middleware.csrf.CsrfViewMiddleware',
+    'django.contrib.auth.middleware.AuthenticationMiddleware',
+    #'django.contrib.messages.middleware.MessageMiddleware',
+)
+
+ROOT_URLCONF = 'urls'
+
+TEMPLATE_DIRS = ( os.path.join(os.path.dirname(__file__),'templates/'),
+    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
+    # Always use forward slashes, even on Windows.
+    # Don't forget to use absolute paths, not relative paths.
+)
+
+INSTALLED_APPS = (
+    #'django.contrib.auth',
+    'django.contrib.contenttypes',
+    #'django.contrib.sessions',
+    #'django.contrib.sites',
+    #'django.contrib.messages',
+    #'django.contrib.staticfiles',
+    #'chart'
+    # Uncomment the next line to enable the admin:
+     'django.contrib.admin',
+    # Uncomment the next line to enable admin documentation:
+    # 'django.contrib.admindocs',
+)
+
+# A sample logging configuration. The only tangible logging
+# performed by this configuration is to send an email to
+# the site admins on every HTTP 500 error.
+# See http://docs.djangoproject.com/en/dev/topics/logging for
+# more details on how to customize your logging configuration.
+
Binary file added.

static/styles.css

+html,body{margin:0;padding:0}
+body{font: 76% arial,sans-serif;text-align:center}
+p{margin:0 10px 10px}
+a{padding:5px; text-decoration:none; color:#3BB9FF;}
+li{margin:0 10px 10px}
+div#header{background-color:#cccccc;}
+div#header h1{height:80px;line-height:80px;margin:0;padding-left:10px;}
+div#container{text-align:left}
+div#content p{line-height:1.4}
+div#navigation{background:#F6F0E0;}
+div#navigation ul{margin:15px 0; padding:0; list-style-type:none;}
+div#navigation li{margin-bottom:5px;}
+div#extra{background:#CCC8B3;}
+div#footer{background:#cccccc;}
+div#footer p{margin:0;padding:5px 10px}
+div#container{width:1000px;margin:0 auto}
+div#navigation{float:left;width:350px}
+div#extra{float:right;width:350px}
+div#footer{clear:both;width:100%}

templates/barchart.html

+
+<html>
+  <head>
+    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
+    <script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.min.js"></script>
+    <link type="text/css" rel="stylesheet" href="/static/styles.css" />
+    <script type="text/javascript">
+    
+      google.load('visualization', '1.0', {'packages':['corechart']});
+      google.setOnLoadCallback(drawChart);
+      function drawChart() {
+      	  jQuery.get("/graph", function(list_values){ 
+              var data = new google.visualization.DataTable();
+              data.addColumn('string', 'Topping');
+              data.addColumn('number', 'Slices');
+              data.addRows(list_values);
+              var options = {'title':'How Much Pizza I Ate Last Night',
+                     'width':400,
+                     'height':300};
+              var chart = new google.visualization.BarChart(document.getElementById('chart_div'));
+              chart.draw(data, options);
+              });
+       } 
+
+    </script>
+  </head>
+  <body>
+
+<div id="container">
+<div id="header"><center><h1>Displaying Charts using Django</h1></center></div>
+   			<table>
+			<tr>
+			<td><h4>Click the following links to display the Google Charts : </h4></td>
+			<td><h4><a href="/piechart"> Pie Chart</a></h4></td>
+			<td><h4><a href="/barchart"> Bar Chart</a></h4></td>
+			</tr>
+			</table>
+		<div align="center" id="chart_div"></div>
+    </div>
+  <div id="footer">
+   <center><h6>by</h6><h4>Anoop.S.M</h4></center>
+  </div>
+</div>
+  </body>
+</html> 

templates/home.html

+
+<html>
+  <head>
+    <link type="text/css" rel="stylesheet" href="/static/styles.css" />
+  </head>
+<body>
+<div id="container">
+<div id="header"><center><h1>Displaying Charts using Django</h1></center></div>
+    <div id="content">
+		    <table>
+			
+			<tr>
+			<td><h4>Click the following links to display the Google Charts : </h4></td>
+			<td><h4><a href="/piechart"> Pie Chart</a></h4></td>
+			<td><h4><a href="/barchart"> Bar Chart</a></h4></td>
+			</tr>
+			</table>
+			
+		</div>
+	<div align="center" id="chart_div"></div>
+</div>
+</body>
+</html> 

templates/piechart.html

+
+<html>
+  <head>
+    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
+    <script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.min.js"></script>
+    <link type="text/css" rel="stylesheet" href="/static/styles.css" />
+     <script type="text/javascript">
+    
+      google.load('visualization', '1.0', {'packages':['corechart']});
+      google.setOnLoadCallback(drawChart);
+      function drawChart() {
+      	  jQuery.get("/graph", function(list_values){ 
+              var data = new google.visualization.DataTable();
+              data.addColumn('string', 'Topping');
+              data.addColumn('number', 'Slices');
+              data.addRows(list_values);
+              var options = {'title':'How Much Pizza I Ate Last Night',
+                     'width':400,
+                     'height':300};
+              var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
+              chart.draw(data, options);
+              });
+       } 
+
+    </script>
+  </head>
+  <body>
+
+<div id="container">
+<div id="header"><center><h1>Displaying Charts using Django</h1></center></div>
+    <div id="content">
+			 <table>
+			
+			<tr>
+			<td><h4>Click the following links to display the Google Charts : </h4></td>
+			<td><h4><a href="/piechart"> Pie Chart</a></h4></td>
+			<td><h4><a href="/barchart"> Bar Chart</a></h4></td>
+			</tr>
+			</table>
+	<div align="center" id="chart_div"></div>
+ 
+    </div>
+  
+  <div id="footer">
+   <center><h6>by</h6><h4>Anoop.S.M</h4></center>
+  </div>
+</div>
+  </body>
+</html> 
+from django.conf.urls.defaults import *
+
+# Uncomment the next two lines to enable the admin:
+# from django.contrib import admin
+# admin.autodiscover()
+
+urlpatterns = patterns('views',
+    # Examples:
+     (r'^$', 'index'),
+     (r'^graph/','graph'),
+     (r'^piechart/','piechart'),
+     (r'^barchart/','barchart'),
+    # url(r'^chartapp/', include('chartapp.foo.urls')),
+
+    # Uncomment the admin/doc line below to enable admin documentation:
+    # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
+
+    # Uncomment the next line to enable the admin:
+    # url(r'^admin/', include(admin.site.urls)),
+)
Binary file added.
+# Create your views here.
+from django.http import HttpResponse
+from django.shortcuts import render_to_response
+from django.template import RequestContext
+from django.utils import simplejson
+
+def index(request):
+	return render_to_response('home.html')
+
+def piechart(request):
+	return render_to_response('piechart.html')
+
+def barchart(request):
+	return render_to_response('barchart.html')
+
+
+def graph(request):
+	data = [['Mushrooms', 3],['Onions', 1],['Olives', 1],['Zucchini', 1], ['Pepperoni', 2]]
+	return HttpResponse(simplejson.dumps(data), mimetype='application/json')
+	
+
Binary file added.