コード例 #1
0
ファイル: admin.py プロジェクト: aspc/mainsite
 def raffle_view(self, request):
     from aspc.housing.forms import RaffleForm
     context = {}
     if request.GET:
         form = RaffleForm(request.GET)
         if form.is_valid():
             start = form.cleaned_data["start_date"]
             end = form.cleaned_data["end_date"]
             num = form.cleaned_data["num_winners"]
             reviews = list(Review.objects.filter(create_ts__range=[start, end])) + \
                 list(CourseReview.objects.filter(created_date__range=[start, end]))
             winner_reviews = random.sample(reviews, num)
             context.update({'winner_reviews': winner_reviews})
     else:
         form = RaffleForm()
     context.update({'form': form})
     return render(request, 'housing/raffle.html', context)
コード例 #2
0
ファイル: admin.py プロジェクト: thebradbain/mainsite
 def raffle_view(self, request):
     from aspc.housing.forms import RaffleForm
     context = {}
     if request.GET:
         form = RaffleForm(request.GET)
         if form.is_valid():
             start = form.cleaned_data["start_date"]
             end = form.cleaned_data["end_date"]
             num = form.cleaned_data["num_winners"]
             reviews = list(Review.objects.filter(create_ts__range=[start, end])) + \
                 list(CourseReview.objects.filter(created_date__range=[start, end]))
             winner_reviews = random.sample(reviews, num)
             context.update({'winner_reviews': winner_reviews})
     else:
         form = RaffleForm()
     context.update({'form': form})
     return render(request, 'housing/raffle.html', context)
コード例 #3
0
ファイル: admin.py プロジェクト: 0ffkilter/mainsite
 def raffle_view(self, request):
     from aspc.housing.forms import RaffleForm
     context = {}
     if request.GET:
         form = RaffleForm(request.GET)
         if form.is_valid():
             start = form.cleaned_data["start_date"]
             end = form.cleaned_data["end_date"]
             num = form.cleaned_data["num_winners"]
             winner_ids = Review.objects\
                 .filter(create_ts__range=[start, end])\
                 .order_by('?')[:num]\
                 .values_list('author', flat=True)
             winners = User.objects.filter(pk__in=winner_ids)
             context.update({'winners': winners})
     else:
         form = RaffleForm()
     context.update({'form': form})
     return render(request, 'housing/raffle.html', context)
コード例 #4
0
ファイル: admin.py プロジェクト: KentShikama/mainsite
    def raffle_view(self, request):
        from aspc.housing.forms import RaffleForm

        context = {}
        if request.GET:
            form = RaffleForm(request.GET)
            if form.is_valid():
                start = form.cleaned_data["start_date"]
                end = form.cleaned_data["end_date"]
                num = form.cleaned_data["num_winners"]
                winner_ids = (
                    Review.objects.filter(create_ts__range=[start, end])
                    .order_by("?")[:num]
                    .values_list("author", flat=True)
                )
                winners = User.objects.filter(pk__in=winner_ids)
                context.update({"winners": winners})
        else:
            form = RaffleForm()
        context.update({"form": form})
        return render(request, "housing/raffle.html", context)