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


Python Score.save方法代码示例

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


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

示例1: request

# 需要导入模块: from models import Score [as 别名]
# 或者: from models.Score import save [as 别名]
def request(request):
    if request.method == "GET":
        rg = request.GET
        player = Player.objects.get(id=request.session['user_id'])
        if 'new_player_name' in rg:    
            player.name = rg['new_player_name']
            player.save()
            return HttpResponse(json.dumps({"result": "success", "player_name": rg['new_player_name']}))
        if 'new_max_score' in rg:
            game_name = rg['game_name']
            score = None
            try:
                score = Score.objects.get(player=player, game__name=game_name) 
            except:
                score = Score(player=player, game=Game.objects.get(name=game_name), score=0)
            score.score = rg['new_max_score']
            score.save()
            return HttpResponse(json.dumps({"result": "success", "max_score": rg['new_max_score']}))
        if 'max_score_records' in rg:
            game_name = rg['game_name']
            count = rg['count']
            max_score_records = []
            for record in Score.objects.filter(game__name=game_name).order_by('-score')[:10]:
                max_score_records.append({"score": record.score, "player_name": record.player.name})
            return HttpResponse(json.dumps(max_score_records))
开发者ID:antoshkaplus,项目名称:Django_PersonalWebsite,代码行数:27,代码来源:views.py

示例2: test_float_serialization

# 需要导入模块: from models import Score [as 别名]
# 或者: from models.Score import save [as 别名]
 def test_float_serialization(self):
     """Tests that float values serialize and deserialize intact"""
     sc = Score(score=3.4)
     sc.save()
     serial_str = serializers.serialize(self.serializer_name, [sc])
     deserial_objs = list(serializers.deserialize(self.serializer_name,
                                             serial_str))
     self.assertEqual(deserial_objs[0].object.score, Approximate(3.4, places=1))
开发者ID:Terhands,项目名称:django,代码行数:10,代码来源:tests.py

示例3: post

# 需要导入模块: from models import Score [as 别名]
# 或者: from models.Score import save [as 别名]
 def post(self, request):
     score = request.POST.get('score')
     question_id = request.POST.get('question_id')
     question = Question.objects.get(pk=question_id)
     
     score = Score(question=question,user=request.user,score=int(score))
     score.save()
     
     return HttpResponse(status=201)
开发者ID:muthurajendran,项目名称:hangman,代码行数:11,代码来源:views.py

示例4: submit

# 需要导入模块: from models import Score [as 别名]
# 或者: from models.Score import save [as 别名]
def submit(user):
    try:
        score_ = submit_score(request.form.to_dict())
    except MultipleInvalid as e:
        return show_errors(e)

    score = Score(value=score_['score'], user=user)
    score.save()
    return {"success": True}
开发者ID:raymank26,项目名称:asteroids-server,代码行数:11,代码来源:scores.py

示例5: create_score

# 需要导入模块: from models import Score [as 别名]
# 或者: from models.Score import save [as 别名]
def create_score(registered_client):
    score = Score()
    score.registered_client = registered_client
    score.played_on = timezone.now()
    score.recieved_on = timezone.now()
    score.play_time = random.randint(2000, 30000)
    score.altitude = random.randint(0, 2000)
    score.score = random.randint(0, 130)
    score.save()

    return score
开发者ID:RomekRJM,项目名称:BubbleUpServer,代码行数:13,代码来源:tests.py

示例6: addscore

# 需要导入模块: from models import Score [as 别名]
# 或者: from models.Score import save [as 别名]
def addscore(request, game_id):
    if request.method == "POST":
        form = ScoreForm(request.POST)
        if form.is_valid():
            score = Score()
            score.score = form.cleaned_data.get("score", "0")
            score.player = request.user
            score.game = get_object_or_404(Game, pk=game_id)
            score.date = datetime.now()
            score.save()
            return HttpResponseRedirect(reverse("ranking:index"))
    else:
        form = ScoreForm()

    return render_to_response(
        "ranking/addscore.html", {"form": form, "game_id": game_id}, context_instance=RequestContext(request)
    )
开发者ID:lite,项目名称:djsite,代码行数:19,代码来源:views.py

示例7: match_edit

# 需要导入模块: from models import Score [as 别名]
# 或者: from models.Score import save [as 别名]
def match_edit(request, match_id):
    content = json.loads(request.body)
    time = content['match_time']
    users = content['users']
    score_desc = content['score']

    match = Match.objects.get(id=match_id)
    match.match_time = time
    match.users = [user['user_id'] for user in users]
    score = None
    if match.score:
        score = match.score
        score.score_desc = score_desc
        score.save()
    else:
        if score_desc:
            score = Score(score_desc=score_desc)
            score.save()
    if score:
        match.score = score
    match.save()
    return JsonResponse({"success": "ok"})
开发者ID:hyades,项目名称:foot-match,代码行数:24,代码来源:views.py

示例8: initialiseScoring

# 需要导入模块: from models import Score [as 别名]
# 或者: from models.Score import save [as 别名]
def initialiseScoring(request):
	score = Score.objects(type='submitidea')
	if not score:
		score = Score()
		score.type='submitidea'
		score.value=100
		score.save()
	
	score = Score.objects(type='submitarticle')
	if not score:
		score = Score()
		score.type='submitarticle'
		score.value=80
		score.save()
	
	score = Score.objects(type='comment')
	if not score:
		score = Score()
		score.type='comment'
		score.value=50
		score.save()
	
	score = Score.objects(type='vote')
	if not score:
		score = Score()
		score.type='vote'
		score.value=40
		score.save()

	score = Score.objects(type='report')
	if not score:
		score = Score()
		score.type='report'
		score.value=20
		score.save()
	
	score = Score.objects(type='view')
	if not score:
		score = Score()
		score.type='view'
		score.value=10
		score.save()
	
	score = Score.objects(type='promotion')
	if not score:
		score = Score()
		score.type='promotion'
		score.value=80
		score.save()
		
	initialiseRatings()
	return HttpResponseRedirect('/')
开发者ID:naughtond,项目名称:innuvate,代码行数:54,代码来源:views.py

示例9: populate

# 需要导入模块: from models import Score [as 别名]
# 或者: from models.Score import save [as 别名]
 def populate(self):
   new_score = Score()
   new_score.score = random.randint(1, 1234)
   new_score.save()
开发者ID:CADBOT,项目名称:sample-django-mysql-selenium,代码行数:6,代码来源:storage.py


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