Example #1
0
def profile(request):
    user_reservation = request.user

    reserv = user_reservation.reserved_restaurants.all()

    for res in reserv:
        no_of_total_visits = Reservation.objects.filter(
            user=user_reservation, restaurant=res).count()
        visits_in_last_6 = Reservation.objects.filter(
            user=user_reservation,
            restaurant=res).filter(date__gte=datetime.now() -
                                   timedelta(180)).count()
        if no_of_total_visits > 7 or visits_in_last_6 > 2:
            res.fav = True
        else:
            res.fav = False
    # for user_reservation in reserv.user:
    #     no_of_total_visits = Reservation.objects.filter(user = user_reservation, restaurant = restaurants).count()
    #     visits_in_last_6 = Reservation.objects.filter(user = user_reservation, restaurant = restaurants).filter(date__gte= datetime.now() - timedelta(180)).count()
    #     if no_of_total_visits > 7 or visits_in_last_6 > 2:
    #         user_reservation.vip_user = True
    #     else:
    #         user_reservation.vip_user = False

    context = {'title': 'Profile', 'reserv': set(reserv)}
    if not Profile.exists_for_user(request.user):
        form = ProfileForm()
        context['form'] = form
    return render(request, 'profile.html', context)
Example #2
0
def profile(request):
    context = {'title': 'Profile'}
    if not Profile.exists_for_user(request.user):
        form = ProfileForm()
        context['form'] = form
    return render(request, 'profile.html', context)