本文整理汇总了Python中models.File.file方法的典型用法代码示例。如果您正苦于以下问题:Python File.file方法的具体用法?Python File.file怎么用?Python File.file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.File
的用法示例。
在下文中一共展示了File.file方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from models import File [as 别名]
# 或者: from models.File import file [as 别名]
def post(self):
fil = self.request.POST["file"]
if not fil.value:
self.redirect("/")
return
logging.getLogger().info("selected val %s" % self.request.POST["compression-type"])
if self.request.POST["compression-type"] == "NONE":
data = fil.value
else:
params = urllib.urlencode(
[
("js_code", fil.value),
("compilation_level", self.request.POST["compression-type"]),
("output_format", "text"),
("output_info", "compiled_code"),
]
)
headers = {"Content-type": "application/x-www-form-urlencoded"}
conn = httplib.HTTPConnection("closure-compiler.appspot.com")
conn.request("POST", "/compile", params, headers)
response = conn.getresponse()
data = response.read()
conn.close
file = File()
file.name = fil.filename
file.file = db.Blob(data)
file.content_type = fil.type
file.user = users.get_current_user()
file.put()
self.redirect("/")
示例2: upload
# 需要导入模块: from models import File [as 别名]
# 或者: from models.File import file [as 别名]
def upload(request):
if request.POST:
userid = request.POST.get('userid')
# Queries all non-expired sessions
sessions = Session.objects.filter(expire_date__gte=datetime.now())
# Checks if session is active
for session in sessions:
data = session.get_decoded()
found_userid=data.get('_auth_user_id')
# Prceeds when user id is validated
if found_userid!=None and long(userid)==found_userid:
user = User.objects.filter(id=userid)[0]
faculty=None
faculty=Faculty.objects.filter(id=request.POST.get('fid'))[0]
transaction = Transaction.objects.get(id=request.POST.get('transaction'))
document = Dokument()
document.faculty= faculty
document.transaction= transaction
document.save()
#Generates a random alphanum string for filename template
while True:
fnameTemplate=''
fnameTemplate = ''.join(random.choice(string.ascii_lowercase))
fnameTemplate += ''.join(random.choice(string.ascii_lowercase + string.digits) for x in range(4)) + '_'
if len(File.objects.filter(filename__startswith = fnameTemplate))==0: break
#Processes uploaded files, page by page
for key in request.FILES:
files = request.FILES[key]
filename = fnameTemplate + key.split('_')[1] + '.bmp'
with open('DCSArchivingSystem/testapp/media/files/' + filename, 'wb+') as destination:
for chunk in files.chunks():
destination.write(chunk)
file = File()
file.filename = filename
file.file = 'files/' + filename
file.save()
document.files.add(file)
Log.create(user, "Uploaded file", file, document).save()
Log.create(user, "Created Document", None, document).save()
return HttpResponseRedirect("/dashboard/")
else:
return render_to_response('upload.html', context_instance=RequestContext(request))