コード例 #1
0
ファイル: .~c9_invoke_3xhDdj.py プロジェクト: Hlotfy/eltabler
def recent_orders(username):
    conn = functions.getConn('tabtracker')
    if not session.get('username'):
        access_tab(username)
    if request.method == 'POST':
        form = request.form.to_dict(flat=False)
        if form:
            print form
            form = [{form.keys()[j]: form.values()[j][i] for j in range(len(form))} for i in range(len(form.values()[0]))]
            print form
            
            functions.addOrder(conn,form,username)
            orders = functions.getRecentOrders(conn,username)
            items = functions.getOrderItems(conn,username)
            user = functions.getUser(conn,username)
            if session['username'] in session['currentOrders']:
                session['currentOrders'][session['username']].update(session['cart'])
            else:
                session['currentOrders'][session['username']] = session['cart']
            print session['currentOrders'][session['username']]
            clearCart()
            return render_template('recent_orders.html',orders=orders, items=items, user=user)
        else:
            return redirect(request.referrer)

    orders = functions.getRecentOrders(conn,username)
    items = functions.getOrderItems(conn,username)
    user = functions.getUser(conn,username)
    return render_template('recent_orders.html',orders=orders, items=items, user=user)
コード例 #2
0
ファイル: app.py プロジェクト: achanchan/WellesleyStays
def insertUser():
    if ('CAS_USERNAME' not in session):
        return redirect(url_for("index"))

    conn = functions.getConn(db)
    message = ''
    if request.method == 'POST':
        bnumber = request.form['bnumber']
        if len(bnumber) != 9:
            message = 'BNUMBER must be valid'
            flash(message)
            return redirect(request.referrer)
        exists = functions.getUser(conn, bnumber)
        if exists:
            message = 'error: user exists; User with bnumber: %s is already in database' % bnumber
        else:
            email = request.form['email']
            name = request.form['user_name']
            phonenum = request.form['phonenum']
            functions.insertUser(conn, bnumber, email, name, phonenum)
            message = 'User %s inserted.' % name
        flash(message)
        return redirect(url_for('index'))
    else:
        attributes = session['CAS_ATTRIBUTES']
        return render_template('insertUser.html', attributes=attributes)
コード例 #3
0
ファイル: serviceops.py プロジェクト: LouisChang/aponurho
def escort(request):
    user = getUser(request)
    if type(user) is HttpResponseRedirect:
        return user
    try:
        currentSemester = Semester.objects.get(active=True)
    except Semester.DoesNotExist:
        #no current semester!
        return HttpResponseRedirect("/main")
    if 'msg' in request.GET:
        message = messageDict[request.GET['msg']]
    else:
        message = None
    try:
        semreqs = SemesterRequirements.objects.get(semester=currentSemester, user=user)
    except SemesterRequirements.DoesNotExist:
        return HttpResponseRedirect("/main")
    myShifts = semreqs.escortShifts.all()
    shifts = EscortShift.objects.filter(semester=currentSemester).order_by("date", "shift")
    t = loader.get_template("aponurho/service.escort.html")
    contextDict = buildDict(user)
    contextDict.update({
                'message': message,
                'shifts': shifts,
                'myshifts': myShifts
                })
    c = RequestContext(request, contextDict)
    return HttpResponse(t.render(c))
コード例 #4
0
def payment(username):
    if not session.get('staffId'):
        return redirect(url_for('index'))
    conn = functions.getConn('tabtracker')
    user = functions.getUser(conn,username)
    if request.method == 'GET':
        payments = functions.getRecentPayments(conn,username)
            
        return render_template('payment_page.html', payments=payments, user=user)
        
    else: #method must be 'POST'
        #get the payment amount and method
        amount = request.form.get('amount')
        method = request.form.get('method')
        dt = request.form.get('dt')
        print "request dt: ", dt
        
        try:
            # convert to float to type check and to insert into database
            amount = float(amount)
        except ValueError:
            return jsonify({'error':True, 'err':"Please enter an number."})
            
        # make sure the employee enters a payment method
        if not method:
            return jsonify({'error':True, 'err': "Please select a payment method."})
            
        # make sure new payment will not drop balance below 0
        currentBalance = functions.getUser(conn,username)['balanceOwed']
        if(currentBalance - amount < 0):
            return jsonify({'error':True, 'err': "Please enter an amount that is less than the current balance."})
            
        #calculates the user's new balance and updates the database
        newBalance = functions.makePayment(conn,username,method,amount,dt)
        name = user['name']
        print name
        payments = functions.getRecentPayments(conn,username)

        try:
            method=request.form.get('method')
            amount=request.form.get('amount')
            print(method,amount)
            return jsonify({'error':False,'method':method,'amount':amount,'newBalance':newBalance,'user':name,'dt':dt})
        except Exception as err:
            return jsonify({'error':True, 'err':str(err)})
コード例 #5
0
ファイル: app.py プロジェクト: achanchan/WellesleyStays
def listing():
    if ('CAS_USERNAME' not in session):
        return redirect(url_for("index"))

    attributes = session['CAS_ATTRIBUTES']
    bnumber = attributes['cas:id']
    conn = functions.getConn(db)
    user = functions.getUser(conn, bnumber)
    return render_template('listingform.html', user=user)
コード例 #6
0
def get_user(user_id):
    res = functions.getUser(user_id)
    #print data
    
    if res["success"]:
        user = res['user']
        return {"status": 200, "success": True, "data": user}
    else:
        return {"status": 401, "success": False, "message": res['message']}
コード例 #7
0
ファイル: app.py プロジェクト: achanchan/WellesleyStays
def index():
    if ('CAS_USERNAME' in session):
        attributes = session['CAS_ATTRIBUTES']
        bnumber = attributes['cas:id']

        conn = functions.getConn(db)
        user = functions.getUser(conn, bnumber)
        if not user:
            return redirect("insertUser")

    return render_template('home.html')
コード例 #8
0
ファイル: serviceops.py プロジェクト: LouisChang/aponurho
def escortMain(request):
    user = getUser(request)
    if type(user) is HttpResponseRedirect:
        return user
    try:
        currentSemester = Semester.objects.get(active=True)
    except Semester.DoesNotExist:
        #no current semester!
        return HttpResponseRedirect("/main")
    t = loader.get_template("aponurho/service.escortmain.html")
    contextDict = buildDict(user)
    c = Context(contextDict)
    return HttpResponse(t.render(c))
コード例 #9
0
ファイル: app.py プロジェクト: achanchan/WellesleyStays
def requestPage(rid):
    if ('CAS_USERNAME' not in session):
        return redirect(url_for("index"))

    conn = functions.getConn(db)
    aRequest = functions.getRequest(conn, rid)
    guest = functions.getUser(conn, aRequest['bnumber'])
    if aRequest:
        if aRequest['isfilled']:
            aRequest['isfilled'] = 'Y'
        else:
            aRequest['isfilled'] = 'N'
        return render_template('request.html', aRequest=aRequest, guest=guest)
    else:
        flash('Request does not exist.')
        return redirect(request.referrer)
コード例 #10
0
ファイル: app.py プロジェクト: achanchan/WellesleyStays
def updateUser(bnumber):
    if ('CAS_USERNAME' not in session):
        return redirect(url_for("index"))

    conn = functions.getConn(db)
    if request.method == 'GET':
        user = functions.getUser(conn, bnumber)
        return render_template('updateUser.html', user=user)
    else:
        if request.form['submit'] == 'update':
            functions.updateUser(conn, bnumber, request.form['email'],
                                 request.form['user_name'],
                                 request.form['phonenum'], bnumber)
            flash('User (%s) was successfully updated' %
                  request.form['user_name'])
            return redirect(url_for('updateUser', bnumber=bnumber))
コード例 #11
0
ファイル: serviceops.py プロジェクト: LouisChang/aponurho
def deleteEscort(request):
    user = getUser(request)
    if type(user) is HttpResponseRedirect:
        return user
    try:
        currentSemester = Semester.objects.get(active=True)
    except Semester.DoesNotExist:
        #no current semester!
        return HttpResponseRedirect("/main")
    semreqs = SemesterRequirements.objects.get(user=user, semester=currentSemester)
    shift = EscortShift.objects.get(id=request.GET['id'])
    if shift.time() + timedelta(hours=24) < datetime.now():
        return HttpResponseRedirect("/service/escortsignup?msg=toolateunsign")
    #semreqs.escortHours = semreqs.escortHours - Decimal('2.5')
    semreqs.escortHours = Decimal(str(float(semreqs.escortHours) - 2.5))
    semreqs.escortShifts.remove(shift)
    semreqs.save()
    updateService(user, currentSemester)
    return HttpResponseRedirect("/service/escortsignup")
コード例 #12
0
ファイル: app.py プロジェクト: achanchan/WellesleyStays
def place(pid):
    if ('CAS_USERNAME' not in session):
        return redirect(url_for("index"))

    conn = functions.getConn(db)
    place = functions.getPlace(conn, pid)
    if place:
        host = functions.getUser(conn, place['bnumber'])
        availability = functions.getAvailabilityForPlace(conn, pid)
        src = functions.getPic(conn, pid)
        if src is not None:
            src = url_for('pic', pid=pid)
        return render_template('place.html',
                               place=place,
                               host=host,
                               availability=availability,
                               src=src)
    else:
        flash('Listing does not exist.')
        return redirect(request.referrer)
コード例 #13
0
ファイル: serviceops.py プロジェクト: LouisChang/aponurho
def main(request):
    user = getUser(request)
    if type(user) is HttpResponseRedirect:
        return user
    try:
        currentSemester = Semester.objects.get(active=True)
    except Semester.DoesNotExist:
        #no current semester!
        return HttpResponseRedirect("/main")
    months = [(1,"January"),
        (2,"February"),
        (3,"March"),
        (4,"April"),
        (5,"May"),
        (6,"June"),
        (7,"July"),
        (8,"August"),
        (9,"September"),
        (10,"October"),
        (11,"November"),
        (12,"December")]
    serviceOpps = ServiceOpp.objects.filter(permanentHours=False, semester=currentSemester)
    services = ServiceHours.objects.filter(user=user, type__semester=currentSemester).order_by("date")
    year = currentSemester.year
    try:
        semreqs = SemesterRequirements.objects.get(semester=currentSemester, user=user)
    except SemesterRequirements.DoesNotExist:
        return HttpResponseRedirect("/main")
    t = loader.get_template("aponurho/service.html")
    contextDict = buildDict(user)
    contextDict.update({
                'services': services,
                'serviceopps': serviceOpps,
                'year': year,
                'months': months,
                'days': range(1,32),
                'countable': semreqs.service,
                'hours': semreqs.serviceTotal
                })
    c = RequestContext(request, contextDict)
    return HttpResponse(t.render(c))
コード例 #14
0
ファイル: serviceops.py プロジェクト: LouisChang/aponurho
def deleteService(request):
    user = getUser(request)
    if type(user) is HttpResponseRedirect:
        return user
    try:
        currentSemester = Semester.objects.get(active=True)
    except Semester.DoesNotExist:
        #no current semester!
        return HttpResponseRedirect("/main")
    service = ServiceHours.objects.get(id=request.GET['id'])
    try:
        semreqs = SemesterRequirements.objects.get(semester=currentSemester, user=user)
    except SemesterRequirements.DoesNotExist:
        return HttpResponseRedirect("/main")
    a = service.type.name
    if (a.encode('ascii', 'ignore').find("Escort") != -1) or (a.encode('ascii', 'ignore').find("escort") != -1):
        semreqs.escortHours -= Decimal(str(service.hours))
        semreqs.save()
    service.delete()
    updateService(user, currentSemester)
    return HttpResponseRedirect("/service")
コード例 #15
0
ファイル: app.py プロジェクト: achanchan/WellesleyStays
def profile(bnumber):
    if ('CAS_USERNAME' not in session):
        return redirect(url_for("index"))

    conn = functions.getConn(db)
    user = functions.getUser(conn, bnumber)
    listings = functions.getUserListings(conn, bnumber)
    userRequests = functions.getUserRequests(conn, bnumber)
    if userRequests:
        for r in userRequests:
            if r['isfilled']:
                r['isfilled'] = 'Y'
            else:
                r['isfilled'] = 'N'
    if user:
        return render_template('profile.html',
                               user=user,
                               listings=listings,
                               requests=userRequests)
    else:
        flash('User does not exist.')
        return redirect(request.referrer)
コード例 #16
0
ファイル: serviceops.py プロジェクト: LouisChang/aponurho
def addEscort(request):
    user = getUser(request)
    if type(user) is HttpResponseRedirect:
        return user
    try:
        currentSemester = Semester.objects.get(active=True)
    except Semester.DoesNotExist:
        #no current semester!
        return HttpResponseRedirect("/main")
    semreqs = SemesterRequirements.objects.get(user=user, semester=currentSemester)
    if semreqs.escortShifts.all().count() >= 4:
        return HttpResponseRedirect("/service/escortsignup?msg=toomanyshifts")
    shift = EscortShift.objects.get(id=request.GET['id'])
    if shift.semesterrequirements_set.all().count() >= 6:
        return HttpResponseRedirect("/service/escortsignup?msg=fullshift")
    if shift.time() + timedelta(hours=24) < datetime.now():
        return HttpResponseRedirect("/service/escortsignup?msg=toolatesign")
    semreqs.escortShifts.add(shift)
    #semreqs.escortHours = semreqs.escortHours + Decimal('2.5')
    semreqs.escortHours = Decimal(str(float(semreqs.escortHours) + 2.5))
    semreqs.save()
    updateService(user, currentSemester)
    return HttpResponseRedirect("/service/escortsignup")
コード例 #17
0
ファイル: serviceops.py プロジェクト: LouisChang/aponurho
def escortRoster(request):
    user = getUser(request)
    if type(user) is HttpResponseRedirect:
        return user
    try:
        currentSemester = Semester.objects.get(active=True)
    except Semester.DoesNotExist:
        #no current semester!
        return HttpResponseRedirect("/main")

    shifts = EscortShift.objects.filter(semester=currentSemester).order_by("date", "shift")
    hiddenShifts = [shift for shift in shifts if shift.time() + timedelta(hours=24) < datetime.now()]
    visibleShifts = [shift for shift in shifts if shift.time() + timedelta(hours=24) >= datetime.now()]

    t = loader.get_template("aponurho/service.escortroster.html")
    contextDict = buildDict(user)
    contextDict.update({
                'hiddenshifts': hiddenShifts,
                'visibleshifts': visibleShifts,
                'all': ('all' in request.GET)
                })
    c = RequestContext(request, contextDict)
    return HttpResponse(t.render(c))
コード例 #18
0
ファイル: serviceops.py プロジェクト: LouisChang/aponurho
def addService(request):
    user = getUser(request)
    if type(user) is HttpResponseRedirect:
        return user
    try:
        currentSemester = Semester.objects.get(active=True)
    except Semester.DoesNotExist:
        #no current semester!
        return HttpResponseRedirect("/main")
    sDate = date(int(request.POST['year']), int(request.POST['month']), int(request.POST['day']))
    sType = ServiceOpp.objects.get(id=request.POST['type'])
    service = ServiceHours(user=user, date=sDate, type=sType, hours=request.POST['hours'], description=request.POST['desc'])
    service.save()

    try:
        semreqs = SemesterRequirements.objects.get(semester=currentSemester, user=user)
    except SemesterRequirements.DoesNotExist:
        return HttpResponseRedirect("/main")
    a = sType.name
    if (a.encode('ascii','ignore').find("Escort") != -1) or (a.encode('ascii', 'ignore').find("escort") != -1):
        semreqs.escortHours = Decimal(str(float(semreqs.escortHours) + float(request.POST['hours'].encode('ascii','ignore'))))
        semreqs.save()
    updateService(user, currentSemester)
    return HttpResponseRedirect("/service")
コード例 #19
0
def send():
    functions.getHost(newHost.get())
    functions.getPort(newPort.get())
    functions.getUser(newUsername.get())
    functions.getPass(newPassword.get())
    ssh.ssh()
コード例 #20
0
import cgi, cgitb
import xml.etree.ElementTree as ET
import functions as fun
from datetime import datetime
import os, sys

fun.init()
print ("Content-type:text/xml\r\n\r\n")

form = cgi.FieldStorage()

username = form.getvalue('username')
password = form.getvalue('password')


user = fun.getUser(username,password)

if user == None:
	print ("<error>Username and Password do not match up</error>")
	sys.exit()

if user[3] == 1:
	ID = user[4]
elif user[3] == 2:
	ID = form.getvalue('ID')
	if ID == None:
		print('<error>No Student ID Given On Teacher Account</error>')
		sys.exit()

sdate = form.getvalue("sdate")
edate = form.getvalue("edate")