def get(self):
        # Checks for active Google account session for app auth
        user = users.get_current_user()
        if user:
            logging.debug('User found, object instance: %s', user)
            user_id = users.get_current_user().user_id()
            logging.debug('User id: %s', user_id)

            # Checks for Quant session
            session = SessionData.query(SessionData.user == user_id).get()
            # If not, init a session
            if not session:
                session = SessionData(user=user_id,
                                      email=user.nickname(),
                                      qtarget = "Co",
                                      qlambda=0,
                                      available = phaselist.availablePhases,
                                      selected = phaselist.defaultPhases)
                session.put()
                # logging.debug(session.available)
            # logging.debug(session)
            ## Code to render home page
            template = JINJA_ENVIRONMENT.get_template('upload.html')
            template_vars = {
                'upload_form_url': '/process'
            }
            self.response.out.write(template.render(template_vars))
        else:
            logging.debug("No user -> need login")
            self.redirect(users.create_login_url(self.request.uri))
    def get(self):
        logging.debug("Calibration")
        user = users.get_current_user()
        if user:
            user_id = users.get_current_user().user_id() 
            session = SessionData.query(SessionData.user == user_id).get()

            if not session:
                session = SessionData(user=user_id,
                                      email=user.nickname(),
                                      qtarget = "Co",
                                      qlambda=0,
                                      available = phaselist.availablePhases,
                                      selected = phaselist.defaultPhases)
                session.put()
            # logging.debug(session)
            template = JINJA_ENVIRONMENT.get_template('calibration.html')
            template_vars = {
                'lambda': session.qlambda,
                'target': session.qtarget,
            }
            self.response.out.write(template.render(template_vars))
        else:
            logging.info("No user -> need login")
            self.redirect(users.create_login_url(self.request.uri))
    def post(self):
        logging.debug("Loading File...")
        user = users.get_current_user()
        if user:
            logging.debug('User signed, object instance: %s', user)
        logging.debug(user.user_id())
        logging.debug(user.nickname())
        logout = users.create_logout_url('/')
        user_id = users.get_current_user().user_id()
        logging.debug(user_id)
        ludo = SessionData.query(SessionData.user == user_id).get()
        if not ludo:
            ludo = SessionData(user=user_id, email=user.nickname())
        ludo.sampleBlob = self.request.get('file')
        ludo.sampleFilename = self.request.params["file"].filename
        user_data_key = ludo.put()
        logging.debug(ludo.sampleFilename)
        logging.debug(user_data_key)

        # Generate image, returns results
        results = dynamic_png(user_data_key)
        csv = user_data_key.urlsafe()
        template = JINJA_ENVIRONMENT.get_template('chart.html')
        template_vars = {
            'phaselist': ludo.results,
            'url_text': csv,
            'logout_url': logout,
            'user': user.nickname(),
            'key': user_data_key.urlsafe(),
            'samplename': ludo.sampleFilename
        }
        self.response.out.write(template.render(template_vars))
 def get(self):
     user = users.get_current_user()
     if user:
         user_id = users.get_current_user().user_id() 
         session = SessionData.query(SessionData.user == user_id).get()
         # Checks for Quant session
         # If not, init a session
         if not session:
             session = SessionData(user=user_id,
                                   email=user.nickname(),
                                   qtarget = "Co",
                                   qlambda=0,
                                   available = phaselist.availablePhases,
                                   selected = phaselist.defaultPhases)
             session.put()
         template = JINJA_ENVIRONMENT.get_template('phase.html')
         template_vars = {
             'availablephaselist': session.available,
             'selectedphaselist': session.selected
         }
         self.response.out.write(template.render(template_vars))
     else:
         logging.info("No user -> need login")
         self.redirect(users.create_login_url(self.request.uri))