Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEsteban Bordon <ebordon@plan.ceibal.edu.uy>2012-04-16 16:52:38 (GMT)
committer Esteban Bordon <ebordon@plan.ceibal.edu.uy>2012-04-16 16:52:38 (GMT)
commitf717b4e99b57e6d87ec4d7ba2a58c92989a95c28 (patch)
tree6be82cb1873a69f2e466ab041db816de2dcc620e
parent56811517bc85b6d64ed752c0400803a47eb7c9a8 (diff)
Se agregan funciones en store.py para poder eliminar mensajes y agregar o quitar de favorito. Se modifica la estructura de la base para contemplar si un mensaje está marcado como favorito. Se agrega la función is_fav que devuelve el valor seteado para ese campo (0:False, 1:True)
-rw-r--r--store.py38
1 files changed, 36 insertions, 2 deletions
diff --git a/store.py b/store.py
index 6c271b2..2c905c2 100644
--- a/store.py
+++ b/store.py
@@ -1,6 +1,6 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
-# 2011-12-16
+# 2012-04-16
# Autor: Esteban Bordón - ebordon@plan.ceibal.edu.uy
#
# Guarda los mensajes obtenidos desde el servidor
@@ -18,7 +18,7 @@ import shelve
class Db:
def __init__(self, db_filename=None):
init_db = """
-CREATE TABLE IF NOT EXISTS notifications (id INTEGER PRIMARY KEY,title VARCHAR(30) NOT NULL ON CONFLICT REPLACE DEFAULT '',text TEXT NOT NULL ON CONFLICT REPLACE DEFAULT '', priority INTEGER NOT NULL, launched DATE NOT NULL ON CONFLICT REPLACE DEFAULT 00000000,expires DATETIME, type VARCHAR(15) NOT NULL ON CONFLICT REPLACE DEFAULT ''); """
+CREATE TABLE IF NOT EXISTS notifications (id INTEGER PRIMARY KEY,title VARCHAR(30) NOT NULL ON CONFLICT REPLACE DEFAULT '',text TEXT NOT NULL ON CONFLICT REPLACE DEFAULT '', priority INTEGER NOT NULL, launched DATE NOT NULL ON CONFLICT REPLACE DEFAULT 00000000,expires DATETIME, type VARCHAR(15) NOT NULL ON CONFLICT REPLACE DEFAULT '',fav INTEGER NOT NULL ON CONFLICT REPLACE DEFAULT 0 ); """
if db_filename:
self._db_filename = db_filename
else:
@@ -43,6 +43,7 @@ CREATE TABLE IF NOT EXISTS notifications (id INTEGER PRIMARY KEY,title VARCHAR(3
conn.close()
def add_message(self, keys, values):
+ """Agrega un mensaje a la base de datos"""
con = self._connect()
c = con.cursor()
c.execute('BEGIN TRANSACTION')
@@ -53,7 +54,40 @@ CREATE TABLE IF NOT EXISTS notifications (id INTEGER PRIMARY KEY,title VARCHAR(3
c.execute('END TRANSACTION')
self._close_connection(con)
+ def remove_message(self, id_msg):
+ """Elimina el mensaje de la base de datos"""
+ con = self._connect()
+ c = con.cursor()
+ c.execute('BEGIN TRANSACTION')
+ try:
+ c.execute('delete from notifications where id=%i' %id)
+ except sqlite3.IntegrityError,e:
+ print "Error al eliminar datos: %s" %str(e)
+ c.execute('END TRANSACTION')
+ self._close_connection(con)
+
+ def set_fav(self, id_msg, fav=True):
+ """Marca un mensaje como favorito.
+ Si fav == False lo desmarca"""
+ con = self._connect()
+ c = con.cursor()
+ c.execute('BEGIN TRANSACTION')
+ try:
+ c.execute('update notifications set fav=%i where id=%i' %(int(fav),id))
+ except sqlite3.IntegrityError,e:
+ print "Error al eliminar datos: %s" %str(e)
+ c.execute('END TRANSACTION')
+ self._close_connection(con)
+
+ def is_fav(self, id_msg):
+ fav = self.run_query("select fav from notifications where id=%i" %id_msg)
+ return fav[0]['fav']
+
def run_query(self, query):
+ """
+ Ejecuta una consulta cualquiera a la base de datos.
+ Retorna el resultado de dicha consulta
+ """
con = self._connect()
con.row_factory = self.dict_factory
c = con.cursor()