1
1
#
2
2
# Gramps - a GTK+/GNOME based genealogy program
3
3
#
4
+ # Copyright (C) 2020 David Straub
4
5
# Copyright (C) 2019 Matthias Kemmer
5
6
#
6
7
# This program is free software; you can redistribute it and/or modify
22
23
# GRAMPS modules
23
24
#
24
25
# ----------------------------------------------------------------------------
26
+ from gramps .gen .filters import CustomFilters , GenericFilterFactory
25
27
from gramps .gui .plug import MenuToolOptions , PluginWindows
26
- from gramps .gen .plug .menu import NumberOption , BooleanOption
28
+ from gramps .gen .plug .menu import NumberOption , BooleanOption , FilterOption
27
29
from gramps .gui .dialog import OkDialog
28
30
from gramps .gen .lib .date import Today
29
31
from gramps .gen .db import DbTxn
@@ -93,34 +95,46 @@ def lock_persons(self, date, lock_no_date):
93
95
with DbTxn (_ ("Set Privacy Tool" ), self .db , batch = True ) as self .trans :
94
96
self .db .disable_signals ()
95
97
person_list = list (self .db .iter_people ())
98
+
99
+ filter_option = self .options .menu .get_option_by_name ('person_filter' )
100
+ person_filter = filter_option .get_filter ()
101
+ filtered_person_handles = person_filter .apply (self .db , self .db .iter_person_handles ())
102
+
96
103
self .progress .set_pass (_ ('Set persons private..' ),
97
- len (person_list ))
104
+ len (filtered_person_handles ))
98
105
cnt = [0 , 0 ]
106
+
107
+
99
108
for Person in person_list :
109
+ if Person .handle not in filtered_person_handles :
110
+ continue
100
111
birth_ref = Person .get_birth_ref ()
101
112
if birth_ref :
102
113
birth = self .db .get_event_from_handle (birth_ref .ref )
103
114
birth_date = birth .get_date_object ()
115
+ set_privacy = None
104
116
if birth_date .get_year () == 0 and lock_no_date :
105
- Person . set_privacy ( True )
117
+ set_privacy = True
106
118
cnt [0 ] += 1
107
119
elif birth_date .get_year () == 0 and not lock_no_date :
108
- Person . set_privacy ( False )
120
+ set_privacy = False
109
121
cnt [1 ] += 1
110
122
elif birth_date .get_year () != 0 and birth_date >= date :
111
- Person . set_privacy ( True )
123
+ set_privacy = True
112
124
cnt [0 ] += 1
113
125
else :
114
- Person . set_privacy ( False )
126
+ set_privacy = False
115
127
cnt [1 ] += 1
116
128
else :
117
129
if lock_no_date :
118
- Person . set_privacy ( True )
130
+ set_privacy = True
119
131
cnt [0 ] += 1
120
132
else :
121
- Person . set_privacy ( False )
133
+ set_privacy = False
122
134
cnt [1 ] += 1
123
- self .db .commit_person (Person , self .trans )
135
+ if set_privacy is not None and set_privacy != Person .private :
136
+ Person .set_privacy (set_privacy )
137
+ self .db .commit_person (Person , self .trans )
124
138
self .progress .step ()
125
139
self .db .enable_signals ()
126
140
self .db .request_rebuild ()
@@ -130,24 +144,35 @@ def lock_events(self, date, lock_no_date):
130
144
with DbTxn (_ ("Set Privacy Tool" ), self .db , batch = True ) as self .trans :
131
145
self .db .disable_signals ()
132
146
event_list = list (self .db .iter_events ())
147
+
148
+ filter_option = self .options .menu .get_option_by_name ('event_filter' )
149
+ event_filter = filter_option .get_filter ()
150
+ filtered_event_handles = event_filter .apply (self .db , self .db .iter_event_handles ())
151
+
133
152
self .progress .set_pass (_ ('Set events private..' ),
134
- len (event_list ))
153
+ len (filtered_event_handles ))
154
+
135
155
cnt = [0 , 0 ]
136
156
for Event in event_list :
157
+ if Event .handle not in filtered_event_handles :
158
+ continue
137
159
event_date = Event .get_date_object ()
160
+ set_privacy = None
138
161
if event_date .get_year () == 0 and lock_no_date :
139
- Event . set_privacy ( True )
162
+ set_privacy = True
140
163
cnt [0 ] += 1
141
164
elif event_date .get_year () == 0 and not lock_no_date :
142
- Event . set_privacy ( False )
165
+ set_privacy = False
143
166
cnt [1 ] += 1
144
167
elif event_date .get_year () != 0 and event_date >= date :
145
- Event . set_privacy ( True )
168
+ set_privacy = True
146
169
cnt [0 ] += 1
147
170
else :
148
- Event . set_privacy ( False )
171
+ set_privacy = False
149
172
cnt [1 ] += 1
150
- self .db .commit_event (Event , self .trans )
173
+ if set_privacy is not None and set_privacy != Event .private :
174
+ Event .set_privacy (set_privacy )
175
+ self .db .commit_event (Event , self .trans )
151
176
self .progress .step ()
152
177
self .db .enable_signals ()
153
178
self .db .request_rebuild ()
@@ -157,24 +182,35 @@ def lock_media(self, date, lock_no_date):
157
182
with DbTxn (_ ("Set Privacy Tool" ), self .db , batch = True ) as self .trans :
158
183
self .db .disable_signals ()
159
184
media_list = list (self .db .iter_media ())
185
+
186
+ filter_option = self .options .menu .get_option_by_name ('media_filter' )
187
+ media_filter = filter_option .get_filter ()
188
+ filtered_media_handles = media_filter .apply (self .db , self .db .iter_media_handles ())
189
+
160
190
self .progress .set_pass (_ ('Set media private..' ),
161
- len (media_list ))
191
+ len (filtered_media_handles ))
192
+
162
193
cnt = [0 , 0 ]
163
194
for Media in media_list :
195
+ if Media .handle not in filtered_media_handles :
196
+ continue
164
197
media_date = Media .get_date_object ()
198
+ set_privacy = None
165
199
if media_date .get_year () == 0 and lock_no_date :
166
- Media . set_privacy ( True )
200
+ set_privacy = True
167
201
cnt [0 ] += 1
168
202
elif media_date .get_year () == 0 and not lock_no_date :
169
- Media . set_privacy ( False )
203
+ set_privacy = False
170
204
cnt [1 ] += 1
171
205
elif media_date .get_year () != 0 and media_date >= date :
172
- Media . set_privacy ( True )
206
+ set_privacy = True
173
207
cnt [0 ] += 1
174
208
else :
175
- Media . set_privacy ( False )
209
+ set_privacy = False
176
210
cnt [1 ] += 1
177
- self .db .commit_media (Media , self .trans )
211
+ if set_privacy is not None and set_privacy != Media .private :
212
+ Media .set_privacy (set_privacy )
213
+ self .db .commit_media (Media , self .trans )
178
214
self .progress .step ()
179
215
self .db .enable_signals ()
180
216
self .db .request_rebuild ()
@@ -192,15 +228,40 @@ def __init__(self, name, person_id=None, dbstate=None):
192
228
MenuToolOptions .__init__ (self , name , person_id , dbstate )
193
229
194
230
def add_menu_options (self , menu ):
231
+
195
232
self .person = BooleanOption (_ ("Persons" ), False )
196
233
menu .add_option (_ ("Option" ), "person" , self .person )
197
234
235
+ self .__person_filter = FilterOption (_ ("Person Filter" ), 0 )
236
+ self .__person_filter .set_help (_ ("Select filter to restrict people" ))
237
+ menu .add_option (_ ("Option" ), "person_filter" , self .__person_filter )
238
+ person_filter_all = GenericFilterFactory ("Person" )()
239
+ person_filter_all .name = _ ("Entire Database" )
240
+ person_filter_list = [person_filter_all ] + CustomFilters .get_filters ("Person" )
241
+ self .__person_filter .set_filters (person_filter_list )
242
+
198
243
self .event = BooleanOption (_ ("Events" ), False )
199
244
menu .add_option (_ ("Option" ), "event" , self .event )
200
245
246
+ self .__event_filter = FilterOption (_ ("Event Filter" ), 0 )
247
+ self .__event_filter .set_help (_ ("Select filter to restrict events" ))
248
+ menu .add_option (_ ("Option" ), "event_filter" , self .__event_filter )
249
+ event_filter_all = GenericFilterFactory ("Event" )()
250
+ event_filter_all .name = _ ("Entire Database" )
251
+ event_filter_list = [event_filter_all ] + CustomFilters .get_filters ('Event' )
252
+ self .__event_filter .set_filters (event_filter_list )
253
+
201
254
self .media = BooleanOption (_ ("Media" ), False )
202
255
menu .add_option (_ ("Option" ), "media" , self .media )
203
256
257
+ self .__media_filter = FilterOption (_ ("Media Filter" ), 0 )
258
+ self .__media_filter .set_help (_ ("Select filter to restrict medias" ))
259
+ menu .add_option (_ ("Option" ), "media_filter" , self .__media_filter )
260
+ media_filter_all = GenericFilterFactory ("Media" )()
261
+ media_filter_all .name = _ ("Entire Database" )
262
+ media_filter_list = [media_filter_all ] + CustomFilters .get_filters ('Media' )
263
+ self .__media_filter .set_filters (media_filter_list )
264
+
204
265
self .no_date = BooleanOption (_ ("Always private if no date." ), False )
205
266
self .no_date .set_help (_ ("If checked, all objects without a date will "
206
267
"also be set private." ))
0 commit comments