<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>base/DB.py</filename>
    </added>
    <added>
      <filename>base/DBObjectGAE.py</filename>
    </added>
    <added>
      <filename>base/DBObjectStandalone.py</filename>
    </added>
    <added>
      <filename>models/modelsGAE.py</filename>
    </added>
    <added>
      <filename>models/modelsStandalone.py</filename>
    </added>
    <added>
      <filename>models/modelsbase.py</filename>
    </added>
    <added>
      <filename>sql/create.sql</filename>
    </added>
    <added>
      <filename>start-wsgi.py</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -1,21 +1,9 @@
 &quot;&quot;&quot;
 The DBObject base class
 
-Database objects that could be DB-backed, or GAE backed. For now, just GAE.
-
-This needs more work to be much more generic.
-
 ben@adida.net
 &quot;&quot;&quot;
 
-import utils
-
-from django.utils import simplejson
-import datetime
-
-from google.appengine.ext import db
-
-
 def from_utf8(string):
     if type(string) == str:
         return string.decode('utf-8')
@@ -28,151 +16,9 @@ def to_utf8(string):
     else:
         return string
 
-class DBObject(db.Model):
-
-    # GAE get_id
-    def get_id(self):
-        return self.key()
-
-    @classmethod
-    def selectById(cls, key_value):
-        return cls.get(key_value)
-        
-    @classmethod
-    def selectByKey(cls, key_name, key_value):
-        obj = cls()
-        if obj.select(keys={key_name:key_value}):
-            return obj
-        else:
-            return None
-    
-    @classmethod
-    def selectByKeys(cls, keys):
-        # GAE
-        all_values= cls.selectAllByKeys(keys)
-        if len(all_values) == 0:
-          return None
-        else:
-          return all_values[0]
-
-    @classmethod
-    def selectAll(cls, order_by = None, offset = None, limit = None):
-        # GAE query
-        query = cls.all()
-        
-        # order
-        if order_by:
-            query.order(order_by)
-        
-        return query.fetch(limit or 1000, offset or 0)
-
-    @classmethod
-    def selectAllByKey(cls, key_name, key_value, order_by = None, offset = None, limit = None):
-        keys = dict()
-        keys[key_name] = key_value
-        return cls.selectAllByKeys(keys, order_by, offset, limit)
-        
-    @classmethod
-    def selectAllByKeys(cls, keys, order_by = None, offset = None, limit = None):
-        # unicode
-        for k,v in keys.items():
-            keys[k] = to_utf8(v)
-
-        # GAE query
-        query = cls.all()
-
-        # order
-        if order_by:
-          query.order(order_by)
-
-        # conditions
-        for k,v in keys.items():
-          query.filter('%s' % k, v)
-
-        return query.fetch(limit or 1000, offset or 0)        
-
-    def _load_from_row(self, row, extra_fields=[]):
-
-        prepared_row = self._prepare_object_values(row)
-        
-        for field in self.FIELDS:
-            # unicode
-            self.__dict__[field] = from_utf8(prepared_row[field])
-
-        for field in extra_fields:
-            # unicode
-            self.__dict__[field] = from_utf8(prepared_row[field])
-
-    def insert(self):
-        &quot;&quot;&quot;
-        Insert a new object, but only if it hasn't been inserted yet
-        &quot;&quot;&quot;
-        self.save()
-
-    def update(self):
-        &quot;&quot;&quot;
-        Update an object
-        &quot;&quot;&quot;
-        # GAE
-        self.save()
-
-    # DELETE inherited from GAE
-            
-    @classmethod
-    def multirow_to_array(cls, multirow, extra_fields=[]):
-        objects = []
-
-        if multirow == None:
-            return objects
-
-        for row in multirow:
-            one_object = cls()
-            one_object._load_from_row(row, extra_fields)
-            objects.append(one_object)
-
-        return objects
-    
-    def toJSONDict(self, extra_fields = []):
-        # a helper recursive procedure to navigate down the items
-        # even if they don't have a toJSONDict() method
-        def toJSONRecurse(item):
-            if type(item) == int or type(item) == bool or hasattr(item, 'encode') or not item:
-                return item
-
-            if hasattr(item,'toJSONDict'):
-                return item.toJSONDict()
-            
-            if type(item) == dict:
-                new_dict = dict()
-                for k in item.keys():
-                    new_dict[k] = toJSONRecurse(item[k])
-                return new_dict
-
-            if hasattr(item,'__iter__'):
-                return [toJSONRecurse(el) for el in item]
-                
-            return str(item)
-            
-        # limit the fields to just JSON_FIELDS if it exists
-        json_dict = dict()
-        if hasattr(self.__class__,'JSON_FIELDS'):
-            keys = self.__class__.JSON_FIELDS + extra_fields
-        else:
-            keys = extra_fields
-        
-        # go through the keys and recurse down each one
-        for f in keys:
-            ## FIXME: major hack here while I figure out how to dynamically get the right field
-            if hasattr(self, f):
-                json_dict[f] = toJSONRecurse(getattr(self, f))
-            else:
-                if self.__dict__.has_key(f):
-                    json_dict[f] = toJSONRecurse(self.__dict__[f])
-                else:
-                    continue
-            
-
-        return json_dict
-        
-    def toJSON(self):
-        return simplejson.dumps(self.toJSONDict())
+#from DBObjectGAE import *
+try:
+  from google.appengine.ext import db
+  from DBObjectGAE import *
+except:
+  from DBObjectStandalone import *
\ No newline at end of file</diff>
      <filename>base/DBObject.py</filename>
    </modified>
    <modified>
      <diff>@@ -4,7 +4,8 @@
 #
 
 root = '.'
-hostname = 'www.heliosvoting.org'
+#hostname = 'www.heliosvoting.org'
+hostname = 'localhost:8082'
 webroot = 'http://' + hostname
 
 #
@@ -18,3 +19,9 @@ PYTHON_DEBUG = True
 ##
 SEND_MAIL = True
 
+#
+# database
+#
+DB_HOST = &quot;localhost&quot;
+DB_NAME = &quot;helios&quot;
+DB_PORT = 5432</diff>
      <filename>base/config.py</filename>
    </modified>
    <modified>
      <diff>@@ -7,7 +7,11 @@ Ben Adida (ben@adida.net)
 # needs a rewrite for GAE
 
 from base import config
-from google.appengine.api import mail
+
+try:
+  from google.appengine.api import mail
+except:
+  pass
 
 def no_send(recipient_names, recipient_emails, sender_name, sender_email, subject, body, reply_to=None):
   print &quot;not sending email as per config (GAE update needed to see email)&quot;</diff>
      <filename>base/mail.py</filename>
    </modified>
    <modified>
      <diff>@@ -11,7 +11,12 @@ Ben Adida - ben@adida.net
 import urllib, re, sys, datetime, urlparse, string
 import cherrypy
 import threading
-from django.utils import simplejson
+
+try:
+  from django.utils import simplejson
+except:
+  import simplejson
+  
 import random
 import htmlsanitizer, config
 import sha, hmac, base64</diff>
      <filename>base/utils.py</filename>
    </modified>
    <modified>
      <diff>@@ -5,10 +5,14 @@ Ben Adida (ben@adida.net)
 &quot;&quot;&quot;
 
 from base import *
-from base import REST, session, Controller, template, utils
+from base import REST, session, Controller, template
 
 import cherrypy, time, logging
-from django.utils import simplejson
+
+try:
+  from django.utils import simplejson
+except:
+  import simplejson
 
 class HeliosController(Controller):
   &quot;&quot;&quot;</diff>
      <filename>controllers/basic.py</filename>
    </modified>
    <modified>
      <diff>@@ -7,12 +7,19 @@ Ben Adida (ben@adida.net)
 from base import *
 from base import REST, session, Controller, template, mail
 from crypto import algs
-from models import models as do
+import models as do
 
 import cherrypy, time, logging
-from django.utils import simplejson
 
-from google.appengine.api import users
+try:
+  from django.utils import simplejson
+except:
+  import simplejson
+
+try:
+  from google.appengine.api import users
+except:
+  pass
 
 import basic
 </diff>
      <filename>controllers/election.py</filename>
    </modified>
    <modified>
      <diff>@@ -7,12 +7,19 @@ Ben Adida (ben@adida.net)
 from base import *
 from base import REST, session, Controller, template
 from crypto import algs
-from models import models as do
+import models as do
 
 import cherrypy, time, logging
-from django.utils import simplejson
 
-from google.appengine.api import users
+try:
+  from django.utils import simplejson
+except:
+  import simplejson
+
+try:
+  from google.appengine.api import users
+except:
+  pass
 
 # the basic controllers
 import basic</diff>
      <filename>controllers/user.py</filename>
    </modified>
    <modified>
      <diff>@@ -19,7 +19,6 @@
 
 
 import wsgiref.handlers
-import models
 
 import cherrypy
 import sitemap</diff>
      <filename>heliosvoting.py</filename>
    </modified>
    <modified>
      <diff>@@ -10,7 +10,7 @@ indexes:
 # automatically uploaded to the admin console when you next deploy
 # your application using appcfg.py.
 
-# Used 6 times in query history.
+# Used 11 times in query history.
 - kind: ElectionExponent
   properties:
   - name: election
@@ -30,7 +30,7 @@ indexes:
   - name: cast_id
     direction: desc
 
-# Unused in query history -- copied from input.
+# Used 2 times in query history.
 - kind: Voter
   properties:
   - name: election</diff>
      <filename>index.yaml</filename>
    </modified>
    <modified>
      <diff>@@ -0,0 +1,12 @@
+&quot;&quot;&quot;
+The Models for Helios.
+
+First the generic stuff, then the extension
+&quot;&quot;&quot;
+
+#from modelsGAE import *
+try:
+  from google.appengine.ext import db
+  from modelsGAE import *
+except:
+  from modelsStandalone import *
\ No newline at end of file</diff>
      <filename>models/__init__.py</filename>
    </modified>
    <modified>
      <diff>@@ -24,7 +24,7 @@ function load_election_and_ballots(election_id) {
     VOTER_LIST = [];
     
     // get the election data
-    Helios.get_election({'election_id' : election_id}, function(election) {
+    Helios.get_election({'election_id' : election_id}, function(election_json) {
         var election = HELIOS.Election.fromJSONObject(election_json);        
         ELECTION = election;
         
@@ -158,8 +158,7 @@ function do_tally() {
 &lt;div id=&quot;sk_section&quot;&gt;
     &lt;form onsubmit=&quot;return false;&quot;&gt;
         Your Secret Key:&lt;br /&gt;
-        &lt;textarea id=&quot;sk_textarea&quot; cols=&quot;60&quot; rows=&quot;5&quot;&gt;
-        &lt;/textarea&gt;
+        &lt;textarea id=&quot;sk_textarea&quot; cols=&quot;60&quot; rows=&quot;5&quot;&gt;&lt;/textarea&gt;
     &lt;/form&gt;
 &lt;/div&gt;
 </diff>
      <filename>templates/election/drive_tally.tmpl</filename>
    </modified>
    <modified>
      <diff>@@ -59,7 +59,7 @@ BOOTH.setup_election = function(election) {
 };
 
 BOOTH.show = function(el) {
-  \$('#page div').hide();
+  \$('.panel').hide();
   el.show();
   return el;
 };
@@ -140,7 +140,8 @@ BOOTH.seal_ballot = function() {
     
     BOOTH.encrypted_ballot = new HELIOS.EncryptedVote(BOOTH.election, BOOTH.ballot.answers);
     
-    BOOTH.show(\$('#seal_div')).processTemplate({'encrypted_vote_hash' : BOOTH.encrypted_ballot.get_hash()});
+    \$('#seal_div').processTemplate({'encrypted_vote_hash' : BOOTH.encrypted_ballot.get_hash()});
+    BOOTH.show(\$('#seal_div'));
 };
 
 BOOTH.audit_ballot = function() {
@@ -210,30 +211,30 @@ BOOTH.show_receipt = function() {
 
 &lt;/script&gt;
 &lt;div id=&quot;page&quot;&gt;
-  &lt;div class=&quot;entry&quot; id=&quot;election_div&quot; class=&quot;panel&quot;&gt;
+  &lt;div id=&quot;election_div&quot; class=&quot;panel&quot;&gt;
     Loading Election Booth...
   &lt;/div&gt;
 
-  &lt;div class=&quot;entry&quot; id=&quot;question_div&quot; class=&quot;panel&quot;&gt;
+  &lt;div id=&quot;question_div&quot; class=&quot;panel&quot;&gt;
   &lt;/div&gt;
 
-  &lt;div class=&quot;entry&quot; id=&quot;confirm_div&quot; class=&quot;panel&quot;&gt;
+  &lt;div id=&quot;confirm_div&quot; class=&quot;panel&quot;&gt;
   &lt;/div&gt;
   
-  &lt;div class=&quot;entry&quot; id=&quot;processing_div&quot; class=&quot;panel&quot;&gt;
+  &lt;div id=&quot;processing_div&quot; class=&quot;panel&quot;&gt;
       &lt;h3 align=&quot;center&quot;&gt;Processing....&lt;/h3&gt;
   &lt;/div&gt;
 
-  &lt;div class=&quot;entry&quot; id=&quot;seal_div&quot; class=&quot;panel&quot;&gt;
+  &lt;div id=&quot;seal_div&quot; class=&quot;panel&quot;&gt;
   &lt;/div&gt;
 
-  &lt;div class=&quot;entry&quot; id=&quot;audit_div&quot; class=&quot;panel&quot;&gt;
+  &lt;div id=&quot;audit_div&quot; class=&quot;panel&quot;&gt;
   &lt;/div&gt;
 
-  &lt;div class=&quot;entry&quot; id=&quot;login_div&quot; class=&quot;panel&quot;&gt;
+  &lt;div id=&quot;login_div&quot; class=&quot;panel&quot;&gt;
   &lt;/div&gt;
 
-  &lt;div class=&quot;entry&quot; id=&quot;done_div&quot; class=&quot;panel&quot;&gt;
+  &lt;div id=&quot;done_div&quot; class=&quot;panel&quot;&gt;
   &lt;/div&gt;
 &lt;/div&gt;
 #include &quot;templates/booth-footer.tmpl&quot;</diff>
      <filename>templates/election/vote.tmpl</filename>
    </modified>
    <modified>
      <diff>@@ -17,6 +17,11 @@
   &lt;script language=&quot;javascript&quot; src=&quot;/static/elgamal.js&quot;&gt;&lt;/script&gt;
   &lt;script language=&quot;javascript&quot; src=&quot;/static/sha1.js&quot;&gt;&lt;/script&gt;
   &lt;script language=&quot;javascript&quot; src=&quot;/static/helios.js&quot;&gt;&lt;/script&gt;
+#from base import utils
+&lt;script language=&quot;javascript&quot;&gt;
+var API_HOST = '$utils.get_host()'
+&lt;/script&gt;
+
   &lt;script language=&quot;javascript&quot; src=&quot;/static/cross-site-api.js&quot;&gt;&lt;/script&gt;
 &lt;/head&gt;
 &lt;body&gt;&lt;div id=&quot;content&quot;&gt;&lt;div id=&quot;header&quot;&gt;</diff>
      <filename>templates/header.tmpl</filename>
    </modified>
  </modified>
  <removed type="array">
    <removed>
      <filename>models/models.py</filename>
    </removed>
  </removed>
  <parents type="array">
    <parent>
      <id>3c1589d3a88f4afc70c6408163a87c3bc20e8f50</id>
    </parent>
  </parents>
  <author>
    <name>Ben Adida</name>
    <email>ben@adida.net</email>
  </author>
  <url>http://github.com/benadida/helios/commit/9e8d2219aa423559f014704557938fd06ed632ac</url>
  <id>9e8d2219aa423559f014704557938fd06ed632ac</id>
  <committed-date>2008-08-18T14:40:38-07:00</committed-date>
  <authored-date>2008-08-18T14:40:38-07:00</authored-date>
  <message>began the refactoring of code to enable running on PostgreSQL backend</message>
  <tree>1ffe8e2135df1bf5528bf515aca27b8ab91190d0</tree>
  <committer>
    <name>Ben Adida</name>
    <email>ben@adida.net</email>
  </committer>
</commit>
