当前位置: 首页>>代码示例>>Python>>正文


Python User.save方法代码示例

本文整理汇总了Python中user.User.save方法的典型用法代码示例。如果您正苦于以下问题:Python User.save方法的具体用法?Python User.save怎么用?Python User.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在user.User的用法示例。


在下文中一共展示了User.save方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: fivee

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import save [as 别名]
def fivee():
    if request.method == 'POST':
        user = User.get_user_from_token(request.form['token'])
        if not user:
            abort(404)
        user.load()
        if user['status'] == "waiting":
            return jsonify({})
        user['lat'] = request.form['lat']
        user['lng'] = request.form['lng']
        if not user['lat'] or not user['lng']:
            abort(400)
        user.save()
        log.info("User %s want to be a fivee", user['username'])
        fiver_wait_list = User.get_wait_list('fiver')
        fiver_match = None
        fiver_distance = None
        for str_fiver in fiver_wait_list:
            fiver = json.loads(str_fiver)
            distance = user.distance(fiver['lat'], fiver['lng'])
            if fiver_distance is None or distance < fiver_distance:
                fiver_distance = distance
                fiver_match = str_fiver

        if fiver_distance is None or fiver_distance > MAX_FYVE_DISTANCE:
            # No matches
            user['match'] = "..."
            user['status'] = "waiting"
            user.save()
            User.insert_into_wait_list('fivee', json.dumps(user.wait_list_format))
            return jsonify({})

        # We found a match!
        User.remove_from_wait_list('fiver', fiver_match)
        fiver_match = User(json.loads(fiver_match)['username'])
        fiver_match.load()
        fiver_match['match'] = user['username']
        fiver_match['status'] = "matched"
        fiver_match.save()
        user['match'] = fiver_match['username']
        user['status'] = "matched"
        user.save()

        return jsonify(fiver_match.match_format)

    else:
        user = User.get_user_from_token(request.args['token'])
        if not user:
            abort(404)
        user.load()
        # Checking in for a match
        if user['match'] == "...":
            # Still waiting
            assert user['status'] == "waiting"
            return jsonify({})
        # We have a match!
        match_user = User(user['match'])
        match_user.load()
        return jsonify(match_user.match_format)
开发者ID:Spearl,项目名称:highfyve-api,代码行数:61,代码来源:fyve.py

示例2: register

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import save [as 别名]
def register():
    """ Let's read the config """
    with open(os.path.join(os.path.dirname(__file__), "config.yaml"), "r") as f:
        doc = yaml.load(f)

    """ Let's create the database object """
    db = DB(doc["database"]["host"], doc["database"]["user"], doc["database"]["pw"], doc["database"]["dbname"])

    mail_id = ""
    if request.method == "POST":
        if request.form["mail_id"] != None and request.form["mail_pw"] != None:
            user = User(db, request.form["mail_id"], request.form["mail_pw"])
            user.save()

    return render_template("/pages/register.html", error=mail_id)
开发者ID:sebbekarlsson,项目名称:mailsystem,代码行数:17,代码来源:register.py

示例3: success

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import save [as 别名]
def success():
    user = User.get_user_from_token(request.form['token'])
    if not user:
        abort(404)
    log.info("User %s is reporting a successful high five!", user['username'])
    user.load()
    user_fyved = User(user['match'])
    user_fyved.load()

    # Fuck yeah!
    user['status'] = "fyved"
    user.save()
    user_fyved['status'] = "fyved"
    user_fyved.save()

    return jsonify({})
开发者ID:Spearl,项目名称:highfyve-api,代码行数:18,代码来源:fyve.py

示例4: bail

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import save [as 别名]
def bail():
    user = User.get_user_from_token(request.form['token'])
    if not user:
        abort(404)
    log.info("User %s is bailing", user['username'])
    user.load()

    user_left_hanging = User(user['match'])
    user_left_hanging.load()
    user_left_hanging['status'] = "cancelled"
    user_left_hanging.save()

    user['status'] = "cancelled"
    user.save()

    return jsonify({})
开发者ID:Spearl,项目名称:highfyve-api,代码行数:18,代码来源:fyve.py

示例5: post

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import save [as 别名]
    def post(self):
        try:
            body = json.loads(self.request.body)
            name = body['name']
            pw = body['pw']
            target_url = body.get('next')
        except (KeyError, ValueError, TypeError) as e:
            self.application.log.info('User creation request malformed, error={}, url={}, body={}'.format(e, self.request.uri, self.request.body))
            self.send_error(httplib.BAD_REQUEST)
            return

        exists = yield User.exists(name)
        if exists:
            self.send_error(httplib.CONFLICT)
            return

        user = User(name, pw)
        yield user.save()
        self.set_current_user(user.guid)
        if target_url:
            self.redirect(target_url)
        else:
            self.set_header('Location', self.reverse_url(UserMaintenanceHandler.__name__, user.guid))
            self.write(self.application.user_representation(user))
            self.set_status(httplib.CREATED)
开发者ID:lchapple,项目名称:minterest,代码行数:27,代码来源:api.py

示例6: main

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import save [as 别名]
def main():
    #    user = random_user()
    #    with open(FILENAME, "w") as f:
    #        f.write(user.yaml())

    print 70 * "="
    user = User()
    user = read_user(FILENAME)

    print 70 * "="
    pprint(user.json())
    user.save()

    user.update(**{"set__username": "Hallo"})
    user.save()
    print User.objects(username="Hallo")
开发者ID:lee212,项目名称:cloudmesh,代码行数:18,代码来源:read.py

示例7: login

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import save [as 别名]
def login():
    username = request.form['username']
    password = request.form['password']
    user = User(username)
    if not user.exists:
        if not request.form['photo']:
            abort(401)
        user['token'] = str(uuid.uuid4()).replace('-','')
        user['password'] = password
        user['photo'] = request.form['photo']
        user.save()
        user.save_token()
    else:
        user.load()
        if password != user['password']:
            abort(401)
    log.info("User %s logged in", username)
    return jsonify({'token': user['token']})
开发者ID:Spearl,项目名称:highfyve-api,代码行数:20,代码来源:fyve.py

示例8: post

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import save [as 别名]
 def post(self):
     if not request.json:
         abort(400)
     user = User.objects(user_id=request.json['user_id'])
     if user.first() != None:
         return jsonify({'Result':'User ID already exists'})
     user = User(
         user_id= request.json['user_id'],
         cliqs= request.json['cliqs'],
         first_name= request.json['first_name'],
         last_name= request.json['last_name'],
         gender= request.json['gender'],
         phone= request.json['phone'],
         age= request.json['age'],
         _id= ObjectId()
     )
     user.save()
     return user.to_json()
开发者ID:dadavis21,项目名称:json_rest_api,代码行数:20,代码来源:userView.py

示例9: new

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import save [as 别名]
def new():
    """New user form."""
    if request.method == 'POST':
        u = User(request.form['email'])
        if u.save():
            return render_template('/created.html', user=u)
        else:
            flash('Invalid email or user already exists.', 'danger')
            return render_template('new.html')
    else:
        return render_template('new.html')
开发者ID:WilliamRen,项目名称:python-totp,代码行数:13,代码来源:main.py

示例10: post

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import save [as 别名]
    def post(self):
        values = {
            'username': self.request.get('username').strip().lower(),
            'password': self.request.get('password'),
            'password_confirmation': self.request.get('password_confirmation'),
            'email': self.request.get('email').strip().lower()}

        # If user is successfully saved to database, it returns the user,
        # otherwise it returns errors occured during validation process
        new_user = errors = User.save(values)
        if new_user.__class__ == User:
            # User successfully created_at
            self.login(new_user.key().id())
            self.redirect('/')
        else:
            # User information has some errors
            self.render('signup.html', values=values, errors=errors)
开发者ID:sbagdat,项目名称:multiplog,代码行数:19,代码来源:main.py

示例11: get_message_reply

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import save [as 别名]
def get_message_reply(message):	
	user = User(message.sender.id)
	if message.text == "/start" or message.text == "🔄 Начать заново":
		user.progressLabel, user.progressKey, user.active, user.variables = "start", -1, 1, {}
		user.save() 	
		return ("Вы начали игру заново", ReplyKeyboardMarkup.create([['⏸ Приостановить игру']],resize_keyboard=True))
	elif message.text == "/pause" or message.text == "⏸ Приостановить игру":
		user.active = 0
		user.save()
		return ("Игра приостановлена", ReplyKeyboardMarkup.create([['🔄 Начать заново'],['▶️ Продолжить игру']],resize_keyboard=True))
	elif message.text == "/continue" or message.text == "▶️ Продолжить игру":
		user.active = 1
		user.save()
		return ("Игра возобновлена", ReplyKeyboardMarkup.create([['⏸ Приостановить игру']],resize_keyboard=True))
	else:
		scenario.load(user)
		if scenario.get_current().__class__.__name__ == "NodeMenu":
			menu_item_finded = False
			for line,label in scenario.get_current().menu:
				if (line == message.text):
					menu_item_finded = True
					scenario.goto(label,-1)
					break
			if (menu_item_finded):
				reply, menu = scenario.next()
				user.load(scenario)
				user.lastMessage = round(time.time())
				user.save()
				if (menu):
					return (reply, ReplyKeyboardMarkup.create([[line] for line,label in menu],resize_keyboard=True))
				else:
					return (reply, ReplyKeyboardMarkup.create([['⏸ Приостановить игру']],resize_keyboard=True))
			else:
				return ("???", ReplyKeyboardMarkup.create([[line] for line,label in scenario.get_current().menu] + [['🔄 Начать заново']],resize_keyboard=True))
		else:
			if (user.active):
				return ("Чтобы начать заново введите /start, чтобы приостановить игру введите /pause", ReplyKeyboardMarkup.create([['🔄 Начать заново'],['⏸ Приостановить игру']],resize_keyboard=True))
			else:
				return ("Чтобы начать заново введите /start, чтобы продолжить игру введите /continue", ReplyKeyboardMarkup.create([['🔄 Начать заново'],['▶️ Продолжить игру']],resize_keyboard=True))
开发者ID:Tairesh,项目名称:telegram-quest,代码行数:41,代码来源:bot.py

示例12: User

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import save [as 别名]
from urllib2 import urlopen, URLError
from user import User
import sys
import simplejson as json
import psycopg2
import cPickle
import time
from copy import copy

conn = psycopg2.connect("dbname='jmelloy'")
cursor = conn.cursor()

screenname = sys.argv[1]

central_user = User(screenname, conn, True)
central_user.save()

users = set(central_user.followers(True))

user_follow = {}
users.add(central_user.id)

blacklist = ["BarackObama", "MrTweet", "tweet140", "yourheart", "yourpenis", "plusplusbot"]
#blacklist = []

user_hash = {central_user.id:central_user}

sql = "insert into twitter_followers values (%(id)s, %(data)s)"
failed = []
for u in users:
    print u
开发者ID:jmelloy,项目名称:tweetdag,代码行数:33,代码来源:tweetdag.py

示例13:

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import save [as 别名]
# This script creates all tables from each model defined before: User, State, City, Place, PlaceBook, Amenity, PlaceAmenities

from base import database
from user import User
from state import State
from city import City
from place import Place
from place_book import PlaceBook
from amenity import Amenity
from place_amenity import PlaceAmenities

database.connect()

database.create_tables([User, State, City, Place, PlaceBook, Amenity, PlaceAmenities], safe=True)

test_record=User(email='foo', password='bar', first_name='foo',last_name='bar')
test_record.save()
开发者ID:IanWagener,项目名称:airbnb_clone,代码行数:19,代码来源:migrate.py


注:本文中的user.User.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。