Пример #1
0
def index(request):
    if request.method == 'POST':
        redemptions = {}
        for key, value in request.POST.items():
            if key.startswith('points-'):
                event_id = int(key.rpartition('-')[2])
                redemptions[event_id] = int(value)

        try:
            save_redemptions(request, redemptions)
            messages.success(request, _("You successfully redeemed your points."))
        except (NoPointsSelected, NotEnoughPoints) as error:
            messages.warning(request, error)

    total_points_available = reward_points_of_user(request.user)
    reward_point_grantings = RewardPointGranting.objects.filter(user_profile=request.user)
    reward_point_redemptions = RewardPointRedemption.objects.filter(user_profile=request.user)
    events = RewardPointRedemptionEvent.objects.filter(redeem_end_date__gte=datetime.now())
    events = sorted(events, key=lambda event: event.date)

    reward_point_actions = []
    for granting in reward_point_grantings:
        reward_point_actions.append((granting.granting_time, _('Reward for') + ' ' + granting.semester.name, granting.value, ''))
    for redemption in reward_point_redemptions:
        reward_point_actions.append((redemption.redemption_time, redemption.event.name, '', redemption.value))

    reward_point_actions.sort(key=lambda action: action[0], reverse=True)

    template_data = dict(
            reward_point_actions=reward_point_actions,
            total_points_available=total_points_available,
            events=events,
            point_selection=[x for x in range(0, total_points_available + 1)])
    return render(request, "rewards_index.html", template_data)
Пример #2
0
def index(request):
    if request.method == "POST":
        redemptions = {}
        try:
            for key, value in request.POST.items():
                if key.startswith("points-"):
                    event_id = int(key.rpartition("-")[2])
                    redemptions[event_id] = int(value)
        except ValueError as e:
            raise BadRequest from e

        try:
            save_redemptions(request, redemptions)
            messages.success(request,
                             _("You successfully redeemed your points."))
        except (NoPointsSelected, NotEnoughPoints,
                RedemptionEventExpired) as error:
            messages.warning(request, error)

    total_points_available = reward_points_of_user(request.user)
    reward_point_grantings = RewardPointGranting.objects.filter(
        user_profile=request.user)
    reward_point_redemptions = RewardPointRedemption.objects.filter(
        user_profile=request.user)
    events = RewardPointRedemptionEvent.objects.filter(
        redeem_end_date__gte=datetime.now()).order_by("date")

    reward_point_actions = []
    for granting in reward_point_grantings:
        reward_point_actions.append(
            (granting.granting_time,
             _("Reward for") + " " + granting.semester.name, granting.value,
             ""))
    for redemption in reward_point_redemptions:
        reward_point_actions.append(
            (redemption.redemption_time, redemption.event.name, "",
             redemption.value))

    reward_point_actions.sort(key=lambda action: action[0], reverse=True)

    template_data = dict(
        reward_point_actions=reward_point_actions,
        total_points_available=total_points_available,
        events=events,
        point_selection=range(0, total_points_available + 1),
    )
    return render(request, "rewards_index.html", template_data)
Пример #3
0
def index(request):
    if request.method == 'POST':
        redemptions = {}
        for key, value in request.POST.items():
            if (key.startswith('points-')):
                event_id = int(key.rpartition('-')[2])
                redemptions[event_id] = int(value)

        try:
            save_redemptions(request, redemptions)
            messages.success(request,
                             _("You successfully redeemed your points."))
        except (NoPointsSelected, NotEnoughPoints) as error:
            messages.warning(request, error)

    total_points_available = reward_points_of_user(request.user)
    reward_point_grantings = RewardPointGranting.objects.filter(
        user_profile=request.user)
    reward_point_redemptions = RewardPointRedemption.objects.filter(
        user_profile=request.user)
    events = RewardPointRedemptionEvent.objects.filter(
        redeem_end_date__gte=datetime.now())
    events = sorted(events, key=lambda event: event.date)

    reward_point_actions = []
    for granting in reward_point_grantings:
        reward_point_actions.append(
            (granting.granting_time,
             _('Reward for') + ' ' + granting.semester.name, granting.value,
             ''))
    for redemption in reward_point_redemptions:
        reward_point_actions.append(
            (redemption.redemption_time, redemption.event.name, '',
             redemption.value))

    reward_point_actions.sort(key=lambda action: action[0], reverse=True)

    template_data = dict(
        reward_point_actions=reward_point_actions,
        total_points_available=total_points_available,
        events=events,
        point_selection=[x for x in range(0, total_points_available + 1)])
    return render(request, "rewards_index.html", template_data)
Пример #4
0
def index(request):
    if request.method == 'POST':
        redemptions = {}
        for key, value in request.POST.iteritems():
            if(key.startswith('points-')):
                event_id = int(key.rpartition('-')[2])
                redemptions[event_id] = int(value)
     
        if save_redemptions(request, redemptions):
            messages.success(request, _("You successfully redeemed your points."))
        else:
            messages.warning(request, _("You don't have enough reward points."))            

    total_points_available = reward_points_of_user(request.user.userprofile)
    reward_point_grantings = RewardPointGranting.objects.filter(user_profile=request.user.userprofile)
    reward_point_redemptions = RewardPointRedemption.objects.filter(user_profile=request.user.userprofile)
    events = RewardPointRedemptionEvent.objects.filter(redeem_end_date__gte=datetime.now())
    events = sorted(events, key=lambda event: event.date)

    reward_point_actions=[]
    for granting in reward_point_grantings:
        reward_point_actions.append((granting.granting_time, _('Reward for') + ' ' + granting.semester.name, granting.value, ''))
    for redemption in reward_point_redemptions:
        reward_point_actions.append((redemption.redemption_time, redemption.event.name, '', redemption.value))

    reward_point_actions.sort(key=lambda action: action[0], reverse=True)

    return render_to_response(
        "rewards_index.html",
        dict(
            reward_point_actions=reward_point_actions,
            total_points_available=total_points_available,
            events=events,
            point_selection=[x for x in range(0,total_points_available+1)]
        ),
        context_instance=RequestContext(request))