Commits

Miran Levar committed f869055

Fixes and custom errors

Comments (0)

Files changed (6)

P4/graph_viewer/Templates/error.html

+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+    <meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8"/>
+    <link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/bootstrap.css"/>
+    <link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/jquery.ui.custom.min.css"/>
+    <link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/default.css"/>
+	
+    <title>graph viewer</title>
+
+    <script type="text/javascript" src="{{ STATIC_URL }}js/jquery.min.js"></script>
+    <script type="text/javascript" src="{{ STATIC_URL }}js/jquery.ui.min.js"></script>
+    <script type="text/javascript" src="{{ STATIC_URL }}js/bootstrap.min.js"></script>
+
+</head>
+<body>
+
+<div class="container-narrow">
+    <div class="masthead">
+		<div class="navbar navbar-static-top">
+		<div class="navbar-inner">
+			<span class="brand">graph viewer</span>
+	    </div>
+	    </div>
+	</div>
+
+    <div class="content">
+        <center>
+        <h1>
+		{{error }}
+        </h1>
+        </center>
+	</div>
+</div>
+
+<div class="footer navbar-fixed-bottom" >
+    <img class="pull-right" src="/img/appengine-noborder-120x30.gif" 
+    alt="Powered by Google App Engine" />
+    <p id="foot">
+    <span class="brand">Miran Levar, P2, FRI 2012/2013 </span>
+    </p>
+</div>
+</body>
+</html>

P4/graph_viewer/views.py

 
     return _wrapper
 
+@loginrequired
+def logout(request):
+    """
+    Logout bypass that flushes the cache for each user.
+    """
+    request.session.flush()
+    return HttpResponsePermanentRedirect(users.create_logout_url("/"))
 
 # ******************************
 #             CRUD
     return render_to_response('home.html',  c)
 
 @loginrequired
-def logout(request):
-    """
-    Logout bypass that flushes the cache for each user.
-    """
-    request.session.flush()
-    return HttpResponsePermanentRedirect(users.create_logout_url("/"))
-
-@loginrequired
 def view_graph(request, id):
     """
     view_graph stores the selected graph into session for viewing.
 
 @loginrequired
 def calculate(request):
+    """
+    Runs the mapreduce pipeline and redirects to the mr console
+    """
     pipeline = mr.PhrasesPipeline()
     pipeline.start()
     return HttpResponseRedirect(pipeline.base_path + "/status?root=" + pipeline.pipeline_id)
     })
 
 
-
+# ******************************
+#             EMAIL
+# ******************************
 @csrf_exempt    
 def email_handler(request):
     """
         
     return HttpResponse('ok')
 
+def error_500(request):
+    c = RequestContext(request, {'error':"500: Server Error"})
+    return render_to_response('error.html',  c)
+
+def error_403(request):
+    c = RequestContext(request, {'error':"403: Forbidden"})
+    return render_to_response('error.html',  c)
+
+def error_404(request):
+    c = RequestContext(request, {'error':"404: Request page not found."})
+    return render_to_response('error.html',  c)
 from django.conf import settings
 
 from django.contrib.staticfiles.urls import staticfiles_urlpatterns
-
+from django.conf.urls.defaults import handler403, handler404, handler500
 
 
 urlpatterns = patterns('',
 
     # static handler
     url(r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.STATIC_ROOT}),
+
 )
 
+# custom error handlers
+handler500 = 'P4.graph_viewer.views.error_500'
+handler403 = 'P4.graph_viewer.views.error_403'
+handler404 = 'P4.graph_viewer.views.error_404'
+
 urlpatterns += staticfiles_urlpatterns()
 version: 4
 runtime: python27
 api_version: 1
-threadsafe: true #false
-
-
+threadsafe: false #has to be false because of mapreduce
 
 handlers:
 - url: /favicon.ico
   static_files: img/favicon.ico
-  upload: img/favicon.
-
+  upload: img/favicon.ico
 - url: /img/
   static_dir: img
-
 - url: /info/.*
   script: main.app
-
+- url: /blobstore/.*
+  script: main.app
 - url: /mapreduce/pipeline/images
   static_dir: mapreduce/lib/pipeline/ui/images
-
 - url: /mapreduce(/.*)?
   script: mapreduce.main.APP
 
-- url: /blobstore/.*
-  script: main.app
-
-
 libraries:
 - name: jinja2
   version: latest
 builtins:
 - django_wsgi: on
 
-#includes:
-#- mapreduce/include.yaml
+includes:
+- mapreduce/include.yaml
 
 inbound_services:
 - mail
         template = jinja_environment.get_template('info.html')
         self.response.out.write(template.render({"username": user.nickname()}))
 
-
-class HelloHandler(webapp.RequestHandler):
+class HelloHandler(webapp2.RequestHandler):
     def get(self):
         self.response.out.write('Hello world!')
 
     blob_info = blobstore.BlobInfo.get(key)
     self.send_blob(blob_info)
 
-
 app = webapp2.WSGIApplication([('/info/', MainHandler), ('/info/hello', HelloHandler), (r'/blobstore/(.*)', DownloadHandler),], debug=False)
 import urllib
 
 def graph_stats_map(data):
-    """Phrases demo map function."""
+    """
+    Graph stats map function, currently emits the number of edges but could do proper processing of each graph
+    """
     graph = simplejson.loads(data.nodes)
     yield None, "%d %d" % (1, len(graph["nodes"]))
 
 def graph_stats_reduce(key, values):
-    """Phrases demo reduce function."""
+    """
+    Graph stats reduce fuinction, emits a string that is later shown in the app.
+    """
     numb, length = 0, 0
     for v in values:
         n,l = v.split(' ')
 
 
 class PhrasesPipeline(base_handler.PipelineBase):
-    """A pipeline to run statistics
-
-    Args:
-    blobkey: blobkey to process as string. Should be a zip archive with
-        text files inside.
+    """
+    A pipeline to run statistics
     """
 
     def run(self):
 
 
 class StoreOutput(base_handler.PipelineBase):
-    """A pipeline to store the result of the MapReduce job in the database.
+    """
+    A pipeline to store the result of the MapReduce job in the memcache.
 
     Args:
-    mr_type: the type of mapreduce job run (e.g., WordCount, Index)
-    encoded_key: the DB key corresponding to the metadata of this job
     output: the blobstore location where the output of the job is stored
     """
 
     def run(self, output):
         blob_reader = blobstore.BlobReader(output[0][11:])
         blob = blob_reader.read()
-        logging.info("MR OUTPUT: %s" % blob )
+        logging.info("M_R OUTPUT: %s" % blob )
         memcache.set("stats", blob)
         return output[0]