2007-03-27 Zsolt Foldvari <zfoldvar@users.sourceforge.net>

* src/GrampsDb/_GrampsDbBase.py: add note_bookmarks.
	* src/DataViews/_NoteView.py: 'add' and 'remove' functionalities added.
	* src/Editors/_EditNote.py: DeleteNoteQuery added.
	* src/DisplayTabs/_NoteModel.pya: unnecessary delete_tags call removed.
	* src/Utils.py: get_referents() and get_note_referents added();
	get_source_referents() and get_media_referents() rewritten.



svn: r8326
This commit is contained in:
Zsolt Foldvari 2007-03-27 18:28:26 +00:00
parent 2151ad9780
commit cbd230e24b
6 changed files with 141 additions and 105 deletions

View File

@ -1,3 +1,11 @@
2007-03-27 Zsolt Foldvari <zfoldvar@users.sourceforge.net>
* src/GrampsDb/_GrampsDbBase.py: add note_bookmarks.
* src/DataViews/_NoteView.py: 'add' and 'remove' functionalities added.
* src/Editors/_EditNote.py: DeleteNoteQuery added.
* src/DisplayTabs/_NoteModel.pya: unnecessary delete_tags call removed.
* src/Utils.py: get_referents() and get_note_referents added();
get_source_referents() and get_media_referents() rewritten.
2007-03-27 Brian Matherly <brian@gramps-project.org>
* src/ReportBase/_ReportDialog.py
* src/ReportBase/_BareReportDialog.py

View File

@ -17,14 +17,14 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# $Id: _PlaceView.py 8060 2007-02-06 05:19:16Z dallingham $
# $Id$
"""
Place View
"""
__author__ = "Don Allingham"
__revision__ = "$Revision: 8060 $"
__revision__ = "$Revision$"
#-------------------------------------------------------------------------
#
@ -38,17 +38,16 @@ import gtk
# gramps modules
#
#-------------------------------------------------------------------------
import RelLib
from RelLib import Note
import PageView
import DisplayModels
import Utils
import Errors
import Bookmarks
import Config
from DdTargets import DdTargets
from QuestionDialog import QuestionDialog, ErrorDialog
from Filters.SideBar import NoteSidebarFilter
from Editors import EditNote
from Editors import EditNote, DeleteNoteQuery
#-------------------------------------------------------------------------
#
@ -92,7 +91,7 @@ class NoteView(PageView.ListView):
PageView.ListView.__init__(
self, _('Notes'), dbstate, uistate, column_names,
len(column_names), DisplayModels.NoteModel, signal_map,
dbstate.db.get_place_bookmarks(),
dbstate.db.get_note_bookmarks(),
Bookmarks.NoteBookmarks,
filter_class=NoteSidebarFilter,
multiple=False)
@ -101,7 +100,7 @@ class NoteView(PageView.ListView):
self.filter_toggle)
def get_bookmarks(self):
return self.dbstate.db.get_place_bookmarks()
return self.dbstate.db.get_note_bookmarks()
def define_actions(self):
PageView.ListView.define_actions(self)
@ -166,7 +165,7 @@ class NoteView(PageView.ListView):
def on_double_click(self, obj, event):
handle = self.first_selected()
note = RelLib.Note()
note = Note()
try:
EditNote(self.dbstate, self.uistate, [], note)
except Errors.WindowActiveError:
@ -174,45 +173,31 @@ class NoteView(PageView.ListView):
def add(self, obj):
try:
pass
EditNote(self.dbstate, self.uistate, [], Note())
except Errors.WindowActiveError:
pass
def remove(self, obj):
for handle in self.selected_handles():
for note_handle in self.selected_handles():
db = self.dbstate.db
# person_list = [
# item[1] for item in
# self.dbstate.db.find_backlink_handles(place_handle,['Person'])]
the_lists = Utils.get_note_referents(note_handle, db)
# family_list = [
# item[1] for item in
# self.dbstate.db.find_backlink_handles(place_handle,['Family'])]
# event_list = [
# item[1] for item in
# self.dbstate.db.find_backlink_handles(place_handle,['Event'])]
# place = db.get_place_from_handle(place_handle)
# ans = DeletePlaceQuery(self.dbstate,self.uistate,
# place,person_list,family_list,event_list)
note = db.get_note_from_handle(note_handle)
# if len(person_list) + len(family_list) > 0:
# msg = _('This place is currently being used. Deleting it '
# 'will remove it from the database and from all '
# 'people and families that reference it.')
# else:
# msg = _('Deleting place will remove it from the database.')
ans = DeleteNoteQuery(self.dbstate, self.uistate, note, the_lists)
if filter(None, the_lists): # quick test for non-emptiness
msg = _('This note is currently being used. Deleting it '
'will remove it from the database and from all '
'other objects that reference it.')
else:
msg = _('Deleting note will remove it from the database.')
# msg = "%s %s" % (msg, Utils.data_recover_msg)
# descr = place.get_title()
# if descr == "":
# descr = place.get_gramps_id()
# self.uistate.set_busy_cursor(1)
# QuestionDialog(_('Delete %s?') % descr, msg,
# _('_Delete Place'), ans.query_response)
msg = "%s %s" % (msg, Utils.data_recover_msg)
descr = note.get_gramps_id()
self.uistate.set_busy_cursor(1)
QuestionDialog(_('Delete %s?') % descr, msg,
_('_Delete Note'), ans.query_response)
self.uistate.set_busy_cursor(0)
def edit(self, obj):

View File

@ -41,6 +41,6 @@ class NoteModel(gtk.ListStore):
note = self.db.get_note_from_handle(handle)
self.append(row=[
str(note.get_type()),
note.delete_tags(note.get()).replace('\n', ' ')[:80],
note.get().replace('\n', ' ')[:80],
handle,
])

View File

@ -247,3 +247,59 @@ class EditNote(EditPrimary):
Config.set(Config.NOTE_WIDTH, width)
Config.set(Config.NOTE_HEIGHT, height)
Config.sync()
class DeleteNoteQuery:
def __init__(self, dbstate, uistate, note, the_lists):
self.note = note
self.db = dbstate.db
self.uistate = uistate
self.the_lists = the_lists
def query_response(self):
trans = self.db.transaction_begin()
self.db.disable_signals()
(person_list, family_list, event_list, place_list, source_list,
media_list, repo_list) = self.the_lists
note_handle = self.note.get_handle()
for handle in person_list:
person = self.db.get_person_from_handle(handle)
person.remove_note(note_handle)
self.db.commit_person(person,trans)
for handle in family_list:
family = self.db.get_family_from_handle(handle)
family.remove_note(note_handle)
self.db.commit_family(family,trans)
for handle in event_list:
event = self.db.get_event_from_handle(handle)
event.remove_note(note_handle)
self.db.commit_event(event,trans)
for handle in place_list:
place = self.db.get_place_from_handle(handle)
place.remove_note(note_handle)
self.db.commit_place(place,trans)
for handle in source_list:
source = self.db.get_source_from_handle(handle)
source.remove_note(note_handle)
self.db.commit_source(source,trans)
for handle in media_list:
media = self.db.get_object_from_handle(handle)
media.remove_note(note_handle)
self.db.commit_media_object(media,trans)
for handle in repo_list:
repo = self.db.get_repository_from_handle(handle)
repo.remove_note(note_handle)
self.db.commit_repository(repo,trans)
self.db.enable_signals()
self.db.remove_note(note_handle, trans)
self.db.transaction_commit(
trans,_("Delete Source (%s)") % self.note.get_gramps_id())

View File

@ -211,9 +211,9 @@ class GrampsDbBase(GrampsDBCallback):
'note-update' : (list, ),
'note-delete' : (list, ),
'note-rebuild' : None,
'long-op-start' : (object, ),
'long-op-heartbeat' : None,
'long-op-end' : None
'long-op-start' : (object, ),
'long-op-heartbeat' : None,
'long-op-end' : None
}
@ -311,6 +311,7 @@ class GrampsDbBase(GrampsDBCallback):
self.source_bookmarks = GrampsDbBookmarks()
self.repo_bookmarks = GrampsDbBookmarks()
self.media_bookmarks = GrampsDbBookmarks()
self.note_bookmarks = GrampsDbBookmarks()
self.path = ""
self.name_group = {}
self.surname_list = []
@ -371,49 +372,49 @@ class GrampsDbBase(GrampsDBCallback):
assert False, "Needs to be overridden in the derived class"
def get_person_cursor_iter(self, msg=_("Processing Person records")):
return CursorIterator(self, self.get_person_cursor(), msg)
return CursorIterator(self, self.get_person_cursor(), msg)
def get_family_cursor(self):
assert False, "Needs to be overridden in the derived class"
def get_family_cursor_iter(self, msg=_("Processing Family records")):
return CursorIterator(self, self.get_family_cursor(), msg)
return CursorIterator(self, self.get_family_cursor(), msg)
def get_event_cursor(self):
assert False, "Needs to be overridden in the derived class"
def get_event_cursor_iter(self, msg=_("Processing Event records")):
return CursorIterator(self, self.get_event_cursor(), msg)
return CursorIterator(self, self.get_event_cursor(), msg)
def get_place_cursor(self):
assert False, "Needs to be overridden in the derived class"
def get_place_cursor_iter(self, msg=_("Processing Place records")):
return CursorIterator(self, self.get_place_cursor(), msg)
return CursorIterator(self, self.get_place_cursor(), msg)
def get_source_cursor(self):
assert False, "Needs to be overridden in the derived class"
def get_source_cursor_iter(self, msg=_("Processing Source records")):
return CursorIterator(self, self.get_source_cursor(), msg)
return CursorIterator(self, self.get_source_cursor(), msg)
def get_media_cursor(self):
assert False, "Needs to be overridden in the derived class"
def get_media_cursor_iter(self, msg=_("Processing Media records")):
return CursorIterator(self, self.get_media_cursor(), msg)
return CursorIterator(self, self.get_media_cursor(), msg)
def get_repository_cursor(self):
assert False, "Needs to be overridden in the derived class"
def get_repository_cursor_iter(self, msg=_("Processing Repository records")):
return CursorIterator(self, self.get_repository_cursor(), msg)
return CursorIterator(self, self.get_repository_cursor(), msg)
def get_note_cursor(self):
assert False, "Needs to be overridden in the derived class"
def get_note_cursor_iter(self, msg=_("Processing Note records")):
return CursorIterator(self, self.get_note_cursor(), msg)
return CursorIterator(self, self.get_note_cursor(), msg)
def open_undodb(self):
if not self.readonly:

View File

@ -793,72 +793,58 @@ def too_old(date,current_year=None):
#
#
#-------------------------------------------------------------------------
def get_source_referents(source_handle,db):
def get_referents(handle, db, primary_objects):
""" Find objects that refer to an object.
This function is the base for other get_<object>_referents finctions.
"""
Find objects that refer the source.
# Use one pass through the reference map to grab all the references
object_list = [item for item in db.find_backlink_handles(handle)]
# Then form the object-specific lists
the_lists = ()
for primary in primary_objects:
primary_list = [item[1] for item in object_list if item[0] == primary]
the_lists = the_lists + (primary_list,)
return the_lists
def get_source_referents(source_handle, db):
""" Find objects that refer the source.
This function finds all primary objects that refer (directly or through
secondary child-objects) to a given source handle in a given database.
"""
# Use one pass through the reference map to grab all the references
object_list = [item for item in db.find_backlink_handles(source_handle)]
# Then form the object-specific lists
# Persons
person_list = [item[1] for item in object_list if item[0] == 'Person']
# Families
family_list = [item[1] for item in object_list if item[0] == 'Family']
# Events
event_list = [item[1] for item in object_list if item[0] == 'Event']
# Places
place_list = [item[1] for item in object_list if item[0] == 'Place']
# Sources
source_list = [item[1] for item in object_list if item[0] == 'Source']
# Media Objects
media_list = [item[1] for item in object_list if item[0] == 'MediaObject']
# Repositories
repo_list = [item[1] for item in object_list if item[0] == 'Repository']
return (person_list,family_list,event_list,place_list,source_list,
media_list,repo_list)
"""
_primaries = ('Person', 'Family', 'Event', 'Place',
'Source', 'MediaObject', 'Repository')
return (get_referents(source_handle, db, _primaries))
def get_media_referents(media_handle,db):
"""
Find objects that refer the media object.
""" Find objects that refer the media object.
This function finds all primary objects that refer
to a given media handle in a given database.
"""
_primaries = ('Person', 'Family', 'Event', 'Place', 'Source')
return (get_referents(media_handle, db, _primaries))
# Use one pass through the reference map to grab all the references
object_list = [item for item in db.find_backlink_handles(media_handle)]
# Then form the object-specific lists
# Persons
person_list = [item[1] for item in object_list if item[0] == 'Person']
# Families
family_list = [item[1] for item in object_list if item[0] == 'Family']
# Events
event_list = [ item[1] for item in object_list if item[0] == 'Event']
# Places
place_list = [ item[1] for item in object_list if item[0] == 'Place']
# Sources
source_list = [ item[1] for item in object_list if item[0] == 'Source']
return (person_list,family_list,event_list,place_list,source_list)
def get_note_referents(note_handle, db):
""" Find objects that refer a note object.
This function finds all primary objects that refer
to a given note handle in a given database.
"""
_primaries = ('Person', 'Family', 'Event', 'Place',
'Source', 'MediaObject', 'Repository')
return (get_referents(note_handle, db, _primaries))
#-------------------------------------------------------------------------
#