本文整理汇总了Python中models.File.filename方法的典型用法代码示例。如果您正苦于以下问题:Python File.filename方法的具体用法?Python File.filename怎么用?Python File.filename使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.File
的用法示例。
在下文中一共展示了File.filename方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: upload
# 需要导入模块: from models import File [as 别名]
# 或者: from models.File import filename [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))
示例2: upload
# 需要导入模块: from models import File [as 别名]
# 或者: from models.File import filename [as 别名]
def upload(request, name):
if request.method == 'POST':
if request.FILES is None:
return HttpResponseBadRequest('No file[] found')
file = request.FILES[u'files[]']
wrapped_file = UploadedFile(file)
filename = wrapped_file.name
file_size = wrapped_file.file.size
entry = File()
entry.filename = unicode(filename)
entry.username = unicode(name)
entry.size = file_size
entry.slug = generate_slug(8)
entry.data = file
entry.save()
uploaded = [{'name': filename, 'size': filesizeformat(file_size), 'slug': entry.slug,
'date': entry.created.date().isoformat()}]
return HttpResponse(json.dumps({'files': uploaded}))
else:
raise Http404
示例3: multiuploader
# 需要导入模块: from models import File [as 别名]
# 或者: from models.File import filename [as 别名]
def multiuploader(request):
"""
Main Multiuploader module.
Parses data from jQuery plugin and makes database changes.
"""
if request.method == 'POST':
log.info('received POST to main multiuploader view')
if request.FILES == None:
return HttpResponseBadRequest('Must have files attached!')
#getting file data for farther manipulations
file = request.FILES[u'files[]']
wrapped_file = UploadedFile(file)
filename = wrapped_file.name
file_size = wrapped_file.file.size
log.info ('Got file: "%s"' % filename)
#writing file manually into model
#because we don't need form of any type.
image = File()
image.filename= filename
image.image=file
image.key_data = image.key_generate
image.save()
log.info('File saving done')
#settings imports
try:
file_delete_url = settings.MULTI_FILE_DELETE_URL+'/'
# file_url = settings.MULTI_IMAGE_URL+'/'+image.key_data+'/'
except AttributeError:
file_delete_url = 'multi_delete/'
# file_url = 'multi_image/'+image.key_data+'/'
file_url = image.image.url;
#generating json response array
result = []
context = {"name":filename,
"size":file_size,
"url":file_url,
"file_id": image.id,
"delete_url":file_delete_url+str(image.pk)+'/',
"delete_type":"POST",
}
#getting thumbnail url using sorl-thumbnail
print image.is_image
if image.is_image:
im = get_thumbnail(image, "80x80", quality=50)
context['thumbnail_url'] = im.url
result.append(context)
response_data = simplejson.dumps(result)
#checking for json data type
#big thanks to Guy Shapiro
if "application/json" in request.META['HTTP_ACCEPT_ENCODING']:
mimetype = 'application/json'
else:
mimetype = 'text/plain'
return HttpResponse(response_data, mimetype=mimetype)
else: #GET
return HttpResponse('Only POST accepted')