def gift(request): if not request.user.has_perm('app.master'): raise PermissionDenied if request.method == 'GET': return render(request, 'staff/gift.html', {"form": FastSendForm()}) else: form = FastSendForm(request.POST) if form.is_valid(): player = form.cleaned_data['player'] card = Card() # hard code present = request.user.first_name if present == "": present = '祝福' with transaction.atomic(): card.name = "來自 %s 的%s" % (request.user.last_name, present) card.value = form.cleaned_data['point'] card.comment = form.cleaned_data['message'] card.active = True card.retrieved = True card.issuer = request.user card.capturer = player card.save() record_reciever = History(action=0xfeed, user=player.user, card=card, comment="從 %s 收到一張卡片" % request.user.get_full_name()) record_reciever.save() record_sender = History( action=0xfeed, user=request.user, card=card, comment="給了 %s (%s)" % (player.user.get_full_name(), player.user.username)) record_sender.save() return render( request, "submit.html", { "success": True, "title": "成功發送卡片", "content": "成功將卡片送給 %s 了!" % player.user.get_full_name(), }) else: return render( request, "submit.html", { "success": False, "title": "發送卡片失敗", "content": "要不要去戳戳系統管理員呢?" "(如果是POST奇怪的資料,可能會收到彈力繩喔ˊ_>ˋ)" })
def gift(request): if user_permission(request.user) < 3: raise PermissionDenied if request.method == 'GET': return render(request, 'staff/gift.html', {"form": FastSendForm()}) else: form = FastSendForm(request.POST) if form.is_valid(): player = form.cleaned_data['player'] card = Card() # hard code present = request.user.first_name if present == "": present = '祝福' with transaction.atomic(): card.name = "來自 %s 的%s" % (request.user.last_name, present) card.value = form.cleaned_data['point'] card.comment = form.cleaned_data['message'] card.active = True card.retrieved = True card.issuer = request.user card.capturer = player card.save() record_reciever = History( action=0xfeed, user=player.user, card=card, comment="從 %s 收到一張卡片" % request.user.get_full_name()) record_reciever.save() record_sender = History( action=0xfeed, user=request.user, card=card, comment="給了 %s (%s)" % (player.user.get_full_name(), player.user.username)) record_sender.save() return render( request, "submit.html", { "success": True, "title": "成功發送卡片", "content": "成功將卡片送給 %s 了!" % player.user.get_full_name(), }) else: return render( request, "submit.html", { "success": False, "title": "發送卡片失敗", "content": "要不要去戳戳系統管理員呢?" "(如果是POST奇怪的資料,可能會收到彈力繩喔ˊ_>ˋ)" })
def gift(request): if request.method == 'GET': return render(request, 'staff/gift.html', {"form": FastSendForm()}) else: form = FastSendForm(request.POST) if form.is_valid(): player = form.cleaned_data['player'] card = Card() card.name = "來自 %s 的祝福" % request.user.get_full_name() card.value = form.cleaned_data['point'] card.comment = form.cleaned_data['message'] card.active = True card.retrieved = True card.issuer = request.user card.capturer = player card.save() record_reciever = History(action=0xfeed, user=player.user, card=card, comment="從 %s 收到一張卡片" % request.user.get_full_name()) record_reciever.save() record_sender = History( action=0xfeed, user=request.user, card=card, comment="給了 %s (%s)" % (player.user.get_full_name(), player.user.username)) record_sender.save() return render( request, "submit.html", { "success": True, "title": "成功發送卡片", "content": "成功將卡片送給 %s 了!" % player.user.get_full_name(), }) else: return render(request, "submit.html", { "success": False, "title": "發送卡片失敗", "content": "要不要去戳戳系統管理員呢?" })
def gift(request): if request.method == 'GET': return render(request, 'staff/gift.html', {"form": FastSendForm()}) else: form = FastSendForm(request.POST) if form.is_valid(): player = form.cleaned_data['player'] card = Card() card.name = "來自 %s 的祝福" % request.user.get_full_name() card.value = form.cleaned_data['point'] card.comment = form.cleaned_data['message'] card.active = True card.retrieved = True card.issuer = request.user card.capturer = player card.save() record_reciever = History( action=0xfeed, user=player.user, card=card, comment="從 %s 收到一張卡片" % request.user.get_full_name()) record_reciever.save() record_sender = History( action=0xfeed, user=request.user, card=card, comment="給了 %s (%s)" % (player.user.get_full_name(), player.user.username)) record_sender.save() return render( request, "submit.html", { "success": True, "title": "成功發送卡片", "content": "成功將卡片送給 %s 了!" % player.user.get_full_name(), }) else: return render( request, "submit.html", { "success": False, "title": "發送卡片失敗", "content": "要不要去戳戳系統管理員呢?" })