本文整理匯總了Python中pyxform.xls2json.SurveyReader.get方法的典型用法代碼示例。如果您正苦於以下問題:Python SurveyReader.get方法的具體用法?Python SurveyReader.get怎麽用?Python SurveyReader.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pyxform.xls2json.SurveyReader
的用法示例。
在下文中一共展示了SurveyReader.get方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: edit_repo
# 需要導入模塊: from pyxform.xls2json import SurveyReader [as 別名]
# 或者: from pyxform.xls2json.SurveyReader import get [as 別名]
def edit_repo( request, repo_id ):
"""
Edits a data repository
Takes user to Form Builder
"""
repo = get_object_or_404( Repository, mongo_id=repo_id )
# Check that this user has permission to edit this repo
if not request.user.has_perm( 'delete_repository', repo ):
return HttpResponse( 'Unauthorized', status=401 )
if request.method == 'POST':
form = NewRepoForm( request.POST, request.FILES, user=request.user )
#print form.cleaned_data
repo.name = request.POST['name'].replace( ' ','_' )
repo.description = request.POST['desc']
repo.save()
data = request.FILES[ 'xform_file' ]
# Split apart the file name so we can attempt to detect the file type
name, file_ext = os.path.splitext( data.name )
file_ext = file_ext[1:].lower()
if not settings.DEBUG and not settings.TESTING:
storage.bucket_name = settings.AWS_TASK_STORAGE_BUCKET_NAME
s3_url = '%s.%s' % ( repo.mongo_id, file_ext )
storage.save( s3_url, data )
xform = storage.open( s3_url, 'r' )
fields = SurveyReader( xform )
fields = fields.to_json_dict()
repo.update_fields( fields.get( 'children' ) )
#data_repo = db.repo.find_one( ObjectId( repo_id ) )
#newJSON = json.loads( request.POST['survey_json'].strip() )
#newfields = newJSON['children']
#formType = newJSON['type']
#db.repo.update( {"_id":ObjectId( repo_id )},{"$set": {'fields': newfields, 'type': formType}} )
return HttpResponseRedirect( '/' )
else:
form = NewRepoForm()
form.initial["name"] = repo.name
form.initial["desc"] = repo.description
user_repos = Repository.objects.filter( user=request.user, org=None )
repos = []
for temp_repo in user_repos:
#I want a flat list of repo fields
repo_info = {
'name': temp_repo.name,
'mongo_id': temp_repo.mongo_id,
'children': temp_repo.fields() }
repos.append( repo_info )
data_repo = db.repo.find_one( ObjectId( repo_id ) )
temp_dict = {}
temp_dict['children'] = data_repo['fields']
if 'type' in data_repo:
temp_dict['type'] = data_repo['type']
else:
temp_dict['type'] = "survey"
return render_to_response( 'new.html',
{'form': form,
'repo_json': json.dumps(temp_dict),
'user_repos': repos },
context_instance=RequestContext(request) )