Пример #1
0
 def test_send_candidate_their_username_and_password(self):
     contact = CandidacyContact.objects.create(candidate=self.candidate,
                                               mail='*****@*****.**')
     send_candidate_username_and_password(self.candidate)
     contact = CandidacyContact.objects.get(id=contact.id)
     self.assertEquals(contact.times_email_has_been_sent, 1)
     self.assertEquals(len(mail.outbox), 1)
     the_mail = mail.outbox[0]
     self.assertIn(contact.initial_password, the_mail.body)
 def test_send_candidate_their_username_and_password(self):
     contact = CandidacyContact.objects.create(candidate=self.candidate,
                                               mail='*****@*****.**')
     send_candidate_username_and_password(self.candidate)
     contact = CandidacyContact.objects.get(id=contact.id)
     self.assertEquals(contact.times_email_has_been_sent, 1)
     self.assertEquals(len(mail.outbox), 1)
     the_mail = mail.outbox[0]
     self.assertIn(contact.initial_password, the_mail.body)
def process_candidates():
    reader = codecs.open("candidates.csv", 'r', encoding='utf-8')
    counter = 0
    candidates_ids = []
    for line in reader:
        row = line.split(u',')
        area_name = row[0].title().strip()
        area = area_getter(area_name)
        if area is None:
            print u'no encontré a ' + area_name
            return
        kind_of = row[1].title().strip()
        election_name = kind_of + u' por ' + area.name
        if not Election.objects.filter(name__iexact=election_name):
            print u"no pillé a " + election_name
            # Candidate.objects.filter(id__in=candidates_ids).delete()
            return
        else:
            e = Election.objects.get(name__iexact=election_name)
        name = row[2].title().strip()
        candidate = Candidate(name=name)

        candidate.save()
        candidates_ids.append(candidate.id)
        e.candidates.add(candidate)
        print e, candidate
        try:
            mail = row[6].strip().lower()
        except IndexError:
            mail = None
        if mail:
            contact = CandidacyContact.objects.create(candidate=candidate,
                                                      mail=mail)

        pacto = row[3].strip().title()
        sub_pacto = row[4].strip().title()
        partido = row[5].strip().title()
        if pacto:
            PersonalData.objects.create(candidate=candidate,
                                        label=u'Pacto',
                                        value=pacto)
        if sub_pacto:
            PersonalData.objects.create(candidate=candidate,
                                        label=u'Sub Pacto',
                                        value=sub_pacto)
        if partido:
            PersonalData.objects.create(candidate=candidate,
                                        label=u'Partido',
                                        value=partido)
        send_candidate_username_and_password(candidate)
        counter += 1
        if not counter % 1000:
            print u'van' + str(counter)
def process_candidates():
    reader = codecs.open("candidates.csv", 'r', encoding='utf-8')
    counter = 0
    candidates_ids = []
    for line in reader:
        row = line.split(u',')
        area_name = row[0].title().strip()
        area = area_getter(area_name)
        if area is None:
            print u'no encontré a '+ area_name
            return
        kind_of = row[1].title().strip()
        election_name = kind_of + u' por ' + area.name
        if not Election.objects.filter(name__iexact=election_name):
            print u"no pillé a " + election_name
            # Candidate.objects.filter(id__in=candidates_ids).delete()
            return
        else:
            e = Election.objects.get(name__iexact=election_name)
        name = row[2].title().strip()
        candidate = Candidate(name=name)

        candidate.save()
        candidates_ids.append(candidate.id)
        e.candidates.add(candidate)
        print e, candidate
        try:
            mail = row[6].strip().lower()
        except IndexError:
            mail = None
        if mail:
            contact = CandidacyContact.objects.create(candidate=candidate,
                                                      mail=mail)

        pacto = row[3].strip().title()
        sub_pacto = row[4].strip().title()
        partido = row[5].strip().title()
        if pacto:
            PersonalData.objects.create(candidate=candidate,
                                        label=u'Pacto',
                                        value=pacto)
        if sub_pacto:
            PersonalData.objects.create(candidate=candidate,
                                        label=u'Sub Pacto',
                                        value=sub_pacto)
        if partido:
            PersonalData.objects.create(candidate=candidate,
                                        label=u'Partido',
                                        value=partido)
        send_candidate_username_and_password(candidate)
        counter += 1
        if not counter % 1000:
            print u'van' + str(counter)
def send_user_to_candidates():
	for candidate in Candidate.objects.all():
		send_candidate_username_and_password(candidate)
 def test_dont_send_mails_to_candidates_if_they_have_been_contacted(self):
     CandidacyContact.objects.create(candidate=self.candidate,
                                     used_by_candidate=True,
                                     mail='*****@*****.**')
     send_candidate_username_and_password(self.candidate)
     self.assertEquals(len(mail.outbox), 0)
Пример #7
0
def send_user_to_candidates():
    for candidate in Candidate.objects.all():
        send_candidate_username_and_password(candidate)
Пример #8
0
def send_user_to_candidate_from(area):
    for election in area.elections.all():
        for candidate in election.candidates.all().exclude(id__in=excluded):
            send_candidate_username_and_password(candidate)
Пример #9
0
 def test_dont_send_mails_to_candidates_if_they_have_been_contacted(self):
     CandidacyContact.objects.create(candidate=self.candidate,
                                     used_by_candidate=True,
                                     mail='*****@*****.**')
     send_candidate_username_and_password(self.candidate)
     self.assertEquals(len(mail.outbox), 0)
Пример #10
0
 def test_not_send_candidate_their_username_and_password(self):
     contact = CandidacyContact.objects.create(candidate=self.candidate,
                                               mail='*****@*****.**')
     send_candidate_username_and_password(self.candidate)
     self.assertEquals(len(mail.outbox), 0)
 def test_not_send_candidate_their_username_and_password(self):
     contact = CandidacyContact.objects.create(candidate=self.candidate,
                                               mail='*****@*****.**')
     send_candidate_username_and_password(self.candidate)
     self.assertEquals(len(mail.outbox), 0)
def send_user_to_candidate_from(area):
    for election in area.elections.all():
        for candidate in election.candidates.all().exclude(id__in=excluded):
            send_candidate_username_and_password(candidate)