Beispiel #1
0
 def execute(self,**kw):
     self.analyze() # refresh since there may be changes since summary()
     # give others a chance to object
     #~ pre_merge.send(self.obj,merge_to=self.merge_to)
     kw.update(sender=self)
     pre_merge.send(**kw)
     update_count = 0
     # change FK fields of related objects
     for fk,qs in self.related:
         #~ print 20131026, qs.query, fk.name, self.merge_to
         update_count += qs.update(**{fk.name:self.merge_to})
         #~ for relobj in qs:
             #~ setattr(relobj,fk.name,merge_to)
             #~ relobj.full_clean()
             #~ relobj.save()
     
     # merge GenericForeignKey relations
     for gfk,qs in self.generic_related:
         update_count += qs.update(**{gfk.fk_field:self.merge_to.pk})
         #~ for i in qs:
             #~ setattr(qs,gfk.fk_field,merge_to.pk)
             #~ # setattr(qs,gfk.name,merge_to)
             #~ i.full_clean()
             #~ i.save()
         
     # Build the return message
     msg = _("Merged %(this)s into %(merge_to)s. Updated %(updated)d related rows.") % dict(
         this=self.obj,merge_to=self.merge_to,updated=update_count)
         
     # delete any reference to the deleted object
     self.obj.delete()
     del self.obj
     return msg
Beispiel #2
0
    def execute(self, **kw):
        self.analyze()  # refresh since there may be changes since summary()
        # give others a chance to object
        #~ pre_merge.send(self.obj,merge_to=self.merge_to)
        kw.update(sender=self)
        pre_merge.send(**kw)
        update_count = 0
        # change FK fields of related objects
        for fk, qs in self.related:
            #~ print 20131026, qs.query, fk.name, self.merge_to
            update_count += qs.update(**{fk.name: self.merge_to})
            #~ for relobj in qs:
            #~ setattr(relobj,fk.name,merge_to)
            #~ relobj.full_clean()
            #~ relobj.save()

        # merge GenericForeignKey relations
        for gfk, qs in self.generic_related:
            update_count += qs.update(**{gfk.fk_field: self.merge_to.pk})
            #~ for i in qs:
            #~ setattr(qs,gfk.fk_field,merge_to.pk)
            # ~ # setattr(qs,gfk.name,merge_to)
            #~ i.full_clean()
            #~ i.save()

        # Build the return message
        msg = _(
            "Merged %(this)s into %(merge_to)s. Updated %(updated)d related rows."
        ) % dict(this=self.obj, merge_to=self.merge_to, updated=update_count)
        # Delete object from database:
        self.obj.delete()

        # Delete the reference to the deleted object:
        del self.obj
        return msg