Revision b32a2c5d

b/snf-astakos-app/astakos/quotaholder_app/migrations/0010_non_accepted.py
11 11
        )
12 12

  
13 13
    def forwards(self, orm):
14
        AstakosUser = orm["im.astakosuser"]
15
        users = AstakosUser.objects.filter(
16
            models.Q(moderated=False) |
17
            models.Q(moderated=True, is_rejected=True))
18
        uuids = set(users.values_list("uuid", flat=True))
19

  
20
        # no usage
21
        holdings = orm.Holding.objects.filter(holder__in=uuids)
22
        empty = len(holdings.filter(usage_min=0, usage_max=0))
23
        if empty:
24
            print "Deleting %s empty holdings" % empty
25
        holdings.filter(usage_min=0, usage_max=0).delete()
26

  
27
        # with usage
28
        hs = holdings.all()
29
        for h in hs:
30
            print "Warning: Deleting non-empty holding: %s, %s" % (h.holder,
31
                                                                   h.resource)
32
        holdings.all().delete()
14
        pass
33 15

  
34 16
    def backwards(self, orm):
35 17
        "Write your backwards methods here."

Also available in: Unified diff