Пример #1
0
def create(request):
    if request.POST:
        form = AmtForm(request.POST, request.FILES)
        if form.is_valid():
            form.save()

            username = request.POST.get('user', ' ')
            user = Amt.objects.get(user=username)
            photo_url = "http://sid.pythonanywhere.com/media/" + user.get_photo()
            create_AMT_hit(user.get_id(), photo_url)
            return HttpResponse(str(user.get_id()) + ' '+str(photo_url))
    else:
        form = AmtForm()

    args = {}
    args.update(csrf(request))

    args['form'] = form

    return render_to_response('create_amt.html', args)
        return True

sqlite_db_path = "/home/sid/csce438/db.sqlite"

conn = lite.connect(sqlite_db_path)
cur = conn.cursor()

# Get SQLite version
cur.execute('''SELECT SQLITE_VERSION()''')
result = cur.fetchone()
print "SQLite version: %s" % result

# Create table if it doesn't exist yet
if (table_exists(cur, "amt") == False):
    cur.execute('''CREATE TABLE amt (user TEXT, password TEXT, photo TEXT, HITId TEXT)''')

#cur.execute('''INSERT INTO amt_amt VALUES ('abcd1234', 'new_user_meow', 'meowmeow', 'http://sid.pythonanywhere.com/static/sample_pic.jpg', NULL)''')
#conn.commit()

amt.create_AMT_hit(18, 'http://sid.pythonanywhere.com/static/sample_pic.jpg')
t = (18,)
cur.execute('''SELECT * FROM amt_amt WHERE id=?''', t)
result = cur.fetchone()
print result

#print amt.get_AMT_progress('abcd1234')
#print amt.get_AMT_score('abcd1234')

conn.commit()
conn.close()