Esempio n. 1
0
def checkout_2(request):
    if request.method == 'POST':
        netid = request.POST['netid']
        user_info = gdi(netid)
        if user_info is None:
            return render_to_response('dvd/user_not_found.html', context_instance=RequestContext(request))

        due = request.POST['due']
        checked_pks = request.POST.getlist('dvd')
        now = datetime.datetime.now()
        checked_list = []
        for pk in checked_pks:
            dvd = DVD.objects.get(dvd_id=int(pk))
            dvd.amountLeft -= 1
            dvd.save()
            rental = Rental(netid=netid, dvd=dvd, dateRented=now, dateDue=(now + datetime.timedelta(days=int(due))), dateReturned=None)
            rental.save()
            checked_list.append(dvd)
        return render_to_response('dvd/checkout_complete.html', {'netid': netid, 'checked_list': checked_list}, RequestContext(request))

    if 'netid' not in request.GET:
        return HttpResponseRedirect('/dvd/checkout/1/')
    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))
        
    warningList = Rental.objects.filter(netid=netid).filter(dateReturned=None).order_by('dateDue')
    DVD_list = DVD.objects.all().exclude(amountLeft=0).order_by('name')
    return render_to_response('dvd/checkout_2.html', {'netid': netid, 'DVD_list': DVD_list, 'warningList': warningList}, RequestContext(request))
Esempio n. 2
0
def make_new_user(netid):
	""" Add a new user account to the system """
	user_info = gdi(netid)
	email = user_info.get('mail', '*****@*****.**' % (netid))
	
	if 'pustatus' in user_info:
		if user_info['pustatus'] == 'undergraduate' and 'puclassyear' in user_info:
			pustatus = 'u'+user_info['puclassyear'][2:]
		elif user_info['pustatus'] == 'graduate' and 'puacademiclevel' in user_info:
			pustatus = 'g'+user_info['puacademiclevel']
		else:
			pustatus = user_info['pustatus'][:3]
	else:
		pustatus = 'non'				
	newbie = CalUser(
				user_netid = netid,
				user_firstname = user_info.get('givenName', ''),
				user_lastname = user_info.get('sn', ''),
				user_email = email,
				user_pustatus = pustatus,
				user_dept = user_info.get('ou', ''),
				user_last_login = datetime.now(),
				user_privacy_enabled=False, 
				user_reminders_requested=True,
				user_notify_invitation=True)
	newbie.save()
	return newbie
Esempio n. 3
0
def student(request, error_message=None):
    user_name = request.user
    if not request.user.is_authenticated():
        return HttpResponseRedirect(reverse('login'))  # Send to CAS
    if Student.objects.filter(netID=user_name).count() != 1:
        info = gdi(user_name)  # get personal info from LDAP
        s = Student(
            netID=user_name,
            first_name=info.get('givenName'),
            last_name=info.get('sn'))  # need to include other fields, too!
        s.save()
        # Add the special event
        c = Course.objects.get(courseID='S1499')
        Registration(course=c, student=s).save()
    student = Student.objects.get(netID=user_name)
    identity = (student.netID, student.first_name, student.last_name)
    my_registrations = student.registration_set.all()
    my_courses = student.course_set.all()
    table = CourseTable(my_courses)
    RequestConfig(request).configure(table)
    # Only active courses
    active_courses = Course.objects.filter(cancelled=False)
    c_ids = [o.courseID for o in active_courses
             if not o.is_full()]  # can remove
    # Only non-full active courses
    avail_courses = active_courses.filter(courseID__in=c_ids)  # can remove
    context = {
        'identity': identity,
        'my_registrations': my_registrations,
        'active_courses': avail_courses,  # or active_courses
        'error_message': error_message,
        'table': table,
    }
    return render(request, 'wintersession/student.html', context)
Esempio n. 4
0
def student(request, error_message=None):
    user_name = request.user
    if not request.user.is_authenticated():
        return HttpResponseRedirect(reverse('login')) # Send to CAS
    if Student.objects.filter(netID=user_name).count() != 1:
        info = gdi(user_name) # get personal info from LDAP
        s = Student(netID=user_name, first_name=info.get('givenName'),
                    last_name=info.get('sn')) # need to include other fields, too!
        s.save()
        # Add the special event
        c = Course.objects.get(courseID='S1499')
        Registration(course=c, student=s).save()
    student = Student.objects.get(netID=user_name)
    identity = (student.netID, student.first_name, student.last_name)
    my_registrations = student.registration_set.all()
    my_courses = student.course_set.all()
    table = CourseTable(my_courses)
    RequestConfig(request).configure(table)
    # Only active courses
    active_courses = Course.objects.filter(cancelled=False)
    c_ids = [o.courseID for o in active_courses if not o.is_full()] # can remove
    # Only non-full active courses
    avail_courses = active_courses.filter(courseID__in=c_ids)       # can remove
    context = {
        'identity' : identity,
        'my_registrations' : my_registrations,
        'active_courses' : avail_courses, # or active_courses
        'error_message' : error_message,
        'table' : table,
    }
    return render(request, 'wintersession/student.html', context)
Esempio n. 5
0
def make_new_user(netid):
	""" Add a new user account to the system """
	user_info = gdi(netid)
	email = user_info.get('mail', '*****@*****.**' % (netid))
	
	if 'pustatus' in user_info:
		if user_info['pustatus'] == 'undergraduate' and 'puclassyear' in user_info:
			pustatus = 'u'+user_info['puclassyear'][2:]
		elif user_info['pustatus'] == 'graduate' and 'puacademiclevel' in user_info:
			pustatus = 'g'+user_info['puacademiclevel']
		else:
			pustatus = user_info['pustatus'][:3]
	else:
		pustatus = 'non'				
	newbie = CalUser(
				user_netid = netid,
				user_firstname = user_info.get('givenName', ''),
				user_lastname = user_info.get('sn', ''),
				user_email = email,
				user_pustatus = pustatus,
				user_dept = user_info.get('ou', ''),
				user_last_login = datetime.now(),
				user_privacy_enabled=False, 
				user_reminders_requested=True,
				user_notify_invitation=True)
	newbie.save()
	return newbie
Esempio n. 6
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))
Esempio n. 7
0
def checkout_2(request):
    if request.method == 'POST':
        netid = request.POST['netid']
        user_info = gdi(netid)
        if user_info is None:
            return render_to_response('dvd/user_not_found.html',
                                      context_instance=RequestContext(request))

        due = request.POST['due']
        checked_pks = request.POST.getlist('dvd')
        now = datetime.datetime.now()
        checked_list = []
        for pk in checked_pks:
            dvd = DVD.objects.get(dvd_id=int(pk))
            dvd.amountLeft -= 1
            dvd.save()
            rental = Rental(netid=netid,
                            dvd=dvd,
                            dateRented=now,
                            dateDue=(now + datetime.timedelta(days=int(due))),
                            dateReturned=None)
            rental.save()
            checked_list.append(dvd)
        return render_to_response('dvd/checkout_complete.html', {
            'netid': netid,
            'checked_list': checked_list
        }, RequestContext(request))

    if 'netid' not in request.GET:
        return HttpResponseRedirect('/dvd/checkout/1/')
    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))

    warningList = Rental.objects.filter(netid=netid).filter(
        dateReturned=None).order_by('dateDue')
    DVD_list = DVD.objects.all().exclude(amountLeft=0).order_by('name')
    return render_to_response('dvd/checkout_2.html', {
        'netid': netid,
        'DVD_list': DVD_list,
        'warningList': warningList
    }, RequestContext(request))
Esempio n. 8
0
def _create_student(user_name):
    try:
        info = gdi(user_name) # get personal info from LDAP
    except ldap.NO_SUCH_OBJECT:
        first_name = ''
        last_name = ''
    else:
        first_name = info.get('givenName')
        last_name = info.get('sn')

    s = Student.objects.create(netID=user_name,
            first_name=first_name, last_name=last_name)
    return s
Esempio n. 9
0
def check_undergraduate(username):
    # Check if user can be here
    try:
        user = SocUser.objects.get(netid=username)
    except SocUser.DoesNotExist:
        info = gdi(username)
        user = SocUser(netid=username, firstname=info.get('givenName'), lastname=info.get('sn'), pustatus=info.get('pustatus'))
        if info.get('puclassyear'):
            user.puclassyear = int(info.get('puclassyear'))
        user.save()
        
    if user.pustatus == 'undergraduate' and 2011 < user.puclassyear:
        return user
    return None
Esempio n. 10
0
def login_check(request):
    """Checks if a user is currently logged in.

    If the user just logged in, sets up his/her session
    data.  This function should be called wherever an html
    request is sent to the server."""

    # Check login status
    try:
        if request.session['login']:
            return True
        else:
            if request.user.is_authenticated():  # User just logged in
                curr_user = request.user
            else:  # No user logged in
                return False
    except:  # Session not set up
        request.session['login'] = False
        request.session['user'] = None
        request.session['alpha'] = alpha
        request.session['categories'] = Category.objects.all().order_by(
            'h_name')
        return False

    # Look up user in DB
    try:
        stu = Student.objects.get(netid=curr_user.username)
    except:  # User's first time; do ldap lookup and store in DB
        try:
            stu_info = gdi(curr_user.username)
            stu = Student(netid=curr_user.username,
                          first_name=stu_info['givenName'],
                          last_name=stu_info['sn'],
                          email=curr_user.username + '@princeton.edu',
                          year=int(stu_info['puclassyear']))
        except:
            stu = Student(netid=curr_user.username,
                          email=curr_user.username + '@princeton.edu',
                          first_name='Unknown',
                          last_name='Unknown')
        stu.save()

    # Set up session
    request.session['login'] = True
    request.session['user'] = stu
    request.session['alpha'] = alpha
    request.session['categories'] = Category.objects.all().order_by('h_name')
    return True
Esempio n. 11
0
def addadmin(request):
    g = permissions.get_dvdadmin_group()
    if (request.method == 'POST'):
        netid = request.POST['netid']
        user_info = gdi(netid)
        if user_info is None:
            return render_to_response('dvd/user_not_found.html')

        try:
            user = User.objects.get(username=netid)
        except User.DoesNotExist:
            user = User(username=netid, password="") #Password doesn't matter with CAS!
        user.groups.add(g)
        user.save()
    dvdadmins  = [u.username for u in g.user_set.all()] + [u.username for u in User.objects.filter(is_superuser=True)]
    return render_to_response('dvd/addadmin.html', {'dvdadmins': dvdadmins}, context_instance=RequestContext(request))
Esempio n. 12
0
def check_undergraduate(username):
    # Check if user can be here
    try:
        user = SocUser.objects.get(netid=username)
    except SocUser.DoesNotExist:
        info = gdi(username)
        user = SocUser(netid=username,
                       firstname=info.get('givenName'),
                       lastname=info.get('sn'),
                       pustatus=info.get('pustatus'))
        if info.get('puclassyear'):
            user.puclassyear = int(info.get('puclassyear'))
        user.save()

    if user.pustatus == 'undergraduate' and 2011 < user.puclassyear:
        return user
    return None
Esempio n. 13
0
def register(request):
    user_name = request.user
    if not request.user.is_authenticated():
        return HttpResponseRedirect(reverse('login')) # Send to CAS
    if Student.objects.filter(netID=user_name).count() != 1:
        info = gdi(user_name) # get personal info from LDAP
        s = Student(netID=user_name, first_name=info.get('givenName'),
                    last_name=info.get('sn')) # need to include other fields, too!
        s.save()
        # Add the special event
        c = Course.objects.get(courseID='S1499')
        Registration(course=c, student=s).save()
    context = {
        'REGSTART': REGSTART,
        'REGEND': REGEND
    }
    return render(request, 'wintersession/register.html', context)
Esempio n. 14
0
def addadmin(request):
    g = permissions.get_dvdadmin_group()
    if (request.method == 'POST'):
        netid = request.POST['netid']
        user_info = gdi(netid)
        if user_info is None:
            return render_to_response('dvd/user_not_found.html')

        try:
            user = User.objects.get(username=netid)
        except User.DoesNotExist:
            user = User(username=netid,
                        password="")  #Password doesn't matter with CAS!
        user.groups.add(g)
        user.save()
    dvdadmins = [u.username for u in g.user_set.all()] + [
        u.username for u in User.objects.filter(is_superuser=True)
    ]
    return render_to_response('dvd/addadmin.html', {'dvdadmins': dvdadmins},
                              context_instance=RequestContext(request))
Esempio n. 15
0
def get_user(username):
    # Check if user can be here
    try:
        user = User.objects.get(netid=username)
    except:
        info = gdi(username)
        user = User(netid=username, firstname=info.get('givenName'),
                    lastname=info.get('sn'), pustatus=info.get('pustatus'))
        if info.get('puclassyear'):
            user.puclassyear = int(info.get('puclassyear'))
        if user.pustatus == 'undergraduate':
            user.save()
            # Create queues for each draw
            for draw in Draw.objects.all():
                queue = Queue(draw=draw)
                queue.save()
                user.queues.add(queue)
        else:
            return None
    return user
Esempio n. 16
0
def login_check(request):
    """Checks if a user is currently logged in.

    If the user just logged in, sets up his/her session
    data.  This function should be called wherever an html
    request is sent to the server."""

    # Check login status
    try:
        if request.session['login']:
            return True
        else:
            if request.user.is_authenticated():  # User just logged in
                curr_user = request.user
            else:  # No user logged in
                return False
    except:  # Session not set up
        request.session['login'] = False
        request.session['user'] = None
        request.session['alpha'] = alpha
        request.session['categories'] = Category.objects.all().order_by('h_name')
        return False

    # Look up user in DB
    try:
        stu = Student.objects.get(netid=curr_user.username)
    except:  # User's first time; do ldap lookup and store in DB
        try:
            stu_info = gdi(curr_user.username)
            stu = Student(netid=curr_user.username, first_name=stu_info['givenName'], last_name=stu_info['sn'], email=curr_user.username+'@princeton.edu', year=int(stu_info['puclassyear']))
        except:
            stu = Student(netid=curr_user.username, email=curr_user.username+'@princeton.edu',first_name='Unknown',last_name='Unknown')
        stu.save()

    # Set up session
    request.session['login'] = True
    request.session['user'] = stu
    request.session['alpha'] = alpha
    request.session['categories'] = Category.objects.all().order_by('h_name')
    return True
Esempio n. 17
0
def get_user(username):
    # Check if user can be here
    try:
        user = User.objects.get(netid=username)
    except:
        info = gdi(username)
        user = User(netid=username,
                    firstname=info.get('givenName'),
                    lastname=info.get('sn'),
                    pustatus=info.get('pustatus'))
        if info.get('puclassyear'):
            user.puclassyear = int(info.get('puclassyear'))
        if user.pustatus == 'undergraduate':
            user.save()
            # Create queues for each draw
            for draw in Draw.objects.all():
                queue = Queue(draw=draw)
                queue.save()
                user.queues.add(queue)
        else:
            return None
    return user
Esempio n. 18
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))