示例#1
0
 def list_juice():
     query_set = Person.objects \
         .annotate(source_num=Count("sources")) \
         .all() \
         .order_by("-source_num")
     for person in query_set[:100]:
         output_person(person)
示例#2
0
 def juice():
     query_set = Person.objects \
         .annotate(source_num=Count("sources")) \
         .all() \
         .order_by("-source_num")
     for person in query_set[:100]:
         output_person(person)
示例#3
0
 def find(first_name=None, last_name=None, full_name=None, initials=None, prefix=None, birth_date=None,
          batch_size=0, page_number=1, **kwargs):
     # Making the extra kwargs work with the HStore field
     filters = {"props__{}".format(key): value for key, value in six.iteritems(kwargs) if value is not None}
     # Keeping IDE auto complete for the method by writing out the definition.
     # Putting values back in a dictionary (like kwargs) to iterate over the items.
     fixed_arguments = {
         "first_name": first_name,
         "last_name": last_name,
         "full_name": full_name,
         "initials": initials,
         "prefix": prefix,
         "birth_date": birth_date
     }
     filters.update({key: value for key, value in six.iteritems(fixed_arguments) if value is not None})
     query_set = PersonSource.objects.filter(**filters)
     if batch_size:
         pages = Paginator(query_set, batch_size)
         page = pages.page(page_number)
         persons = page.object_list
     else:
         persons = query_set
     for person in persons:
         output_person(person)
     print("Applied filters:", filters)
     print("Total matches:", query_set.count())
     if batch_size:
         print("Batch size:", batch_size)
         print("Page:", page_number)
示例#4
0
 def players_with_city():
     query_set = SoccerSource.objects \
         .annotate(source_num=Count("master__sources")) \
         .filter(source_num__gte=2) \
         .order_by("-source_num")
     for player in query_set:
         if player.master.sources.filter(props__has_key="city").exists():
             output_person(player.master)
示例#5
0
 def players_with_city():
     query_set = SoccerSource.objects \
         .annotate(source_num=Count("master__sources")) \
         .filter(source_num__gte=2) \
         .order_by("-source_num")
     for player in query_set:
         if player.master.sources.filter(props__has_key="city").exists():
             output_person(player.master)
示例#6
0
 def alumni_with_city():
     print(SchoolBankSource.objects.filter(master__isnull=False).count())
     query_set = SchoolBankSource.objects \
         .annotate(source_num=Count("master__sources")) \
         .filter(source_num__gte=2) \
         .order_by("-source_num")
     for alumni in query_set:
         if alumni.master.sources.filter(props__has_key="city").exists():
             output_person(alumni.master)
示例#7
0
 def find(first_name=None,
          last_name=None,
          full_name=None,
          initials=None,
          prefix=None,
          birth_date=None,
          batch_size=0,
          page_number=1,
          **kwargs):
     # Making the extra kwargs work with the HStore field
     filters = {
         "props__{}".format(key): value
         for key, value in six.iteritems(kwargs) if value is not None
     }
     # Keeping IDE auto complete for the method by writing out the definition.
     # Putting values back in a dictionary (like kwargs) to iterate over the items.
     fixed_arguments = {
         "first_name": first_name,
         "last_name": last_name,
         "full_name": full_name,
         "initials": initials,
         "prefix": prefix,
         "birth_date": birth_date
     }
     filters.update({
         key: value
         for key, value in six.iteritems(fixed_arguments)
         if value is not None
     })
     query_set = PersonSource.objects.filter(**filters)
     if batch_size:
         pages = Paginator(query_set, batch_size)
         page = pages.page(page_number)
         persons = page.object_list
     else:
         persons = query_set
     for person in persons:
         output_person(person)
     print("Applied filters:", filters)
     print("Total matches:", query_set.count())
     if batch_size:
         print("Batch size:", batch_size)
         print("Page:", page_number)