当前位置: 首页>>代码示例>>Python>>正文


Python Person.ranking方法代码示例

本文整理汇总了Python中people.models.Person.ranking方法的典型用法代码示例。如果您正苦于以下问题:Python Person.ranking方法的具体用法?Python Person.ranking怎么用?Python Person.ranking使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在people.models.Person的用法示例。


在下文中一共展示了Person.ranking方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: index

# 需要导入模块: from people.models import Person [as 别名]
# 或者: from people.models.Person import ranking [as 别名]
def index(request):
    today = datetime.date.today()
    people_meal_filter = PersonMeal.objects.filter(meal__date=today)
    try:
        who_wash = people_meal_filter.get(wash=True).person
    except PersonMeal.DoesNotExist:
        who_wash = None
    people_who_ate = [person.person.pk for person in people_meal_filter]
    try:
        meal = Meal.objects.get(date=today)
    except Meal.DoesNotExist:
        meal = Meal.objects.create(date=today)

    ranking = Person.ranking()
    people = Person.objects.all()

    return render(
        request,
        "index.html",
        {
            "people": people,
            "ranking": reversed(ranking),
            "min": meal.get_lowest_avg(),
            "form": AuthenticationForm,
            "today": today.strftime("%d/%m/%Y"),
            "pqc": people_who_ate,
            "who_wash": who_wash,
            "tickets": meal.ticket,
        },
    )
开发者ID:TracyWebTech,项目名称:marmitinha,代码行数:32,代码来源:views.py

示例2: get_lowest_avg

# 需要导入模块: from people.models import Person [as 别名]
# 或者: from people.models.Person import ranking [as 别名]
 def get_lowest_avg(self):
     ranking = Person.ranking()
     wash = None
     for person in ranking:
         if person.personmeal_set.filter(meal=self).exists():
             if person.is_new:
                 return person
             elif person.get_average() != unicode(0.0):
                 if wash: return wash
                 return person
             if not wash:
                 wash = person
     return wash
开发者ID:TracyWebTech,项目名称:marmitinha,代码行数:15,代码来源:models.py

示例3: post

# 需要导入模块: from people.models import Person [as 别名]
# 或者: from people.models.Person import ranking [as 别名]
    def post(self, request, *args, **kwargs):
        check_uncheck = request.POST.get('check_uncheck', None)
        person_pk = request.POST.get('person_pk', None)
        date = request.POST.get('date', None)
        type_of = request.POST.get('type_of', None)
        if not type_of or not date or not person_pk:
            return HttpResponseBadRequest()

        person = get_object_or_404(Person, pk=person_pk)

        date = datetime.datetime.strptime(date, '%d/%m/%Y')
        meal = get_object_or_404(Meal, date=date)

        if check_uncheck == 'uncheck_icon':
            if type_of == 'eat':
                person_meal, created = PersonMeal.objects.get_or_create(
                    meal=meal,
                    person=person,
                    defaults={
                        'wash': False
                    }
                )
                wash = False

            elif type_of == 'wash':
                person_meal, created = PersonMeal.objects.get_or_create(
                    meal=meal,
                    person=person,
                    defaults={
                        'wash': True
                    }
                )

                if not created:
                    person_meal.wash = True
                    person_meal.save()

                wash = True

            else:
                return HttpResponseBadRequest()

        elif check_uncheck == 'check_icon':
            person_meal = PersonMeal.objects.get(meal=meal, person=person)
            if type_of == 'eat':
                wash = False
                person_meal.delete()
            elif type_of == 'wash':
                wash = True
                person_meal.wash = False
                person_meal.save()
            else:
                raise HttpResponseBadRequest()

        else:
            return HttpResponseBadRequest()

        # The personal_data is used to rebuild the ranking with the changes
        # made changing the number of times people eat and washing the dishes
        personal_data = []
        ranking = [instance for instance in Person.ranking()]
        number_of_people = Person.objects.all().count()
        for person in ranking:
            personal_data.append([person.name, person.get_average(), person.weight, person.is_new, person.pk])

        meal_today = get_object_or_404(Meal, date=timezone.now().date())
        try:
            washer = meal_today.get_lowest_avg().name
        except AttributeError:
            washer = None

        number_of_meals = PersonMeal.objects.filter(meal=meal).count()

        return HttpResponse(
            json.dumps({
                'wash': wash,
                'pk': person_meal.person.pk,
                'person_data': list(reversed(personal_data)),
                'washer': washer,
                'number_of_people': number_of_people,
                'number_of_meals': number_of_meals,
            }),
            content_type='application/json'
        )
开发者ID:TracyWebTech,项目名称:marmitinha,代码行数:86,代码来源:views.py


注:本文中的people.models.Person.ranking方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。