From 5550ccf6cefbf9c81847797053446535d5a4b279 Mon Sep 17 00:00:00 2001 From: sosguns2002 Date: Tue, 22 Aug 2017 17:35:30 +0300 Subject: [PATCH] Upload codes, configure profile basic implementation --- .../madoap/src/madserver.py | 30 +++++++++++- .../src/templates/create_upload_profile.html | 17 ++++--- .../madoap/src/templates/upload_codes.html | 48 +++++++++++++++++-- 3 files changed, 83 insertions(+), 12 deletions(-) diff --git a/interactive-mining-madoap/madoap/src/madserver.py b/interactive-mining-madoap/madoap/src/madserver.py index 264c6c5..6efeaaa 100755 --- a/interactive-mining-madoap/madoap/src/madserver.py +++ b/interactive-mining-madoap/madoap/src/madserver.py @@ -737,7 +737,7 @@ class importingTextsControllerHandler(BaseHandler): class createUploadProfileHandler(BaseHandler): passwordless=True - # When loading the page first time and evry refresh + # When loading the page first time and every refresh def get(self): if 'data' in self.request.arguments: return @@ -749,11 +749,12 @@ class createUploadProfileHandler(BaseHandler): user_id = 'user{0}'.format(datetime.datetime.now().microsecond + (random.randrange(1, 100+1) * 100000)) self.set_secure_cookie('madgikmining', user_id) self.render('create_upload_profile.html', settings=msettings) + # TODO Upload profile post class uploadCodesHandler(BaseHandler): passwordless=True - # When loading the page first time and evry refresh + # When loading the page first time and every refresh def get(self): if 'data' in self.request.arguments: return @@ -764,6 +765,31 @@ class uploadCodesHandler(BaseHandler): return # check if he already uploaded his grants ids and inform him via a message self.render('upload_codes.html', settings=msettings) + def post(self): + try: + # get user id from cookie. Must have + user_id = self.get_secure_cookie('madgikmining') + if user_id is None: + return + if 'upload' in self.request.files: + # get file info and body from post data + fileinfo = self.request.files['upload'][0] + fname = fileinfo['filename'] + extn = os.path.splitext(fname)[1] + # must be .pdf or .json + if extn != ".txt" and extn != ".pdf": + self.write(json.dumps({'respond': "File must be .pdf or .txt"})) + return + # write data to physical file + cname = "/tmp/docs{0}{1}".format(user_id, extn) + fh = open(cname, 'w') + fh.write(fileinfo['body']) + fh.close() + + except Exception as ints: + self.write(json.dumps({'respond': "File Failed to Upload!"})) + print ints + return class configureProfileHandler(BaseHandler): diff --git a/interactive-mining-madoap/madoap/src/templates/create_upload_profile.html b/interactive-mining-madoap/madoap/src/templates/create_upload_profile.html index f8aa14f..cf14f68 100644 --- a/interactive-mining-madoap/madoap/src/templates/create_upload_profile.html +++ b/interactive-mining-madoap/madoap/src/templates/create_upload_profile.html @@ -3,13 +3,16 @@ {% block content %} Profile create - -
- Create a new mining profile -
-
or
-