@@ -0,0 +1,1514 @@
+# From (I believe) historical bugs, some candidates are missing PopIt%0A# memberships.  This command will recreate them based on their%0A# standing_in and party_memberships data.%0A#%0A#   e.g. ./manage.py candidates_recreate_memberships 2825 3411%0A%0Afrom django.core.management.base import BaseCommand, CommandError%0A%0Afrom candidates.cache import invalidate_posts, invalidate_person%0Afrom candidates.models import PopItPerson%0Afrom candidates.popit import create_popit_api_object, PopItApiMixin%0A%0Aclass Command(PopItApiMixin, BaseCommand):%0A%0A    args = %22%3CPERSON-ID%3E ...%22%0A    help = %22Recreate one or more person's memberships (for fixing bad data)%22%0A%0A    def handle(self, *args, **kwargs):%0A        api = create_popit_api_object()%0A        if len(args) %3C 1:%0A            raise CommandError(%22You must provide one or more PopIt person ID%22)%0A        for person_id in args:%0A            person = PopItPerson.create_from_popit(api, person_id)%0A            posts_to_invalidate = person.get_associated_posts()%0A            person.delete_memberships(api)%0A            # The memberships are recreated when you assign to%0A            # standing_in and party_memberships; this script assumes%0A            # these are correct and so re-setting these should%0A            # recreate the memberships correctly.%0A            person.standing_in = person.standing_in%0A            person.party_memberships = person.party_memberships%0A            person.save_to_popit(api)%0A            invalidate_posts(posts_to_invalidate)%0A            invalidate_person(person_id)%0A

Put back a new candidates_recreate_memberships command