def _create_representative(self, row): """Create a complete Representative record. @param row: data row @type row: [ str ] @return: a representative @rtype: representative.Representative """ name = glt.firstname_first(row[1]) self.stdout.write("%s | Representative: %s ... " % (row[0], name)) dob = self._get_isodate(row[7].decode("utf-8")) representative = Representative(date_of_birth=dob, description=row[6].decode("utf-8").strip(), unit=self.unit) representative.save() pname = PersonName(person=representative, name=name, main=True) pname.save() people = Representative.objects.filter(slug=representative.slug) if len(people) > 1: if self.force: people.exclude(pk=representative.pk).delete() self.stdout.write("replace existing!\n") self._add_representative_data(row, representative) return representative else: self.stdout.write("keep already existing!\n") slug = representative.slug representative.delete() return Representative.objects.get(slug=slug) else: self.stdout.write("add new!\n") self._add_representative_data(row, representative) return representative
def test_Representative_find (self): name = u'idontexistinthisdatabase' self.assertEqual(Representative.find(name), None) name = u'Foo Bar' self.assertNotEqual(Representative.find(name), None) name = u'აბულაშვილი ნუგზარი' self.assertNotEqual(Representative.find(name), None) name = u'ნუგზარ აბულაშვილი' self.assertNotEqual(Representative.find(name), None) name = u'აბულაშვილი' self.assertNotEqual(Representative.find(name), None) name = u'ნუგზარი' self.assertNotEqual(Representative.find(name), None) name = u'ნუგზარ' self.assertNotEqual(Representative.find(name), None) name = name[:NAME_MINLEN] self.assertNotEqual(Representative.find(name), None) name = name[:-1] self.assertEqual(Representative.find(name), None)
def test_Representative_find(self): name = u'idontexistinthisdatabase' self.assertEqual(Representative.find(name), None) name = u'Foo Bar' self.assertNotEqual(Representative.find(name), None) name = u'აბულაშვილი ნუგზარი' self.assertNotEqual(Representative.find(name), None) name = u'ნუგზარ აბულაშვილი' self.assertNotEqual(Representative.find(name), None) name = u'აბულაშვილი' self.assertNotEqual(Representative.find(name), None) name = u'ნუგზარი' self.assertNotEqual(Representative.find(name), None) name = u'ნუგზარ' self.assertNotEqual(Representative.find(name), None) name = name[:NAME_MINLEN] self.assertNotEqual(Representative.find(name), None) name = name[:-1] self.assertEqual(Representative.find(name), None)
def render(self, context, instance, placeholder): representatives = Representative.parliament.all() context['representatives'] = Representative.by_lastname_lastname_first( representatives=representatives) context['random'] = RandomRepresentative.get() try: # temporary: #latest = Question.public.order_by('-date')[0] latest = Question.answered.order_by('-date')[0] except IndexError: latest = None context['latest'] = latest # temporary: #return context if not latest: context['most_active'] = None context['least_active'] = None return context try: representative = representatives.order_by('-answered')[0] context['most_active'] = self._add_activity(representative) except IndexError: context['most_active'] = None try: representative = representatives.order_by('answered')[0] context['least_active'] = self._add_activity(representative) except IndexError: context['least_active'] = None return context
def handle (self, *args, **options): """Command handler.""" representatives = {} for r in VotingRecordResult.objects.all(): out = ['Result for %s' % r.record.number.encode('utf-8')] if r.name in representatives: r.representative = representatives[r.name] else: r.representative = Representative.find(r.name) if r.representative: representatives[r.name] = r.representative if r.representative: out.append(' got representative %s' % r.name.encode('utf-8')) if r.vote == u'დიახ': r.css = 'vote-yes' elif r.vote == u'არა': r.css = 'vote-no' elif r.vote == u'არ მიუცია': r.css = 'vote-abstention' else: r.css = 'vote-absent' out.append(' css %s' % r.css) r.save() self.stdout.write(''.join(out) + '\n')
def _add_representatives(self, draftlaw, field): """Add representatives searching for names in given field. @param draftlaw: draftlaw to add to @type draftlaw: draftlaw.Draftlaw @param field: field to search for names in @type field: str """ try: names = self._get_names(getattr(draftlaw, field)) except AttributeError: return base = field.split('_')[0] # remove language try: field_representatives = getattr(draftlaw, base + '_representatives') except AttributeError: return for name in names: representative = Representative.find(name) if representative: self.stdout.write(u'\n %s: %s' % (field, str(representative.name))) field_representatives.add(representative)
def _add_representatives (self, draftlaw, field): """Add representatives searching for names in given field. @param draftlaw: draftlaw to add to @type draftlaw: draftlaw.Draftlaw @param field: field to search for names in @type field: str """ try: names = self._get_names(getattr(draftlaw, field)) except AttributeError: return base = field.split('_')[0] # remove language try: field_representatives = getattr(draftlaw, base + '_representatives') except AttributeError: return for name in names: representative = Representative.find(name) if representative: self.stdout.write(u'\n %s: %s' % ( field, str(representative.name))) field_representatives.add(representative)
def __init__ (self, **kwargs): if not 'initial' in kwargs and 'session' in kwargs: try: s = kwargs.pop('session')['form_question'] except KeyError: pass else: initial = {} for item in ['representative', 'first_name', 'last_name', 'email', 'mobile']: try: initial[item] = s[item] except KeyError: pass if initial: kwargs['initial'] = initial super(QuestionForm, self).__init__(**kwargs) # bug in Django? shows georgian in english site otherwise... self.fields['first_name'].label = _('First Name') self.fields['last_name'].label = _('Last Name') self.fields['mobile'].label = _('Mobile Phone Number') self.fields['question'].label = _('Question') self.fields['representative'].label = _('Representative') representatives = Representative.parliament.all() self.fields['representative'].choices =\ Representative.by_lastname_lastname_first( representatives=representatives, choices=True)
def __init__(self, **kwargs): if not 'initial' in kwargs and 'session' in kwargs: try: s = kwargs.pop('session')['form_question'] except KeyError: pass else: initial = {} for item in [ 'representative', 'first_name', 'last_name', 'email', 'mobile' ]: try: initial[item] = s[item] except KeyError: pass if initial: kwargs['initial'] = initial super(QuestionForm, self).__init__(**kwargs) # bug in Django? shows georgian in english site otherwise... self.fields['first_name'].label = _('First Name') self.fields['last_name'].label = _('Last Name') self.fields['mobile'].label = _('Mobile Phone Number') self.fields['question'].label = _('Question') self.fields['representative'].label = _('Representative') representatives = Representative.parliament.all() self.fields['representative'].choices =\ Representative.by_lastname_lastname_first( representatives=representatives, choices=True)
def _create_representative (self, row): from representative.models import Representative """Create a complete Representative record. @param row: data row @type row: [ str ] @return: a representative @rtype: representative.Representative """ name = glt.firstname_first(row[1]) self.stdout.write('%s | Representative: %s ... ' % (row[0], name)) dob = self._get_isodate(row[9].decode('utf-8')) representative = Representative( date_of_birth=dob, description=row[8].decode('utf-8').strip(), unit=self.unit) representative.save() pname = PersonName(person=representative, name_ka=name, name_en=glt.to_latin(name), main=True) pname.save() people = Representative.objects.filter(slug=representative.slug) if len(people) > 1: if self.force: people.exclude(pk=representative.pk).delete() self.stdout.write('replace existing!\n') self._add_representative_data(row, representative) return representative else: self.stdout.write('keep already existing!\n') slug = representative.slug representative.delete() return Representative.objects.get(slug=slug) else: self.stdout.write('add new!\n') self._add_representative_data(row, representative) return representative