本文整理汇总了Python中models.Match.image方法的典型用法代码示例。如果您正苦于以下问题:Python Match.image方法的具体用法?Python Match.image怎么用?Python Match.image使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Match
的用法示例。
在下文中一共展示了Match.image方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: submit_make
# 需要导入模块: from models import Match [as 别名]
# 或者: from models.Match import image [as 别名]
def submit_make(request):
if os.environ.get("TEST", None):
request.session["userId"] = request.GET["userId"]
try:
userId = request.POST["userId"]
user = User.objects.get(openId=userId)
now = basic_tools.getNow()
match = Match(title=request.POST["match_name"],description=request.POST["comment"],createTime=now,startTime=basic_tools.DateToInt("%s:00:00" % request.POST["begintime"][:13]),endTime=basic_tools.DateToInt("%s:00:00" % request.POST["endtime"][:13]),creator=user)
match.save()
tags = []
tag = request.POST["tags"]
if not tag == "":
item = MTag.objects.filter(name=tag)
if len(item) == 0:
item = MTag(name=tag)
item.save()
else:
item = item[0]
if not item.matchs.filter(id=match.id).exists():
tags.append(tag)
item.matchs.add(match)
i = 0
while ("tag%d" % i) in request.POST:
tag = request.POST["tag%d" % i]
i += 1
if not tag == "":
item = MTag.objects.filter(name=tag)
if len(item) == 0:
item = MTag(name=tag)
item.save()
else:
item = item[0]
if not item.matchs.filter(id=match.id).exists():
tags.append(tag)
item.matchs.add(match)
match.user_members.add(user)
team = user.user_team_members.get(type=0)
match.members.add(team)
prefix = os.environ.get("WRIST_HOME")
path = "/media/match/"
if not os.path.exists(prefix+path):
os.mkdir(prefix+path)
if "image" in request.FILES:
file = request.FILES["image"]
file_name = "%s%s_%s_%s" % (path, match.title.encode("utf-8"), str(now), file.name.encode("utf-8"))
des = open(prefix+file_name, "wb")
for chunk in file.chunks():
des.write(chunk)
des.close()
else:
file_name = tools.getDefaultImageByTag(tags)
match.image = file_name
match.save()
i = 0
while ("friend%d" % i) in request.POST:
tools.sendInvite(user, plan.id, request.POST["friend%d" % i], 0)
i += 1
i = 0
while ("opponent%d" % i) in request.POST:
tools.sendInvite(user, plan.id, request.POST["opponent%d" % i], 1)
i += 1
return HttpResponseRedirect("/match/redirect/profile?page=3&id=%d" % match.id)
except:
return HttpResponse("/static/404.html")