Re: [google-appengine] how to upload a csv file, parse it, and save in the data model

2010-11-01 Thread djidjadji
You forgot the enctype attribute of the form tag

form name=uploadform enctype=multipart/form-data

2010/10/31 He Jibo hej...@gmail.com:
 Hi, Can someone teach me how to parse a file uploaded to GAE?

 I am writing a feature that users can upload a .csv file, and save
 data into the data model. I have already implemented the uploading,
 see the link below:
 http://gae-hejibo.appspot.com/TestUpload
 But I do not know how to parse it, and save in my data model. Below is
 my html and processing code. I can upload a csv file, but the data in
 the csv is not saved into the data model. Can someone teach me what's
 wrong with my code, and how should I do? Thanks!

 --html file code
 form name=uploadform
      div
          /pCSV File(Comma Separated Value) File*: /p
          input type=file
 name=uploadfilename/
      input type=submit value=Upload/div
 /form


 --processing code
 class TestUpload(webapp.RequestHandler):
    '''add item using .csv file'''
    def get(self):
        path =
 os.path.join(os.path.dirname(__file__),'template','TestUpload.html')
        self.response.out.write(template.render(path, {}))
    def post(self):
        fileReader = open(self.request.get('uploadfilename'))
        csv_file=self.request.get('uploadfilename')
        fileReader = csv.reader(csv_file.split(\n))


        for row in fileReader:
            cell = row.split('\t')

            fourchoice = FourChoices()
            fourchoice.description = cell[0]
            fourchoice.choiceA = cell[1]
            fourchoice.choiceB = cell[2]
            fourchoice.choiceC = cell[3]
            fourchoice.choiceD = cell[4]
            fourchoice.a = cell[5]
            fourchoice.b = cell[6]
            fourchoice.c = cell[7]
            fourchoice.answer = cell[8]
            fourchoice.put()
        path =
 os.path.join(os.path.dirname(__file__),'template','debug.html')
        self.response.out.write(template.render(path,
 {'description':'fileupload'}))

 --
 You received this message because you are subscribed to the Google Groups 
 Google App Engine group.
 To post to this group, send email to google-appeng...@googlegroups.com.
 To unsubscribe from this group, send email to 
 google-appengine+unsubscr...@googlegroups.com.
 For more options, visit this group at 
 http://groups.google.com/group/google-appengine?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Google App Engine group.
To post to this group, send email to google-appeng...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.



[google-appengine] how to upload a csv file, parse it, and save in the data model

2010-10-31 Thread He Jibo
Hi, Can someone teach me how to parse a file uploaded to GAE?

I am writing a feature that users can upload a .csv file, and save
data into the data model. I have already implemented the uploading,
see the link below:
http://gae-hejibo.appspot.com/TestUpload
But I do not know how to parse it, and save in my data model. Below is
my html and processing code. I can upload a csv file, but the data in
the csv is not saved into the data model. Can someone teach me what's
wrong with my code, and how should I do? Thanks!

--html file code
form name=uploadform
  div
  /pCSV File(Comma Separated Value) File*: /p
  input type=file
name=uploadfilename/
  input type=submit value=Upload/div
/form


--processing code
class TestUpload(webapp.RequestHandler):
'''add item using .csv file'''
def get(self):
path =
os.path.join(os.path.dirname(__file__),'template','TestUpload.html')
self.response.out.write(template.render(path, {}))
def post(self):
fileReader = open(self.request.get('uploadfilename'))
csv_file=self.request.get('uploadfilename')
fileReader = csv.reader(csv_file.split(\n))


for row in fileReader:
cell = row.split('\t')

fourchoice = FourChoices()
fourchoice.description = cell[0]
fourchoice.choiceA = cell[1]
fourchoice.choiceB = cell[2]
fourchoice.choiceC = cell[3]
fourchoice.choiceD = cell[4]
fourchoice.a = cell[5]
fourchoice.b = cell[6]
fourchoice.c = cell[7]
fourchoice.answer = cell[8]
fourchoice.put()
path =
os.path.join(os.path.dirname(__file__),'template','debug.html')
self.response.out.write(template.render(path,
{'description':'fileupload'}))

-- 
You received this message because you are subscribed to the Google Groups 
Google App Engine group.
To post to this group, send email to google-appeng...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.



Re: [google-appengine] how to upload a csv file, parse it, and save in the data model

2010-10-31 Thread Jeff Schwartz
I am not a Python person but you said the file was 'comma' separated yet it
looks like (again, I am not a Python person) you are using tab instead of
comma to split your input.

On Sun, Oct 31, 2010 at 2:29 PM, He Jibo hej...@gmail.com wrote:

 Hi, Can someone teach me how to parse a file uploaded to GAE?

 I am writing a feature that users can upload a .csv file, and save
 data into the data model. I have already implemented the uploading,
 see the link below:
 http://gae-hejibo.appspot.com/TestUpload
 But I do not know how to parse it, and save in my data model. Below is
 my html and processing code. I can upload a csv file, but the data in
 the csv is not saved into the data model. Can someone teach me what's
 wrong with my code, and how should I do? Thanks!

 --html file code
 form name=uploadform
  div
  /pCSV File(Comma Separated Value) File*: /p
  input type=file
 name=uploadfilename/
  input type=submit value=Upload/div
 /form


 --processing code
 class TestUpload(webapp.RequestHandler):
'''add item using .csv file'''
def get(self):
path =
 os.path.join(os.path.dirname(__file__),'template','TestUpload.html')
self.response.out.write(template.render(path, {}))
def post(self):
fileReader = open(self.request.get('uploadfilename'))
csv_file=self.request.get('uploadfilename')
fileReader = csv.reader(csv_file.split(\n))


for row in fileReader:
cell = row.split('\t')

fourchoice = FourChoices()
fourchoice.description = cell[0]
fourchoice.choiceA = cell[1]
fourchoice.choiceB = cell[2]
fourchoice.choiceC = cell[3]
fourchoice.choiceD = cell[4]
fourchoice.a = cell[5]
fourchoice.b = cell[6]
fourchoice.c = cell[7]
fourchoice.answer = cell[8]
fourchoice.put()
path =
 os.path.join(os.path.dirname(__file__),'template','debug.html')
self.response.out.write(template.render(path,
 {'description':'fileupload'}))

 --
 You received this message because you are subscribed to the Google Groups
 Google App Engine group.
 To post to this group, send email to google-appeng...@googlegroups.com.
 To unsubscribe from this group, send email to
 google-appengine+unsubscr...@googlegroups.comgoogle-appengine%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/google-appengine?hl=en.




-- 
Jeff

-- 
You received this message because you are subscribed to the Google Groups 
Google App Engine group.
To post to this group, send email to google-appeng...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.



Re: [google-appengine] how to upload a csv file, parse it, and save in the data model

2010-10-31 Thread He Jibo
Thanks for your quick response. The '\t' is a problem, but I think it is not
a reason why the code does not work. Even if I do the following code,
without any code for csv, it does direct my to debug.html after file upload.
It seems the page is not posted file I clicked 'upload' in the page at

http://gae-hejibo.appspot.com/TestUpload


class TestUpload(webapp.RequestHandler):

'''add item using .csv file'''

def get(self):

path = os.path.join(os.path.dirname(__file__),'template','TestUpload.html')

self.response.out.write(template.render(path, {}))

def post(self):

 path = os.path.join(os.path.dirname(__file__),'template','debug.html')

self.response.out.write(template.render(path,{'description':'fileupload'}))


---
He Jibo
Department of Psychology,
Beckman Institute for Advanced Science and Technology
University of Illinois, Urbana Champaign,
603 East Daniel St.,
Champaign, IL 61820
website: www.hejibo.info



On Sun, Oct 31, 2010 at 1:43 PM, Jeff Schwartz jefftschwa...@gmail.comwrote:

 I am not a Python person but you said the file was 'comma' separated yet it
 looks like (again, I am not a Python person) you are using tab instead of
 comma to split your input.

 On Sun, Oct 31, 2010 at 2:29 PM, He Jibo hej...@gmail.com wrote:

 Hi, Can someone teach me how to parse a file uploaded to GAE?

 I am writing a feature that users can upload a .csv file, and save
 data into the data model. I have already implemented the uploading,
 see the link below:
 http://gae-hejibo.appspot.com/TestUpload
 But I do not know how to parse it, and save in my data model. Below is
 my html and processing code. I can upload a csv file, but the data in
 the csv is not saved into the data model. Can someone teach me what's
 wrong with my code, and how should I do? Thanks!

 --html file code
 form name=uploadform
  div
  /pCSV File(Comma Separated Value) File*: /p
  input type=file
 name=uploadfilename/
  input type=submit value=Upload/div
 /form


 --processing code
 class TestUpload(webapp.RequestHandler):
'''add item using .csv file'''
def get(self):
path =
 os.path.join(os.path.dirname(__file__),'template','TestUpload.html')
self.response.out.write(template.render(path, {}))
def post(self):
fileReader = open(self.request.get('uploadfilename'))
csv_file=self.request.get('uploadfilename')
fileReader = csv.reader(csv_file.split(\n))


for row in fileReader:
cell = row.split('\t')

fourchoice = FourChoices()
fourchoice.description = cell[0]
fourchoice.choiceA = cell[1]
fourchoice.choiceB = cell[2]
fourchoice.choiceC = cell[3]
fourchoice.choiceD = cell[4]
fourchoice.a = cell[5]
fourchoice.b = cell[6]
fourchoice.c = cell[7]
fourchoice.answer = cell[8]
fourchoice.put()
path =
 os.path.join(os.path.dirname(__file__),'template','debug.html')
self.response.out.write(template.render(path,
 {'description':'fileupload'}))

 --
 You received this message because you are subscribed to the Google Groups
 Google App Engine group.
 To post to this group, send email to google-appeng...@googlegroups.com.
 To unsubscribe from this group, send email to
 google-appengine+unsubscr...@googlegroups.comgoogle-appengine%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/google-appengine?hl=en.




 --
 Jeff

 --
 You received this message because you are subscribed to the Google Groups
 Google App Engine group.
 To post to this group, send email to google-appeng...@googlegroups.com.
 To unsubscribe from this group, send email to
 google-appengine+unsubscr...@googlegroups.comgoogle-appengine%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/google-appengine?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Google App Engine group.
To post to this group, send email to google-appeng...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.



Re: [google-appengine] how to upload a csv file, parse it, and save in the data model

2010-10-31 Thread Jeff Schwartz
Like I said, I am not a Python person though I find Python quite easy to
read so perhaps a real Python person can help you with your request.
Certainly, though, splitting your input on tab when it was comma separated
would have presented an issue so I am glad I could offer you some help.

Good luck.

Jeff

On Sun, Oct 31, 2010 at 2:54 PM, He Jibo hej...@gmail.com wrote:

  Thanks for your quick response. The '\t' is a problem, but I think it is
 not a reason why the code does not work. Even if I do the following code,
 without any code for csv, it does direct my to debug.html after file upload.
 It seems the page is not posted file I clicked 'upload' in the page at

 http://gae-hejibo.appspot.com/TestUpload


 class TestUpload(webapp.RequestHandler):

 '''add item using .csv file'''

 def get(self):

 path = os.path.join(os.path.dirname(__file__),'template','TestUpload.html')

 self.response.out.write(template.render(path, {}))

 def post(self):

  path = os.path.join(os.path.dirname(__file__),'template','debug.html')

 self.response.out.write(template.render(path,{'description':'fileupload'}))



 ---
 He Jibo
 Department of Psychology,
 Beckman Institute for Advanced Science and Technology
 University of Illinois, Urbana Champaign,
 603 East Daniel St.,
 Champaign, IL 61820
 website: www.hejibo.info



 On Sun, Oct 31, 2010 at 1:43 PM, Jeff Schwartz jefftschwa...@gmail.comwrote:

 I am not a Python person but you said the file was 'comma' separated yet
 it looks like (again, I am not a Python person) you are using tab instead of
 comma to split your input.

 On Sun, Oct 31, 2010 at 2:29 PM, He Jibo hej...@gmail.com wrote:

 Hi, Can someone teach me how to parse a file uploaded to GAE?

 I am writing a feature that users can upload a .csv file, and save
 data into the data model. I have already implemented the uploading,
 see the link below:
 http://gae-hejibo.appspot.com/TestUpload
 But I do not know how to parse it, and save in my data model. Below is
 my html and processing code. I can upload a csv file, but the data in
 the csv is not saved into the data model. Can someone teach me what's
 wrong with my code, and how should I do? Thanks!

 --html file code
 form name=uploadform
  div
  /pCSV File(Comma Separated Value) File*: /p
  input type=file
 name=uploadfilename/
  input type=submit value=Upload/div
 /form


 --processing code
 class TestUpload(webapp.RequestHandler):
'''add item using .csv file'''
def get(self):
path =
 os.path.join(os.path.dirname(__file__),'template','TestUpload.html')
self.response.out.write(template.render(path, {}))
def post(self):
fileReader = open(self.request.get('uploadfilename'))
csv_file=self.request.get('uploadfilename')
fileReader = csv.reader(csv_file.split(\n))


for row in fileReader:
cell = row.split('\t')

fourchoice = FourChoices()
fourchoice.description = cell[0]
fourchoice.choiceA = cell[1]
fourchoice.choiceB = cell[2]
fourchoice.choiceC = cell[3]
fourchoice.choiceD = cell[4]
fourchoice.a = cell[5]
fourchoice.b = cell[6]
fourchoice.c = cell[7]
fourchoice.answer = cell[8]
fourchoice.put()
path =
 os.path.join(os.path.dirname(__file__),'template','debug.html')
self.response.out.write(template.render(path,
 {'description':'fileupload'}))

 --
 You received this message because you are subscribed to the Google Groups
 Google App Engine group.
 To post to this group, send email to google-appeng...@googlegroups.com.
 To unsubscribe from this group, send email to
 google-appengine+unsubscr...@googlegroups.comgoogle-appengine%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/google-appengine?hl=en.




 --
 Jeff

 --
 You received this message because you are subscribed to the Google Groups
 Google App Engine group.
 To post to this group, send email to google-appeng...@googlegroups.com.
 To unsubscribe from this group, send email to
 google-appengine+unsubscr...@googlegroups.comgoogle-appengine%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/google-appengine?hl=en.


  --
 You received this message because you are subscribed to the Google Groups
 Google App Engine group.
 To post to this group, send email to google-appeng...@googlegroups.com.
 To unsubscribe from this group, send email to
 google-appengine+unsubscr...@googlegroups.comgoogle-appengine%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/google-appengine?hl=en.




-- 
Jeff

-- 
You received this message because you are subscribed to the Google Groups 
Google App Engine group.
To post to this group, send