コード例 #1
0
 def handle(self, *args, **kwargs):
     postings = Posting.objects.filter(location_country__isnull=True)
     total_postings = postings.count()
     for i, posting in enumerate(queryset_iterator(postings)):
         if i % 100 == 0:
             print "Processed %s of %s postings." % (i, total_postings)
         try:
             locations = get_locations_from_posting(posting)
             set_locations_to_posting(posting, locations)
             posting.save()
         except JSONDecodeError:
             print "error on json"
コード例 #2
0
            posting,created = Posting.objects.get_or_create(
                                source_id=src['posting']['source_id'],
                                external_id=src['posting']['external_id'],
                                defaults=src['posting'])

            if not created:
                # We have an existing posting -> update it with the
                # newly-supplied values.
                for key,value in src['posting'].items():
                    if key not in ["source_id", "external_id"]:
                        setattr(posting, key, value)
                posting.save()

            try:
                locations = get_locations_from_posting(posting)
                set_locations_to_posting(posting, locations)
                posting.save()
                #logger.error("set locations")
            except:
                logger.error("error on json")


            # Add or update the posting's annotations.

            for annotation_value in src['annotations']:
                annotation = annotations[annotation_value]

                posting_annotation,created = \
                        PostingAnnotation.objects.get_or_create(
                                                posting=posting,
                                                annotation=annotation)