1# -*- coding: UTF-8 -*- 2 3__revision__ = '$Id$' 4 5# Copyright © 2009 Piotr Ożarowski 6# 7# This program is free software; you can redistribute it and/or modify 8# it under the terms of the GNU General Public License as published byp 9# the Free Software Foundation; either version 2 of the License, or 10# (at your option) any later version. 11# 12# This program is distributed in the hope that it will be useful, 13# but WITHOUT ANY WARRANTY; without even the implied warranty of 14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15# GNU Library General Public License for more details. 16# 17# You should have received a copy of the GNU General Public License 18# along with this program; if not, write to the Free Software 19# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 20 21# You may use and distribute this software under the terms of the 22# GNU General Public License, version 2 or later 23 24import logging 25 26from sqlalchemy.sql import update, select 27 28from db.tables import movies as movies_table 29from gutils import question 30from plugins.extensions import GriffithExtensionBase as Base 31from sql import update_whereclause 32from quick_filter import change_filter_update_whereclause 33 34log = logging.getLogger('Griffith') 35 36class GriffithExtension(Base): 37 name = 'Mark as seen' 38 description = _('Marks all currently filtered movies as seen') 39 author = 'Piotr Ożarowski' 40 email = 'piotr@griffith.cc' 41 version = 0.1 42 api = 1 43 enabled = False # disabled by default 44 45 toolbar_icon = 'ge_mark_seen.png' 46 47 def toolbar_icon_clicked(self, widget, movie): 48 if question(_('Are you sure you want to update %d movies?') % self.app.total): 49 session = self.db.Session() 50 51 query = select([movies_table.c.movie_id]) 52 # add conditions from simple filter 53 change_filter_update_whereclause(self.app, query) 54 # add conditions from adv filter 55 query = update_whereclause(query, self.app._search_conditions) 56 movie_ids = [] 57 for movie_entry in session.execute(query): 58 movie_ids.append(movie_entry.movie_id) 59 60 update_query = update(movies_table, values={'seen': True}) 61 update_query = update_query.where(movies_table.c.movie_id.in_(movie_ids)) 62 log.debug(update_query) 63 session.execute(update_query) 64 session.commit() 65 66 self.app.populate_treeview() # update seen widget in the list 67