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


Python File.group方法代码示例

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


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

示例1: Upload

# 需要导入模块: from models import File [as 别名]
# 或者: from models.File import group [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)
开发者ID:WilHall,项目名称:synchy-django,代码行数:94,代码来源:views.py


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