def untag_file(file_id, tag_name): # Get gallery connection gallery = database.get_current_gallery("connection") cursor = gallery.cursor() # Get tag query_get_tags = "SELECT pk_id FROM tag WHERE name = \'%s\'" % (tag_name) cursor.execute(query_get_tags) tags = cursor.fetchall() for tag in tags: tag_id = tag[0] query_untag = ( "DELETE FROM file_has_tag WHERE pk_fk_file_id = %d " "AND pk_fk_tag_id = %d" % (file_id, tag_id)) cursor.execute(query_untag) # Write changes gallery.commit() output.change(file_id, tag_id, False)
def tag_file(file_id, tag_name, amount=-1): # Get gallery connection gallery = database.get_current_gallery("connection") cursor = gallery.cursor() # Get tag or create it if amount > -1: tag_id = create_tag(tag_name, True) elif amount == -1: tag_id = create_tag(tag_name) query_link = ( "INSERT INTO file_has_tag(pk_fk_file_id, pk_fk_tag_id, amount) " "VALUES (%d, %d, %d)" % (file_id, tag_id, amount) ) cursor.execute(query_link) # Write changes gallery.commit() output.change(file_id, tag_id, True)
def remove_file(file_id): gallery = database.get_current_gallery("connection") c = gallery.cursor() c.execute( ( "SELECT pk_id FROM tag " "JOIN file_has_tag ON pk_id=pk_fk_tag_id " "WHERE pk_fk_file_id=:file" ), { "file": file_id } ) tags = c.fetchall() for tag in tags: output.change(file_id, tag[0], False) c.execute("DELETE FROM file WHERE pk_id=%s" % str(file_id)) c.execute("DELETE FROM file_has_tag WHERE pk_fk_file_id=%s" % str(file_id)) gallery.commit()