예제 #1
0
def practice_arithmetic(dbs, communicator, user, operation, min_x, max_x,
                        min_y, max_y):
    # Get or add pertinent arithmetic records:
    #q = dbs.query(db.Performance).filter_by(user = user).filter(db.Performance.x >= min_x).filter(db.Performance.x <= max_x).filter(db.Performance.y >= min_y).filter(db.Performance.y <= max_y).filter(db.Performance.operation == operation).order_by(db.Performance.recent_speed_ms.desc()).order_by(db.Performance.id)
    prefs = db.get_preferences(dbs, user.username)
    if prefs.start_x:
        min_x = max(min_x, prefs.start_x)
    if prefs.start_y:
        min_y = max(min_y, prefs.start_y)
    q = dbs.query(db.Performance).filter_by(user=user).filter(
        db.Performance.x >= min_x).filter(db.Performance.x <= max_x).filter(
            db.Performance.y >= min_y).filter(
                db.Performance.y <= max_y).filter(
                    db.Performance.operation == operation).order_by(
                        db.Performance.id)
    records = q.all()
    existing_combos = [(r.x, r.y) for r in records]
    for combo in [(a, b) for a in range(min_x, max_x + 1)
                  for b in range(min_y, max_y + 1)]:  # all combos as 2-tuples
        if combo not in existing_combos:
            # Add additional combo:
            dbs.add(
                db.Performance(user_id=user.id,
                               x=combo[0],
                               y=combo[1],
                               operation=operation))
    dbs.commit()
    # Re-fetch, to get default values:
    records = q.all()
    # Now run the practice:
    _practice(dbs, communicator, records,
              5000)  # threshold of 4 seconds for arithmetic operations
예제 #2
0
파일: server.py 프로젝트: mgway/skillbook
    def post(self):
        user_id = self.get_current_user()
        messages = self.messages.copy()
        
        if self.get_argument('email-form', default=None):
            mail = self.get_argument('email', default='')
            letter = self.get_argument('newsletter', default=False)
            resubscribe = self.get_argument('resubscribe', default=False) == 'on'
            
            db.change_preferences(user_id, mail, letter, resubscribe)
            messages['mail'] = 'Mail preferences updated'

        elif self.get_argument('password-form', default=None):
            password = self.get_argument('current_password')
            new_pw = self.get_argument('password')
            new_pw_dup = self.get_argument('password_dup')
            if new_pw != new_pw_dup:
                messages['password_error'] = 'Passwords don\'t match'
            else:
                try:
                    db.change_password(user_id, password, new_pw)
                    messages['password'] = '******'
                except db.UserError as e:
                    messages['password_error'] = e.message
        
        prefs = db.get_preferences(user_id)
        self.render('settings.html', prefs=prefs, **messages)
예제 #3
0
def parse_args(channel_id, args):
    args = args.split(' ')

    if args[0] == 'preferences':
        # TODO: format this in a nice way (get ordered dict out)
        return 'Your lunch-spinner preferences are %s' % (str(
            db.get_preferences(channel_id).items()))

    elif args[0] == 'setup':
        new_valid_settings = parse_valid_settings(args)
        all_settings = db.set_preferences(channel_id, new_valid_settings)

        # TODO: reload restaurants upon settings change
        # get_restaurants(channel_id)

        return "We've set your preference to %s \n Your settings are now: %s" % (
            new_valid_settings, db.get_preferences(channel_id))
예제 #4
0
파일: server.py 프로젝트: raylu/skillbook
 def get(self):
     userid = self.get_current_user()
     keys = db.get_keys(userid)
     prefs = db.get_preferences(userid)
     error = self.get_argument("error", "")
     context = self.get_argument("context", "")
     self.render('settings.html', keys=keys, prefs=prefs,
             error=error, context=context)
예제 #5
0
def _math(ws_method, again):
    sess = b.request.environ.get('beaker.session')
    dbs = session_maker()
    prefs = db.get_preferences(dbs, sess['username'])
    ac, no_source_length = make_audios()
    return b.template('math',
                      ws_protocol=k_ws_protocol,
                      ws_url_prefix=k_ws_url_prefix,
                      ws_method=ws_method,
                      intro=k_math_intro,
                      trial=sess.get('trial', 0),
                      again=gurl(again),
                      timer_minutes=prefs.time_minutes,
                      counter=prefs.count,
                      audio_controls=ac,
                      audio_count=no_source_length)
예제 #6
0
파일: server.py 프로젝트: mgway/skillbook
 def get(self):
     user_id = self.get_current_user()
     prefs = db.get_preferences(user_id)
     self.render('settings.html', prefs=prefs, **self.messages)
예제 #7
0
파일: divie.py 프로젝트: athuras/divie
def requestPrefs():
    if request.method == 'POST':
        data = db.get_preferences(1)
        lots = db.get_lots(1)
        res = prefs.processPrefs(data, lots)
        return createJSON(res)
예제 #8
0
def preferences():
    dbs = session_maker()
    sess = b.request.environ.get('beaker.session')
    prefs = db.get_preferences(dbs, sess['username']).__dict__
    return b.template('preferences', username=sess['username'], values=prefs)
예제 #9
0
def get_restaurants(channel_id):
    businesses = refresh_business_list(db.get_preferences(channel_id))
    db.set_restaurants(channel_id, businesses)