Exemplo n.º 1
0
    def compress(self, data_list):
        if data_list != 0:
            curr_id = data_list[0]
            name = data_list[1]
            zipcode = data_list[2]
            city = data_list[3]
            state = data_list[4]

            if curr_id:
                # get the first object with the same id (should be exactly 1)
                curr_place = Place.objects.get(pk=curr_id)
                curr_place.name = name
                curr_place.zipcode = zipcode
                curr_place.city = city
                curr_place.province = state
            else:
                curr_place = Place(
                    name=name,zipcode=zipcode,
                    city=city,province=state
                )

            curr_place.save()

            return curr_place
        else: 
            return ''
Exemplo n.º 2
0
    def compress(self, data_list):
        if data_list != 0:
            curr_id = data_list[0]
            name = data_list[1]
            zipcode = data_list[2]
            city = data_list[3]
            state = data_list[4]

            if curr_id:
                # get the first object with the same id (should be exactly 1)
                curr_place = Place.objects.get(pk=curr_id)
                curr_place.name = name
                curr_place.zipcode = zipcode
                curr_place.city = city
                curr_place.province = state
            else:
                curr_place = Place(name=name,
                                   zipcode=zipcode,
                                   city=city,
                                   province=state)

            curr_place.save()

            return curr_place
        else:
            return ''
Exemplo n.º 3
0
    def get_appointment_instance(self, name, klass):
        """Return a delivery or withdrawal instance.

        If instance already exist in db ==> return it,
        return a non-saved instance otherwise.

        It would be saved in save()
        """

        ddt = self.cleaned_data['%s_datetime' % name]
        if self.cleaned_data.get('%s_city' % name):
            dc =self.cleaned_data['%s_city' % name]
            dp = self.cleaned_data['%s_addr_or_place' % name]

            try:
                p = Place.objects.get(city=dc, name__icontains=dp)
            except Place.DoesNotExist:
                try:
                    p = Place.objects.get(city=dc, address__icontains=dp)
                except Place.DoesNotExist:
                    p = Place(city=dc, name=dp)
                    p.save()
        else:
            if self.cleaned_data.get('pact'):
                pact = self.cleaned_data['pact']
                if not pact:
                    return None
                p = getattr(pact.gas.config, "%s_place" % name)
            else:
                return None

        try:
            # try to get already existent appointment
            appointment = klass.objects.get(date=ddt, place=p)
        except klass.DoesNotExist as e:
            appointment = klass(date=ddt, place=p)
        except klass.MultipleObjectsReturned as e:

            #FIXME TOVERIFY: get() returned more than one Delivery -- it returned 2!
            log.error(u"%s.get_appointment_instance(%s, %s): returned more than one. Lookup parameters were date=%s, place=%s" % (
                self.__class__.__name__,
                name, klass, ddt, p
            ))
            # WORKAROUND
            appointment = klass.objects.filter(date=ddt, place=p)[0]
            # WAS. SHOULD BE: raise

        return appointment
Exemplo n.º 4
0
    def get_appointment_instance(self, name, klass):
        """Return a delivery or withdrawal instance.

        If instance already exist in db ==> return it,
        return a non-saved instance otherwise.

        It would be saved in save()
        """

        ddt = self.cleaned_data['%s_datetime' % name]
        if self.cleaned_data.get('%s_city' % name):
            dc = self.cleaned_data['%s_city' % name]
            dp = self.cleaned_data['%s_addr_or_place' % name]

            try:
                p = Place.objects.get(city=dc, name__icontains=dp)
            except Place.DoesNotExist:
                try:
                    p = Place.objects.get(city=dc, address__icontains=dp)
                except Place.DoesNotExist:
                    p = Place(city=dc, name=dp)
                    p.save()
        else:
            if self.cleaned_data.get('pact'):
                pact = self.cleaned_data['pact']
                if not pact:
                    return None
                p = getattr(pact.gas.config, "%s_place" % name)
            else:
                return None

        try:
            # try to get already existent appointment
            appointment = klass.objects.get(date=ddt, place=p)
        except klass.DoesNotExist as e:
            appointment = klass(date=ddt, place=p)
        except klass.MultipleObjectsReturned as e:

            #FIXME TOVERIFY: get() returned more than one Delivery -- it returned 2!
            log.error(
                u"%s.get_appointment_instance(%s, %s): returned more than one. Lookup parameters were date=%s, place=%s"
                % (self.__class__.__name__, name, klass, ddt, p))
            # WORKAROUND
            appointment = klass.objects.filter(date=ddt, place=p)[0]
            # WAS. SHOULD BE: raise

        return appointment
Exemplo n.º 5
0
    def _update_place(self, pers, d):
        """Process place already bound to person."""
        place = pers.address
        ans = "N"
        if place:
            ans = raw_input("Found address %s for person %s. Overwrite with new info %s [y/N]?" % \
                (place, pers, "city=%s address=%s name=''" % (d['city'], d.get('address','')))
            )
        else:
            place = Place()
            ans = "Y"

        if ans.upper() == "Y":
            place.city = d['city']
            place.address = d.get('address', '')
            place.name = ''

        place.save()
        return place
Exemplo n.º 6
0
    def _update_place(self, pers, d):
        """Process place already bound to person."""
        place = pers.address
        ans = "N"
        if place:
            ans = raw_input("Found address %s for person %s. Overwrite with new info %s [y/N]?" % \
                (place, pers, "city=%s address=%s name=''" % (d['city'], d.get('address','')))
            )
        else:
            place = Place()
            ans = "Y"

        if ans.upper() == "Y":
            place.city = d['city']
            place.address = d.get('address','')
            place.name = ''

        place.save()
        return place