lib/my_db.py
branchxbelweb
changeset 54 f74bad856bce
parent 53 e80160a19653
child 57 31271426f879
equal deleted inserted replaced
53:e80160a19653 54:f74bad856bce
     1 #!/usr/bin/python
       
     2 
       
     3 import pgdb
     1 import pgdb
     4 import config
     2 import config
     5 from bkmark import Bookmark
     3 from bkmark import Bookmark
     6 import os
     4 import os
     7 
     5 
   290 Return a list of id bookmarks who has /has_kw/ set but not /except_kw/.
   288 Return a list of id bookmarks who has /has_kw/ set but not /except_kw/.
   291 """
   289 """
   292 		qry = self._bookmarks_selection(has_kw, except_kw) + ';'
   290 		qry = self._bookmarks_selection(has_kw, except_kw) + ';'
   293 		self.crs.execute(qry)
   291 		self.crs.execute(qry)
   294 		return self.crs.fetchall()
   292 		return self.crs.fetchall()
   295 	def get_bookmarks_count(self, has_kw = [0], except_kw = []):
   293 	def get_bookmarks_count(self, has_kw = [0], except_kw = [], opt_kw = []):
   296 	        """
   294 	        """
   297 Return a count of bookmarks which would have been return on
   295 Return a count of bookmarks which would have been return on
   298 select_bookmarks qry.
   296 select_bookmarks qry.
   299 """
   297 """
   300 		qry = """
   298 		qry = """
   301 			SELECT COUNT(id) FROM bookmarks
   299 			SELECT keyword, COUNT(keyword)
   302 			WHERE userid = %d AND id IN """ % self.userid
   300 			FROM bookmarks_keywords
   303 		qry += "(" + self._bookmarks_selection(has_kw, except_kw) + ");"
   301 			WHERE userid = %d
   304 		self.crs.execute(qry)
   302 			""" % self.userid
   305 		result = self.crs.fetchone()
   303 		if len(opt_kw) > 0:
   306 		if result:
   304 			qry += "AND ( "
   307 			return result[0]
   305 			qry += " OR ".join(map(lambda e: "keyword = %d" % e, opt_kw))
   308 		else:
   306 			qry += ") "
   309 			return 0
   307 		qry += "AND bookmark IN (" + self._bookmarks_selection(has_kw, except_kw) + ") "
       
   308 		qry += "GROUP BY keyword ORDER BY keyword;"
       
   309 		self.crs.execute(qry)
       
   310 		return self.crs.fetchall()
   310 	def get_folder_keyword(self, id):
   311 	def get_folder_keyword(self, id):
   311 		self.crs.execute("""
   312 		self.crs.execute("""
   312 			SELECT k.id, k.name
   313 			SELECT k.id, k.name
   313 			FROM keywords k, folders f
   314 			FROM keywords k, folders f
   314 			WHERE
   315 			WHERE