<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,3 +1,7 @@
+&quot;&quot;&quot;
+Provides a protected administrative area for uploading and deleteing images
+&quot;&quot;&quot;
+
 import os
 import datetime
 
@@ -11,16 +15,25 @@ from google.appengine.api import users
 from models import Image
 
 class Index(webapp.RequestHandler):
+    &quot;&quot;&quot;
+    Main view for the application.
+    Protected to logged in users only.
+    &quot;&quot;&quot;
     def get(self):
-        self.response.out.write('&lt;html&gt;&lt;body&gt;')
-
+        &quot;Responds to GET requets with the admin interface&quot;
+        # query the datastore for images owned by
+        # the current user. You can't see anyone elses images
+        # in the admin
         images = Image.all()
         images.filter(&quot;user =&quot;, users.get_current_user())
         images.order(&quot;-date&quot;)
 
+        # we are enforcing loggins so we know we have a user
         user = users.get_current_user()
+        # we need the logout url for the frontend
         logout = users.create_logout_url(&quot;/&quot;)
-        
+
+        # prepare the context for the template
         context = {
             &quot;images&quot;: images,
             &quot;logout&quot;: logout,
@@ -32,33 +45,57 @@ class Index(webapp.RequestHandler):
         self.response.out.write(template.render(path, context))
 
 class Deleter(webapp.RequestHandler):
+    &quot;Deals with deleting images&quot;
     def post(self):
-       image = db.get(self.request.get(&quot;key&quot;))
-       image.delete()
-       self.redirect('/')
+        &quot;Delete a given image&quot;
+        # we get the user as you can only delete your own images
+        user = users.get_current_user()
+        image = db.get(self.request.get(&quot;key&quot;))
+        # check that we own this image
+        if image.user == user:
+            image.delete()
+        # whatever happens rediect back to the main admin view
+        self.redirect('/')
        
 class Uploader(webapp.RequestHandler):
+    &quot;Deals with uploading new images to the datastore&quot;
     def post(self):
-        image = Image()
-        original_content = self.request.get(&quot;img&quot;)
+        &quot;Upload via a multitype POST message&quot;
         
         try:
+            # check we have numerical width and height values
             width = int(self.request.get(&quot;width&quot;))
             height = int(self.request.get(&quot;height&quot;))
         except ValueError:
+            # if we don't have valid width and height values
+            # then just use the original image
             image_content = self.request.get(&quot;img&quot;)
         else:
+            # if we have valid width and height values
+            # then resize according to those values
             image_content = images.resize(self.request.get(&quot;img&quot;), width, height)
         
+        # get the image data from the form
+        original_content = self.request.get(&quot;img&quot;)
+        # always generate a thumbnail for use on the admin page
         thumb_content = images.resize(self.request.get(&quot;img&quot;), 100, 100)
+        
+        # create the image object
+        image = Image()
+        # and set the properties to the relevant values
         image.image = db.Blob(image_content)
+        # we always store the original here in case of errors
+        # although it's currently not exposed via the frontend
         image.original = db.Blob(original_content)
         image.thumb = db.Blob(thumb_content)
         image.user = users.get_current_user()
                 
+        # store the image in the datasore
         image.put()
+        # and redirect back to the admin page
         self.redirect('/')
                 
+# wire up the views
 application = webapp.WSGIApplication([
     ('/', Index),
     ('/upload', Uploader),
@@ -66,6 +103,7 @@ application = webapp.WSGIApplication([
 ], debug=True)
 
 def main():
+    &quot;Run the application&quot;
     run_wsgi_app(application)
 
 if __name__ == '__main__':</diff>
      <filename>backend.py</filename>
    </modified>
    <modified>
      <diff>@@ -1,3 +1,8 @@
+&quot;&quot;&quot;
+Frontend for the image host. This does the actual serving of the images
+for use on others sites and within the admin
+&quot;&quot;&quot;
+
 import os
 import datetime
 
@@ -8,22 +13,35 @@ from google.appengine.ext.webapp.util import run_wsgi_app
 from models import Image
   
 class GenericServer(webapp.RequestHandler):
+    &quot;&quot;&quot;
+    Image server designed to handle serving png images from
+    different object properties
+    &quot;&quot;&quot;
     property = 'image'
     def get(self):
+        # key is provided in the query string
         image = db.get(self.request.get(&quot;id&quot;))
         if image.image:
+            # we have an image so prepare the response
+            # with the relevant headers
             self.response.headers['Content-Type'] = &quot;image/png&quot;
+            # and then write our the image data direct to the response
             self.response.out.write(eval(&quot;image.%s&quot; % self.property))
         else:
+            # we should probably return an image with the correct header
+            # here instead of the default html 404
             self.error(404)
 
 class ImageServer(GenericServer):
+    &quot;Serve the main image&quot;
     property = 'image'
 
 class ThumbServer(GenericServer):
+    &quot;Serve the thumbnail image&quot;
     property = 'thumb'
 
 class OriginalServer(GenericServer):
+    &quot;Serve the original uploaded image. Currently unused.&quot;
     property = 'original'
 
 application = webapp.WSGIApplication([
@@ -32,6 +50,7 @@ application = webapp.WSGIApplication([
 ], debug=True)
 
 def main():
+    &quot;Run the application&quot;
     run_wsgi_app(application)
 
 if __name__ == '__main__':</diff>
      <filename>frontend.py</filename>
    </modified>
    <modified>
      <diff>@@ -2,8 +2,13 @@ from google.appengine.ext import db
 from google.appengine.api.users import User
 
 class Image(db.Model):
+    &quot;Represents an image stored in the datastore&quot;
+    # blog properties storing up to 1MB of binary data
     image = db.BlobProperty()
     thumb = db.BlobProperty()
     original = db.BlobProperty()
+    # store the date just in case
     date = db.DateTimeProperty(auto_now_add=True)
+    # all images are associated with the user who uploades them
+    # this way we can make it a multi user system if that's useful
     user = db.UserProperty()
\ No newline at end of file</diff>
      <filename>models.py</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>aedb2cd30b2e4fc40d3e686c883aa82661ba3931</id>
    </parent>
  </parents>
  <author>
    <name>Gareth Rushgrove</name>
    <email>gareth@morethanseven.net</email>
  </author>
  <url>http://github.com/garethr/appengine-image-host/commit/1750f7cf2ca7b9ea7bb2f4072e4fb747f53f5add</url>
  <id>1750f7cf2ca7b9ea7bb2f4072e4fb747f53f5add</id>
  <committed-date>2009-02-04T12:15:59-08:00</committed-date>
  <authored-date>2009-02-04T12:15:59-08:00</authored-date>
  <message>lots of comments for the core code</message>
  <tree>3f83311046614d0ab3e6c1a30cdf55129fbd2ac8</tree>
  <committer>
    <name>Gareth Rushgrove</name>
    <email>gareth@morethanseven.net</email>
  </committer>
</commit>
