Esempio n. 1
0
def add(request):
    if not users.get_current_user():
        return HttpResponseRedirect(users.create_login_url('/add'))

    if request.method == 'POST':
        form = AddForm(request.POST)

        if form.is_valid():
            try:
                name = form.clean_data['name']
                birthday = form.clean_birthday()
                p = Person(name=name)
                p.owner = users.get_current_user()
                p.birthday = datetime.date(datetime.strptime(birthday, "%m/%d/%Y"))
            except:
                return show_new_person(form)

            a = p.put()
            logging.info(a)
        else:
            return show_new_person(form)

        return HttpResponseRedirect('/people')
    else:
        form = AddForm()

    return show_new_person(form)
Esempio n. 2
0
    def post(self):
        try:
            upload_files = self.get_uploads('file')
            blob_info = upload_files[0]
            if blob_info.size > 1048576:
                self.redirect('/upload_failure')

            csv_file = fetch_data(blob_info, 0, blob_info.size + 1)
            stringReader = csv.reader(StringIO(csv_file))

            for row in stringReader:
                logging.info(row)
                p = Person(name=row[1].decode('utf-8'))
                p.owner = users.get_current_user()
                p.birthday = datetime.date(datetime.strptime(row[0], "%m/%d/%Y"))
                p.put()

            self.redirect('/')
        except:
            self.redirect('/upload_failure/')
Esempio n. 3
0
    def post(self):
        upload_files = self.get_uploads('file')
        blob_info = upload_files[0]
        if blob_info.size > 1048576: # 1Mb
            self.redirect('/upload_failure')

        csv_file = fetch_data(blob_info, 0, blob_info.size + 1)
        stringReader = csv.reader(StringIO(csv_file))
        #            TODO: clean up blobstore, or save reference to it
        blobstore.delete(upload_files)

        for row in stringReader:
        #            Very ugly
        #            TODO: Optimize, remove redundant datastore queries
            people = Person.all().filter("owner =", users.get_current_user())
            if people.filter("name =", row[1].decode('utf-8')).count() == 0:
                p = Person(name=row[1].decode('utf-8'))
                p.owner = users.get_current_user()
                p.birthday = datetime.date(datetime.strptime(row[0], "%m/%d/%Y"))
                p.put()

        self.redirect('/people')