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


Python UploadForm.save方法代码示例

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


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

示例1: confirm_upload

# 需要导入模块: from forms import UploadForm [as 别名]
# 或者: from forms.UploadForm import save [as 别名]
def confirm_upload(request):
    USER_NAME = request.user.username
    fileName = str((request.FILES['upload_file']).name)
    FILE_DIR = os.path.join(BASE_DIR, 'media/user/'+USER_NAME+"/"+'temporary_files/')+fileName
    print type(request.FILES['upload_file'])
    print pandas.read_csv(request.FILES['upload_file'])

    if os.path.exists(FILE_DIR):
        os.remove(FILE_DIR)

    if request.method == 'POST':
        form = UploadForm(request.POST, request.FILES)
        if form.is_valid():
            form.save()
            args = {}
            args.update(csrf(request))
            if 'datavalue' in fileName :
                importType = 'datavalues'
            elif 'site' in fileName:
                importType = 'sites'
            elif 'method' in fileName:
                importType = 'methods'
            elif 'source' in fileName:
                importType = 'sources'
            elif 'variable' in fileName:
                importType = 'variables'
            args['fileName'] = fileName
            return render_to_response('import_'+importType+'.html',args)
    else:
        form = UploadForm()
    args = {}
    args['filename'] = filename
    args.update(csrf(request))
    args['form'] = form

    return render_to_response('uploadfile.html',args,context_instance=RequestContext(request))
开发者ID:mth2610,项目名称:ewatec,代码行数:38,代码来源:views.py

示例2: confirm_upload

# 需要导入模块: from forms import UploadForm [as 别名]
# 或者: from forms.UploadForm import save [as 别名]
def confirm_upload(request):
    USER_NAME = request.user.username
    FILE_DIR = os.path.join(BASE_DIR, 'media/user/'+USER_NAME+"/"+'temporary_files/')+str((request.FILES['upload_file']).name)
    
    if os.path.exists(FILE_DIR):
        os.remove(FILE_DIR)

    if request.method == 'POST':
        form = UploadForm(request.POST, request.FILES)
        if form.is_valid():
            form.save()
            args = {}
            args.update(csrf(request))
            filename = ((request.FILES['upload_file']).name).replace(".csv","")
            return render_to_response('import_'+filename+'.html',args)
    else:
        form = UploadForm()
    args = {}
    args.update(csrf(request))
    args['form'] = form
    
    filename = (request.FILES['filename']).name
    
    return render_to_response('uploadfile.html',args,context_instance=RequestContext(request))
开发者ID:mth2610,项目名称:ewatec_web,代码行数:26,代码来源:views.py

示例3: upload

# 需要导入模块: from forms import UploadForm [as 别名]
# 或者: from forms.UploadForm import save [as 别名]
def upload(request):
	'''
	Default view for the homepage.  Handles all public image submissions
	'''
	
	# variables passed to template
	context = {}
	
	if request.method == 'GET':
		'''
		Homepage.  Inital form.
		Step 1 - user chooses a picture to upload
		user proceeds through steps with POST requests
		'''
		form = UploadForm()
		form.fields['step'] = forms.CharField(widget=forms.HiddenInput(), initial="upload")
		context['form'] = form
		context['step'] = 'steps/upload.djt'
		request.session.clear() # clear submission cache, starting new submission process
	
	elif request.method == 'POST' and request.POST:
		
		if request.POST['step'] == "upload":
			''' 
			Step 2
			verfiy upload form
			if valid proceed to inspect then details form
			'''
			form = UploadForm(request.POST, request.FILES)
			form.fields['step'] = forms.CharField(widget=forms.HiddenInput(), initial="upload")
			if not form.is_valid():
				messages.error(request, 'Form data was invalid')
				context['form'] = form
				context['step'] = 'steps/upload.djt'
			else:
				# save and return details form
				submission = form.save()
				submission.generate_thumbnail()
				submission.auto_fill()
				submission.complete = False
				submission.save()
				request.session['submission_id'] = submission.id
				form = DetailsForm(instance=submission)
				form.fields['step'] = forms.CharField(widget=forms.HiddenInput(), initial="details")
				context['form'] = form
				context['submission'] = submission
				context['step'] = 'steps/details.djt'

		if request.POST['step'] == "details":
			'''
			Step 3
			complete photo submission
			'''
			submission_id = request.session.get('submission_id', None)
			try:
				submission = Submission.objects.get(pk=submission_id)
			except Submission.DoesNotExist:
				# only should happen if session was somehow destroyed
				return redirect('home')
			
			form = DetailsForm(request.POST, instance=submission)
			if not form.is_valid():
				form.fields['step'] = forms.CharField(widget=forms.HiddenInput(), initial="details")
				context['form'] = form
				context['submission'] = submission
				context['step'] = 'steps/details.djt'
			else:
				# all done
				submission = form.save()
				submission.complete = True
				submission.save()
				context['submission'] = submission
				context['step'] = 'steps/complete.djt'
	else:
		# major dog balls
		messages.error(request, 'Logic Error');
		
	
	# progress bar
	import uuid
	context["uuid"] = uuid.uuid1()
	
	
	response = render_to_response(request, 'home.djt', context)
	response.set_cookie('X-Progress-ID', value=context["uuid"])
	
	return response
开发者ID:UCF,项目名称:Photo-Submissions,代码行数:89,代码来源:views.py

示例4: user_bio

# 需要导入模块: from forms import UploadForm [as 别名]
# 或者: from forms.UploadForm import save [as 别名]
def user_bio(request):
  """
  'my_account' view used to handle avatar image upload
  and routing and templating of users account
  Args: None
  Returns:
      form for avatar upload
  """
  email = request.user.email

  if request.method == 'POST':
    imageupload = UploadForm(request.POST, request.FILES)
    
    if imageupload.is_valid():

      u = imageupload.save(commit=False)
      #image upload to google cloud storage
      uploaded_file = request.FILES['image']
      content_type = request.FILES['image'].content_type
      name = request.FILES['image'].name
      
      data = uploaded_file.read()  
      gcs_file = gcs.open(
                             ('/' + bucket_name + '/' + name),
                             mode = 'w',
                             content_type = 'image/jpeg',
                             options = {
                               'x-goog-acl': 'bucket-owner-full-control'
                             }
                         )
      gcs_file.write(data)
      gcs_file.close()

      #get_serving_url from google and stats
      #avatar = gcs.open('/' + bucket_name + '/' + name)
      blob_key = blobstore.create_gs_key(
                                          '/gs/' + bucket_name + '/' + name
                                        )
      serving_url = get_serving_url(blob_key)
      
      #find existing avatar image
      try:
        u = Upload.objects.get(email = email, is_avatar = True)
      except Upload.DoesNotExist:
        u = False

      #set is_avatar to False but keep entry in db
      if u:
        u.is_avatar = False
        u.save()

      #insert the uploaded avatar
      u = Upload(url = serving_url, email = email, is_avatar = True)
      u.save() 
      stats = gcs.stat('/' + bucket_name + '/' + name)
    
      return HttpResponseRedirect('/my_account/')

  else:
    form = UploadForm()
    gallery_form = GalleryForm()

    try:
      u = Upload.objects.get(email = email, is_avatar = True)
      serving_url = u.url
    except Upload.DoesNotExist:
      serving_url = '/static/bio/blank.png'
      
  return render_to_response(
                               'profile.html',
                               {
                                   'form': form,
                                   'gallery_form': gallery_form,
                                   'serving_url': serving_url,
                                   'user': email,
                               },
                               context_instance = RequestContext(request)
                           )
开发者ID:mrjd26,项目名称:bio,代码行数:80,代码来源:views.py


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