Esempio n. 1
0
def uploadFile(files) :
	if 'userToken' in session :
		userIdx = model.getAccountByToken(session['userToken'])[0][0]
		folder = os.path.join(UPLOAD_FOLDER, str(userIdx))
		if not os.access(folder, os.F_OK) :
			os.mkdir(folder)
		fileExt = files.filename.rsplit('.', 1)[1].lower()
		if fileExt in MUSIC_EXT :
			fileExt = 'music'
		elif fileExt in MOVIE_EXT :
			fileExt = 'movie'
		elif fileExt in IMAGE_EXT :
			fileExt = 'image'
		else :
			fileExt = 'file'
		fileName = secure_filename(files.filename)
		filePath = os.path.join(folder, str(int(time.time())) + fileName)
		dbFilePath = filePath.split("/", 1)[1]
		files.save(filePath)
		nTime = datetime.datetime.fromtimestamp(time.time())
		sql = "SELECT folder_idx FROM folder WHERE user_idx = %s order by folder_idx asc" % (userIdx)
		result = model.query(sql)
		if not result :
			sql = "INSERT INTO folder(user_idx, folder_name, folder_init_date) "
			sql += "VALUES (%s, 'index', '%s')" % (userIdx, nTime)
			model.query(sql)
			sql = "SELECT folder_idx FROM folder WHERE user_idx = %s order by folder_idx asc" % (userIdx)
			result = model.query(sql)
		sql = "INSERT INTO files(user_idx, folder_idx, file_origin_name, file_path, file_type, file_is_shared, folder_init_date)"
		sql += "VALUES (%s, %s, '%s', '%s', '%s', %s, '%s')" % (userIdx, result[0][0], fileName, dbFilePath, fileExt, 0, nTime)
		result = model.query(sql)

		return json.dumps({"result" : 1})
	return json.dumps({"result" : -1})
Esempio n. 2
0
 def get(self):
     if self.answerID in models.query(models.Answers.id):
         a = models.query(models.Answers, str(self.answerID))
         self.questionID = a.get_questionID()
         self.answer = a.get_answer()
         return True
     return False
Esempio n. 3
0
 def get(self):
     if self.questionID in models.query(models.Questions.id):
         q = models.query(models.Questions, str(self.questionID))
         self.questionType = q.get_questionType()
         self.question = q.get_question()
         self.choices = q.get_choices()
         self.order = q.get_order()
         return True
     return False
Esempio n. 4
0
 def get(self):
     if self.formID in models.query(models.Forms.id):
         f = models.query(models.Forms, str(self.formID))
         self.isOwner = self.userID == f.get_ownerID()
         self.questions = f.get_questions()
         self.userAnswers = f.get_userAnswers()
         if self.isTest:
             self.correctAnswers = f.get_correctAnswers()
         else:
             self.correctAnswers = []
         return True
     return False
Esempio n. 5
0
def downloadFile(fileIdx) :
	if 'userToken' in session :
		userIdx = model.getAccountByToken(session['userToken'])[0][0]
		sql = "SELECT file_origin_name, file_path FROM files WHERE user_idx = %s and file_idx = %s" % (userIdx, fileIdx)
		result = model.query(sql)
		if result :
			return send_file(result[0][1], as_attachment = True, attachment_filename = result[0][0]), 200
		return "<script> alert('No Data'); history.back(-1); </script>", 404
	return "<script> alert('Permission Denied'); history.back(-1); </script>", 401
Esempio n. 6
0
 def put(self):
     session = models.Session()
     if self.userID in models.query(models.Users.id):
         query = session.query(models.Users).filter(models.Users.id == str(self.userID)).first()
         query.forms = str(self.forms)
     else:
         session.add(models.Users(id=self.userID, forms=str(self.forms)))
     session.commit()
     session.close()
     return True
Esempio n. 7
0
 def put(self):
     session = models.Session()
     if self.answerID in models.query(models.Answers.id):
         query = session.query(models.Answers).filter(
             models.Answers.id == str(self.answerID)).first()
         query.questionID = str(self.questionID)
         query.answer = str(self.answer)
     else:
         session.add(
             models.Answers(id=self.answerID,
                            questionID=self.questionID,
                            answer=str(self.answer)))
     session.commit()
     session.close()
     return True
Esempio n. 8
0
 def put(self):
     session = models.Session()
     if self.formID in models.query(models.Forms.id):
         query = session.query(models.Forms).filter(
             models.Forms.id == str(self.formID)).first()
         query.questions = str(self.questions)
         query.userAnswers = str(self.userAnswers)
         query.correctAnswers = str(self.correctAnswers)
     else:
         session.add(
             models.Forms(id=models.generateUUID(self.formID[:1]),
                          ownerID=self.ownerID,
                          questions=str(self.questions),
                          userAnswers=str(self.userAnswers),
                          correctAnswers=str(self.correctAnswers)))
     session.commit()
     session.close()
     return True
Esempio n. 9
0
def getFileList() :
	if 'userToken' in session :
		entries = list()
		userIdx = model.getAccountByToken(session['userToken'])[0][0]
		sql = "SELECT file_idx, folder_idx, file_origin_name, file_type, folder_init_date, file_path "
		sql += "FROM files where user_idx = %s" % (userIdx)
		result = model.query(sql)
		if result :
			for i in result :
				entry = dict()
				entry['fileIdx'] = i[0]
				entry['folderIdx'] = i[1]
				entry['fileOriginName'] = i[2]
				entry['fileType'] = i[3]
				entry['fileInitDate'] = i[4].strftime("%Y/%m/%d %H시  %M분")
				entry['filePath'] = i[5].split("/", 1)[1]
				entries.append(entry)
			return entries
		return None
Esempio n. 10
0
    def put(self):
        session = models.Session()
        if self.questionID in models.query(models.Questions.id):
            query = session.query(models.Questions).filter(
                models.Questions.id == str(self.questionID)).first()

            query.questionType = str(self.questionType)
            query.question = str(self.question)
            query.choices = str(self.choices)
            query.order = str(self.order)

        else:
            session.add(
                models.Questions(id=self.questionID,
                                 questionType=self.questionType,
                                 question=self.question,
                                 choices=str(self.choices),
                                 order=str(self.order)))
        session.commit()
        session.close()
        return True
Esempio n. 11
0
def attribute_edit():
    kwargs = {}
    kwargs['title'] = 'Edit Attribute'
    kwargs['startup_function'] = 'attributeEditPage'
    if request.method == 'GET':
        return render_template('blank.html')
    # otherwise, we are saving a new or updated attribute_edit
    # return str(request.get_json())
    valid, output = models.attribute_form_process(request.get_json())
    if not valid:
        return output, 400
    try:
        if 'id' in output:
            models.attribute_insert(output)
        else:
            models.attribute_insert(output)
        return "success"
    except mysql.connector.Error as e:
        return str(e) + " " + models.query(), 500
    except Exception as e:
        return str(e), 500
Esempio n. 12
0
def bookstore_book(book_id):
    book = models.query(book_id)
    return render_template('book.html', book=book)
Esempio n. 13
0
def bookstore_books():
    books = models.query()['results']
    return render_template('books.html', books=books)
Esempio n. 14
0
 def get(self, book_id):
     # GET http://[hostname]/api/books/[book_id] 取得書本資料
     return models.query(book_id)
Esempio n. 15
0
 def get(self):
     # GET http://[hostname]/api/books 取得書本清單
     return models.query()
Esempio n. 16
0
 def get(self):
     if self.userID in models.query(models.Users.id):
         self.forms = models.query(models.Users, str(self.userID)).get_forms()
         return True
     return False
Esempio n. 17
0
                answer = tuple(r)
            order = tuple(shuffle(r))
        else:
            done = True
        
        if(not done):
            qID = f.addQuestion(questionTypes[qChoice-1], question, choice, order)
            if(f.isTest):
                f.addAnswer(qID, answer, order)
    display(userID, f.formID)

if __name__ == "__main__":
    logged_in = False
    while(True):
        if(not logged_in):
            users = models.query(models.Users)
            print("Select an existing user or create a new user: "******". "+str(users[i-1].get_id()))
            print(str(len(users)+1)+". NEW USER")
            uChoice = int(input())
            if(uChoice in range(1, len(users)+1)):
                u = user(users[uChoice-1].get_id())
                u.forms = users[uChoice-1].get_forms()
            else:
                u = user()
                u.forms = []
            logged_in = True
            sChoice = '0'
        if(logged_in):
            while(sChoice not in {'1','2', '3', 'LOGOUT'}):