def post(self):

        # upload new material on google drive
        user = UserData.get_current_user()
        if not user.is_server_admin():  # make sure user has an account to create course
            self.redirect('/')

        # [TODO]Benny: scheduled_update_date超醜,要改掉
        # [TODO]Benny: new_feature_performance要搬到CreateFeaturePerformance 這個handler
        scheduled_update_date = self.request.get('scheduled_update_date')
        scheduled_update_date = datetime.datetime.strptime(scheduled_update_date, "%Y-%m-%d")
        logging.info('scheduled_update_date: %s' %scheduled_update_date)
        index = self.request.get('performance_index')
        new_feature_performance = FeaturePerformance(
            scheduled_update_date=scheduled_update_date,
            index=index)
        new_feature_performance.put()

        feature_name = self.request.get('feature-name')
        summary = self.request.get('summary')
        KPIs = self.request.get('KPI')
        new_feature = Feature(name=feature_name,
                            summary=summary,
                            KPIs=KPIs.strip().split(','),
                            performances=[new_feature_performance.key]
                            )
        new_feature.put()



        self.redirect('/show-feature/%s' % new_feature.key.id()) # 
    def post(self):

        # create or update feature bet
        user = UserData.get_current_user()
        if not user.is_server_admin():  # make sure user has an account to create course
            self.redirect('/')

        feature_key = self.request.get('feature_wanted')
        feature = Feature.get_by_id(int(feature_key))

        options = self.request.get('options').split('\n')
        start_time = self.request.get('start-time')
        start_time = datetime.datetime.strptime(start_time, "%Y-%m-%d")
        end_time = self.request.get('end-time')
        end_time = datetime.datetime.strptime(end_time, "%Y-%m-%d")

        billing_time = self.request.get('billing-time')
        billing_time = datetime.datetime.strptime(billing_time, "%Y-%m-%d")

        new_bet = FeatureBet(performance_bet=feature.performances[0],
                            bet_options=options,
                            start_time=start_time,
                            end_time=end_time,
                            billing_time=billing_time
                            )

        new_bet.put()

        self.redirect('/show-feature/%s' % feature.key.id()) # 
    def get(self):

        # get all features and feature_performance to be chose
        # form page to create/update feature bet
        features = Feature.query().fetch()
        performances = FeaturePerformance.query().fetch()
        data = {
            'features': features,
        }
        return self.render('feature/create-feature-bet.html', data)
    def get(self):

        features = Feature.query().fetch()
        features.sort(key=lambda x: x.created_time, reverse=True)

        # get related feature_bets
        # create feature bets json
        feature_KPIs = [','.join(f.KPIs) for f in features]

        data = {
            'features': features,
            'feature_KPIs': feature_KPIs
        }

        return self.render('feature/list-features.html', data)
 def get(self):
     logging.info('ShowPerformance')
     user = UserData.get_current_user()
     features = Feature.query().fetch()
     feature_performances = []
     for feature in features:
         performance = feature.performances[0].get()
         feature_performances.append({
             'name': feature.name,
             'index': performance.index,
             'scheduled_update_date': performance.scheduled_update_date,
             'key': performance.key.id()
         })
     logging.info('feature_performances: %s' %feature_performances)
     data = {
         'feature_performances': feature_performances
     }
     return self.render('feature/show-performance.html', data)
    def get(self, feature_id):

        user = UserData.get_current_user()
        feature = Feature.get_by_id(int(feature_id))
        feature_KPIs = ','.join(feature.KPIs)
        feature_performance = feature.performances[0].get()
        feature_bets = FeatureBet.get_by_feature_performance(feature_performance)

        # get feature bets by feature
        # get user_feature bets by feature bets
        # get feature performance by feature

        # show all these data in the proper way
        data = {
            'user': user,
            'feature': feature,
            'feature_KPIs': feature_KPIs,
            'feature_bets': feature_bets,
            'feature_performance': feature_performance
        }

        return self.render('feature/show-feature.html', data)