Пример #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)
Пример #2
0
def list(request):
    if not users.get_current_user():
        return HttpResponseRedirect(users.create_login_url('/people'))

    people = modify_people(Person.all().filter("owner =", users.get_current_user()))

    return render_to_response('list.html', {'people': people, 'count': len(people), 'auth_url': auth_user('/people')})
Пример #3
0
def erase(request):
    if not users.get_current_user():
        return HttpResponseRedirect(users.create_login_url('/add'))

    people = Person.all().filter("owner =", users.get_current_user())
    for person in people:
        person.delete()

    return HttpResponseRedirect('/')
Пример #4
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/')
Пример #5
0
def export(request):
    if not users.get_current_user():
        return HttpResponseRedirect(users.create_login_url('/export'))

    people = modify_people(Person.all().filter("owner =", users.get_current_user()))
    response = HttpResponse(mimetype='text/csv')
    response['Content-Disposition'] = 'attachment; filename=birthdays.csv'

    # Create the CSV writer using the HttpResponse as the "file"
    writer = csv.writer(response)
    for person in people:
        writer.writerow(["%s/%s/%s" % (person.birthday.month, person.birthday.day, person.birthday.year),
                         person.name.encode('utf-8')])

    return response
Пример #6
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')
Пример #7
0
def show_new_person(form, request):
    people = modify_people(Person.all().filter("owner =", users.get_current_user()))
    return render_to_response('add.html',
                              {'form': form, 'people': people, 'count': len(people),
                               'auth_url': get_auth_url(request.META['PATH_INFO'])})
Пример #8
0
def show_new_person(form):
    people = modify_people(Person.all().filter("owner =", users.get_current_user()))
    return render_to_response('add.html',
                              {'form': form, 'people': people, 'count': len(people),
                               'auth_url': auth_user('/add')})