Ejemplo n.º 1
0
 def apply_proxy(self, proxy_name, dbase):
     """Apply the named proxy to the database and return."""
     if proxy_name == "privacy":
         if self.private:
             dbase = PrivateProxyDb(dbase)
     elif proxy_name == "living":
         if self.living != LivingProxyDb.MODE_INCLUDE_ALL:
             dbase = LivingProxyDb(
                 dbase,
                 self.living,
                 current_year=self.current_year,
                 years_after_death=self.years_after_death,
                 llocale=self.locale,
             )
     elif proxy_name == "person":
         if self.pfilter is not None and not self.pfilter.is_empty():
             dbase = FilterProxyDb(dbase,
                                   person_filter=self.pfilter,
                                   user=User())
     elif proxy_name == "event":
         if self.efilter is not None and not self.efilter.is_empty():
             dbase = FilterProxyDb(dbase,
                                   event_filter=self.efilter,
                                   user=User())
     elif proxy_name == "note":
         if self.nfilter is not None and not self.nfilter.is_empty():
             dbase = FilterProxyDb(dbase,
                                   note_filter=self.nfilter,
                                   user=User())
     elif proxy_name == "reference":
         if self.reference:
             dbase = ReferencedBySelectionProxyDb(dbase, all_people=True)
     else:
         raise AttributeError("no such proxy '%s'" % proxy_name)
     return dbase
Ejemplo n.º 2
0
    def apply_proxy(self, proxy_name, dbase, progress=None):
        """
        Apply the named proxy to the dbase, and return.
        proxy_name is one of
           ["person", "note", "privacy", "living", "reference"]
        """
        # If the private flag is set, apply the PrivateProxyDb
        if proxy_name == "privacy":
            if self.private:
                if progress:
                    progress.reset(_("Filtering private data"))
                    progress.progress_cnt += 1
                    progress.update(progress.progress_cnt)
                dbase = PrivateProxyDb(dbase)

        # If the restrict flag is set, apply the LivingProxyDb
        elif proxy_name == "living":
            if self.restrict_num > 0:
                if progress:
                    progress.reset(_("Filtering living persons"))
                    progress.progress_cnt += 1
                    progress.update(progress.progress_cnt)
                mode = [
                    None,  # include living
                    LivingProxyDb.MODE_INCLUDE_LAST_NAME_ONLY,
                    LivingProxyDb.MODE_EXCLUDE_ALL,
                ][self.restrict_num]
                dbase = LivingProxyDb(dbase, mode)  #

        # If the filter returned by cfilter is not empty, apply the
        # FilterProxyDb (Person Filter)
        elif proxy_name == "person":
            if self.cfilter != None and not self.cfilter.is_empty():
                if progress:
                    progress.reset(_("Applying selected person filter"))
                    progress.progress_cnt += 1
                    progress.update(progress.progress_cnt)
                dbase = FilterProxyDb(dbase, self.cfilter)

        # Apply the Note Filter
        elif proxy_name == "note":
            if self.nfilter != None and not self.nfilter.is_empty():
                if progress:
                    progress.reset(_("Applying selected note filter"))
                    progress.progress_cnt += 1
                    progress.update(progress.progress_cnt)
                dbase = FilterProxyDb(dbase, note_filter=self.nfilter)

        # Apply the ReferencedBySelection
        elif proxy_name == "reference":
            if progress:
                progress.reset(_("Filtering referenced records"))
                progress.progress_cnt += 1
                progress.update(progress.progress_cnt)
            if self.reference_num == 0:
                pass
            elif self.reference_num == 1:
                dbase = ReferencedBySelectionProxyDb(dbase, all_people=True)
        else:
            raise AttributeError("no such proxy '%s'" % proxy_name)

        return dbase