Example #1
0
def checkin_user(request):
    if request.method == "POST":
        netid = request.POST['netid']
        rental_list = request.POST.getlist('rental') #list of dvd's checked
        checked_list = []
        for rental_id in rental_list:
            rental = Rental.objects.get(rentalID=rental_id, dateReturned=None, netid=netid)
            rental.dateReturned = datetime.datetime.now()
            rental.save()
            #checkin DVD
            checkin_dvd = rental.dvd
            checkin_dvd.amountLeft += 1
            checkin_dvd.save()
            checked_list.append(checkin_dvd)
            dvd_emails.email_if_available(checkin_dvd)
        return render_to_response('dvd/checkinuser_complete.html', {'checked_list': checked_list, 'netid': netid}, RequestContext(request))
    
    if 'netid' not in request.GET:
        return render_to_response('dvd/checkinuser_1.html', context_instance=RequestContext(request))
    netid = request.GET['netid']
    user_info = gdi(netid)
    if user_info is None:
        return render_to_response('dvd/user_not_found.html', context_instance=RequestContext(request))

    rentalList = Rental.objects.filter(netid=netid, dateReturned=None).order_by('dvd__sortname')
    return render_to_response('dvd/checkinuser_2.html', {'netid': netid, 'rentalList': rentalList}, RequestContext(request))
Example #2
0
def checkin_dvd(request):
    if request.method == "POST":
        checked_list = []
        if "dvd" in request.POST:
            ambiguous_list = []  # When more than one copy is checked out
            dvd_list = request.POST.getlist('dvd')  #list of dvd's checked
            for dvd_id in dvd_list:
                checkin_dvd = DVD.objects.get(pk=dvd_id)
                if checkin_dvd.amountTotal - checkin_dvd.amountLeft > 1:
                    #if there's copies of dvd_id still checked out
                    ambiguous_list.append(
                        (checkin_dvd,
                         Rental.objects.filter(dateReturned=None,
                                               dvd=checkin_dvd)))
                else:
                    #if all of the copies of dvd_id are checked in
                    checked_list.append(checkin_dvd)
                    rental = Rental.objects.get(dateReturned=None,
                                                dvd=checkin_dvd)
                    rental.dateReturned = datetime.datetime.now()
                    rental.save()
                    #checkin DVD
                    checkin_dvd.amountLeft += 1
                    checkin_dvd.save()
                dvd_emails.email_if_available(checkin_dvd)
            if ambiguous_list:
                #This allows the person checking in the dvd to select which copy was checked in
                return render_to_response('dvd/ambiguous.html', {
                    'ambiguous_list': ambiguous_list,
                    'checked_list': checked_list
                }, RequestContext(request))
        else:
            rental_list = [(k[4:], v) for k, v in request.POST.iteritems()
                           if k.startswith('dvd-')]
            for dvd_id, rental_id in rental_list:
                checkin_dvd = DVD.objects.get(pk=dvd_id)
                checked_list.append(checkin_dvd)
                rental = Rental.objects.get(rentalID=rental_id)
                rental.dateReturned = datetime.datetime.now()
                rental.save()
                #checkin DVD
                checkin_dvd.amountLeft += 1
                checkin_dvd.save()
                dvd.emails.email_if_available(checkin_dvd)
        return render_to_response('dvd/checkindvd_complete.html',
                                  {'checked_list': checked_list},
                                  RequestContext(request))

    dvd_list = DVD.objects.all()
    excludes = []
    for dvd in dvd_list:
        if dvd.amountLeft == dvd.amountTotal:
            excludes.append(dvd.pk)
    dvd_list = dvd_list.exclude(pk__in=excludes).order_by('sortname')
    return render_to_response('dvd/checkindvd_1.html', {'dvd_list': dvd_list},
                              RequestContext(request))
Example #3
0
def checkin_dvd(request):
    if request.method == "POST":
        checked_list = []
        if "dvd" in request.POST:
            ambiguous_list = [] # When more than one copy is checked out
            dvd_list = request.POST.getlist('dvd') #list of dvd's checked
            for dvd_id in dvd_list:
                checkin_dvd = DVD.objects.get(pk=dvd_id)
                if checkin_dvd.amountTotal - checkin_dvd.amountLeft > 1:
                    #if there's copies of dvd_id still checked out
                    ambiguous_list.append((checkin_dvd, Rental.objects.filter(dateReturned=None, dvd=checkin_dvd)))
                else:
                    #if all of the copies of dvd_id are checked in
                    checked_list.append(checkin_dvd)
                    rental = Rental.objects.get(dateReturned=None, dvd=checkin_dvd)
                    rental.dateReturned = datetime.datetime.now()
                    rental.save()
                    #checkin DVD
                    checkin_dvd.amountLeft += 1
                    checkin_dvd.save()
                dvd_emails.email_if_available(checkin_dvd)
            if ambiguous_list:
                #This allows the person checking in the dvd to select which copy was checked in
                return render_to_response('dvd/ambiguous.html', {'ambiguous_list': ambiguous_list, 'checked_list': checked_list}, RequestContext(request))
        else:
            rental_list = [(k[4:],v) for k,v in request.POST.iteritems() if k.startswith('dvd-')]
            for dvd_id, rental_id in rental_list:
                checkin_dvd = DVD.objects.get(pk=dvd_id)
                checked_list.append(checkin_dvd)
                rental = Rental.objects.get(rentalID=rental_id)
                rental.dateReturned = datetime.datetime.now()
                rental.save()
                #checkin DVD
                checkin_dvd.amountLeft += 1
                checkin_dvd.save()
                dvd.emails.email_if_available(checkin_dvd)
        return render_to_response('dvd/checkindvd_complete.html', {'checked_list': checked_list}, RequestContext(request))

    dvd_list = DVD.objects.all()
    excludes = []
    for dvd in dvd_list:
        if dvd.amountLeft == dvd.amountTotal:
            excludes.append(dvd.pk)
    dvd_list = dvd_list.exclude(pk__in=excludes).order_by('sortname')
    return render_to_response('dvd/checkindvd_1.html', {'dvd_list': dvd_list}, RequestContext(request))
Example #4
0
def checkin_user(request):
    if request.method == "POST":
        netid = request.POST['netid']
        rental_list = request.POST.getlist('rental')  #list of dvd's checked
        checked_list = []
        for rental_id in rental_list:
            rental = Rental.objects.get(rentalID=rental_id,
                                        dateReturned=None,
                                        netid=netid)
            rental.dateReturned = datetime.datetime.now()
            rental.save()
            #checkin DVD
            checkin_dvd = rental.dvd
            checkin_dvd.amountLeft += 1
            checkin_dvd.save()
            checked_list.append(checkin_dvd)
            dvd_emails.email_if_available(checkin_dvd)
        return render_to_response('dvd/checkinuser_complete.html', {
            'checked_list': checked_list,
            'netid': netid
        }, RequestContext(request))

    if 'netid' not in request.GET:
        return render_to_response('dvd/checkinuser_1.html',
                                  context_instance=RequestContext(request))
    netid = request.GET['netid']
    user_info = gdi(netid)
    if user_info is None:
        return render_to_response('dvd/user_not_found.html',
                                  context_instance=RequestContext(request))

    rentalList = Rental.objects.filter(
        netid=netid, dateReturned=None).order_by('dvd__sortname')
    return render_to_response('dvd/checkinuser_2.html', {
        'netid': netid,
        'rentalList': rentalList
    }, RequestContext(request))