Commits

tjama committed 3de1597

fix

Comments (0)

Files changed (2)

game/database.py

-import psycopg2
-import psycopg2.extras
-psycopg2.extensions.register_type(psycopg2.extensions.UNICODE)
-psycopg2.extensions.register_type(psycopg2.extensions.UNICODEARRAY)
-from exce import ntae
-
-class MyDbConnection(object):
-    def __init__(self):
-        self.connection = psycopg2.connect("dbname='django_db' user='django' host='109.74.206.67' password='V0N4Pqzq13A0T78EKKpd'")
-        #self.connection = psycopg2.connect("dbname='animu' user='animu' host='localhost' password='mudkipz666'")
-
-    def get(self, query, *parameters):
-        """Returns the first row returned for the given query."""
-        try:
-            cursor = self.connection.cursor(cursor_factory=psycopg2.extras.NamedTupleCursor)
-            cursor.execute(query, *parameters)
-            self.connection.commit()
-            rows = cursor.fetchall()
-            if not rows:
-                return None
-            elif len(rows) > 1:
-                raise Exception("Multiple rows returned for Database.get() query")
-            else:
-                return rows[0]
-        except Exception, e:
-            ntae.process_exception(e, {'query':query, 'parameters': parameters})
-        
-
-    def query(self, query, *parameters):
-        try:
-            cursor = self.connection.cursor(cursor_factory=psycopg2.extras.NamedTupleCursor)
-            cursor.execute(query, *parameters)
-            rows = cursor.fetchall()
-            return rows
-        except Exception, e:
-            ntae.process_exception(e, {'query':query, 'parameters': parameters})     
-            
-    def queryDict(self, query, *parameters):
-        try:
-            cursor = self.connection.cursor(cursor_factory=psycopg2.extras.RealDictCursor)
-            cursor.execute(query, *parameters)
-            rows = cursor.fetchall()
-            return rows
-        except Exception, e:
-            ntae.process_exception(e, {'query':query, 'parameters': parameters})     
-    
-    def execute(self, query, *parameters):
-        try:
-            cursor = self.connection.cursor()
-            cursor.execute(query, *parameters)
-            self.connection.commit()
-            return cursor.lastrowid
-        except Exception, e:
-            ntae.process_exception(e, {'query':query, 'parameters': parameters})        
-
-    def execute_rowcount(self, query, *parameters):
-        """Executes the given query, returning the rowcount from the query."""            
-        try:
-            cursor = self.connection.cursor()
-            cursor.execute(query, *parameters)
-            return cursor.rowcount
-        except Exception, e:
-            ntae.process_exception(e, {'query':query, 'parameters': parameters})
-        finally:
-            cursor.close()
-
-db = MyDbConnection()
             if self.get_current_user():
                 player = users[self.get_current_user().name]['player']
             else:
-                check_xsrf_cookie()
+                self.check_xsrf_cookie()
                 player = users[self.xsrf_token]['player']
             self.write(loader.load('questionnew.html').generate(player=player,game_id=game_id))
         except Exception, e:
             if self.get_current_user():
                 player = users[self.get_current_user().name]['player']
             else:
-                check_xsrf_cookie()
+                self.check_xsrf_cookie()
                 player = users[self.xsrf_token]['player']
             self.write(loader.load('pointsnew.html').generate(player=player,game_id=game_id))
         except Exception, e: