本文整理汇总了Python中models.Group.token方法的典型用法代码示例。如果您正苦于以下问题:Python Group.token方法的具体用法?Python Group.token怎么用?Python Group.token使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Group
的用法示例。
在下文中一共展示了Group.token方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Upload
# 需要导入模块: from models import Group [as 别名]
# 或者: from models.Group import token [as 别名]
def Upload(request):
if request.method != "POST":
raise Http404
if not request.FILES:
if "cliptext" not in request.POST:
raise Http404
token = utils.gentoken()
while os.path.isdir("/var/www/synchy.org/main/synchy-django/media/%s" % token):
token = utils.gentoken()
os.mkdir("/var/www/synchy.org/main/synchy-django/media/%s" % token)
os.mkdir("/var/www/synchy.org/main/synchy-django/media/%s/files" % token)
if not request.FILES:
if 'cliptext' in request.POST:
group = Group()
group.token = token
group.multi = False
group.save()
file = File()
file.group = group
file.name = "clipboard.txt"
file.mime = "text/plain"
file.save()
data = request.POST['cliptext']
handle = open("/var/www/synchy.org/main/synchy-django/media/%s/files/%s" % (token, file.name), 'w+')
handle.write(data)
handle.close()
else:
os.rmdir("/var/www/synchy.org/main/synchy-django/media/%s/files" % token)
os.rmdir("/var/www/synchy.org/main/synchy-django/media/%s" % token)
return Http404
else:
if len(request.FILES) != 1:
os.rmdir("/var/www/synchy.org/main/synchy-django/media/%s/files" % token)
os.rmdir("/var/www/synchy.org/main/synchy-django/media/%s" % token)
raise Http404
else:
if 'file' in request.FILES:
group = Group()
group.token = token
group.multi = False
group.save()
file = File()
file.group = group
file.name = request.FILES['file'].name
file.mime = request.FILES['file'].content_type
file.save()
data = request.FILES['file'].read()
handle = open("/var/www/synchy.org/main/synchy-django/media/%s/files/%s" % (token, file.name), 'w+')
handle.write(data)
handle.close()
elif 'zip' in request.FILES:
group = Group()
group.token = token
group.multi = True
group.save()
if request.FILES['zip'].content_type != "application/octet-stream":
os.rmdir("/var/www/synchy.org/main/synchy-django/media/%s/files" % token)
os.rmdir("/var/www/synchy.org/main/synchy-django/media/%s" % token)
raise Http404
data = request.FILES['zip'].read()
handle = open("/var/www/synchy.org/main/synchy-django/media/%s/%s%s%s%s" % (token, "files-", token[:2], token[-2:], ".zip"), 'w+')
handle.write(data)
handle.close()
os.system('cd "%s/var/www/synchy.org/main/synchy-django/media/%s/files/"; sudo jar -xf %s/var/www/synchy.org/main/synchy-django/media/%s/files-%s%s.zip' % (os.getcwd(), token, os.getcwd(), token, token[:2], token[-2:]))
zfile = Zip()
zfile.group = group
zfile.name = "%s%s%s%s" % ("files-", token[:2], token[-2:], ".zip")
zfile.save()
mime = magic.Magic(mime=True)
for name in os.listdir("/var/www/synchy.org/main/synchy-django/media/%s/files/" % token):
file = File()
file.group = group
file.name = name
file.mime = mime.from_file("/var/www/synchy.org/main/synchy-django/media/%s/files/%s" % (token, name))
file.save()
else:
os.rmdir("/var/www/synchy.org/main/synchy-django/media/%s/files" % token)
os.rmdir("/var/www/synchy.org/main/synchy-django/media/%s" % token)
raise Http404
return HttpResponse(token)