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
예제 #2
0
    def _find_firstname_first (cls, name, lang):
        """Find a representative with given name firstname first.

        @param name: name of the representative
        @type name: str
        @param lang: user language
        @type lang: str
        @return: representative matching the name
        @rtype: representative.Representative
        """
        if lang == 'ka':
            firstname_first = glt.firstname_first(name)
        else:
            firstname_first = name.split()[0]

        representative = cls.objects.filter(
            Q(names__name_ka__icontains=firstname_first) |\
            Q(names__name_en__icontains=firstname_first) |\
            Q(names__name__icontains=firstname_first)
        )

        try:
            return representative[0]
        except IndexError:
            return None
예제 #3
0
    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