Beispiel #1
0
def _fetch_voter_batch(unfetched_both_steps, unfetched_last_step, voter_records):
    starting_len = len(unfetched_both_steps) + \
        len(unfetched_last_step) + \
        len(voter_records)
    if len(unfetched_both_steps) > 0:
        unfetched_both_steps, new_voter_records, not_found_profiles = \
            _fetch_profiles(unfetched_both_steps, False)
        unfetched_last_step.extend(not_found_profiles)
        voter_records.extend(new_voter_records)
    if len(unfetched_last_step) > 0:
        unfetched_last_step, new_voter_records, not_found_profiles = \
            _fetch_profiles(unfetched_last_step, True)
        voter_records.extend(new_voter_records)
        for profile in not_found_profiles:
            v = VoterRecord(
                fb_uid=profile.uid,
                votizen_id="",
                registered=False)
            try:
                v.save()
                voter_records.append(v)
            except IntegrityError:
                voter_records.append(VoterRecord.objects.get(
                        fb_uid=profile.uid))
    return unfetched_both_steps, unfetched_last_step
Beispiel #2
0
def _fetch_voter_batch(unfetched_both_steps, unfetched_last_step, voter_records):
    starting_len = len(unfetched_both_steps) + \
        len(unfetched_last_step) + \
        len(voter_records)
    if len(unfetched_both_steps) > 0:
        unfetched_both_steps, new_voter_records, not_found_profiles = \
            _fetch_profiles(unfetched_both_steps, False)
        unfetched_last_step.extend(not_found_profiles)
        voter_records.extend(new_voter_records)
    if len(unfetched_last_step) > 0:
        unfetched_last_step, new_voter_records, not_found_profiles = \
            _fetch_profiles(unfetched_last_step, True)
        voter_records.extend(new_voter_records)
        for profile in not_found_profiles:
            v = VoterRecord(
                fb_uid=profile.uid,
                votizen_id="",
                registered=False)
            try:
                v.save()
                voter_records.append(v)
            except IntegrityError:
                voter_records.append(VoterRecord.objects.get(
                        fb_uid=profile.uid))
    return unfetched_both_steps, unfetched_last_step
Beispiel #3
0
def fetch_voter_from_fb_profile(fb_profile):
    fb_uid = fb_profile.uid
    existing_records = VoterRecord.objects.filter(fb_uid=fb_uid)[:1]
    if len(existing_records) > 0:
        return existing_records[0]
    params = _params_from_fb_profile(fb_profile, False)
    voter = _fetch_voter(**params)
    if not voter:
        params = _params_from_fb_profile(fb_profile, True)
        voter = _fetch_voter(**params)
    votizen_id = "" if not voter else voter.id
    registered = False if not voter else voter.registered
    if not VoterRecord.objects.filter(fb_uid=fb_uid).exists():
        try:
            v = VoterRecord(fb_uid=fb_uid,
                        votizen_id=votizen_id,
                        registered=registered)
            v.save()
        except IntegrityError:
            pass
    else:
        v = VoterRecord.objects.get(fb_uid=fb_uid)
    fill_voter_history([v])
    return v
Beispiel #4
0
def fetch_voter_from_fb_profile(fb_profile):
    fb_uid = fb_profile.uid
    existing_records = VoterRecord.objects.filter(fb_uid=fb_uid)[:1]
    if len(existing_records) > 0:
        return existing_records[0]
    params = _params_from_fb_profile(fb_profile, False)
    voter = _fetch_voter(**params)
    if not voter:
        params = _params_from_fb_profile(fb_profile, True)
        voter = _fetch_voter(**params)
    votizen_id = "" if not voter else voter.id
    registered = False if not voter else voter.registered
    if not VoterRecord.objects.filter(fb_uid=fb_uid).exists():
        try:
            v = VoterRecord(fb_uid=fb_uid,
                        votizen_id=votizen_id,
                        registered=registered)
            v.save()
        except IntegrityError:
            pass
    else:
        v = VoterRecord.objects.get(fb_uid=fb_uid)
    fill_voter_history([v])
    return v