def _save_results (self, record, results): """Save results for the given record to database. @param record: record to save for @type record: VotingRecord @param results: list of results, vote + name @type results: [ {'vote': str, 'name': str} ] """ for result in results: vrr = VotingRecordResult( record=record, vote=self._strip(result['vote']), name=self._strip(result['name'])) vrr.save()
def test_get_votecounts (self): vr = VotingRecord.objects.get(pk=1110) counts = {'abstained': 0, 'yes': 0, 'total': 0, 'absent': 0, 'no': 0} self.assertEqual(VotingRecordResult.get_counts(record=vr), counts) r = Representative.objects.get(pk=2) self.assertEqual(VotingRecordResult.get_counts(representative=r), counts) vr = VotingRecord.objects.get(pk=136) counts = {'abstained': 0, 'yes': 1, 'total': 4, 'absent': 0, 'no': 3} self.assertEqual(VotingRecordResult.get_counts(record=vr), counts) r = Representative.objects.get(pk=1) self.assertEqual(VotingRecordResult.get_counts(representative=r), counts)
def test_get_votecounts(self): vr = VotingRecord.objects.get(pk=1110) counts = {'abstained': 0, 'yes': 0, 'total': 0, 'absent': 0, 'no': 0} self.assertEqual(VotingRecordResult.get_counts(record=vr), counts) r = Representative.objects.get(pk=2) self.assertEqual(VotingRecordResult.get_counts(representative=r), counts) vr = VotingRecord.objects.get(pk=136) counts = {'abstained': 0, 'yes': 1, 'total': 4, 'absent': 0, 'no': 3} self.assertEqual(VotingRecordResult.get_counts(record=vr), counts) r = Representative.objects.get(pk=1) self.assertEqual(VotingRecordResult.get_counts(representative=r), counts)
def get_context_data(self, **kwargs): context = super(Detail, self).get_context_data(**kwargs) obj = context['obj'] context['form'] = self._get_form(obj) context['questions'] = self._get_questions(obj) context['votecounts'] = VotingRecordResult.get_counts(representative=obj) context['url_feed'] = reverse('representative_feed_detail', args=[obj.pk]) context['url_votingrecords'] = reverse( 'representative_votingrecords', args=[obj.pk, obj.slug]) try: context['decl'] = obj.incomedeclaration.all()[0] except IndexError: context['decl'] = None set_language_changer(self.request, obj.get_absolute_url) return context