def create_author():
    af = AuthorForm()
    if af.author_form_submit.data and af.validate_on_submit():
        author = Author()
        author.name = af.name.data
        author.biography = af.biography.data
        db.session.add(author)
        db.session.commit()

    # fields
    return render_template('create_author.html', af=af)
def create_books():
    a1 = Author(name='Harper Lee')
    b1 = Book(title='To Kill a Mockingbird',
              publish_date=date(1960, 7, 11),
              author=a1)
    db.session.add(b1)

    a2 = Author(name='Sylvia Plath')
    b2 = Book(title='The Bell Jar', author=a2)
    db.session.add(b2)
    db.session.commit()
def create_author():
    authorForm = AuthorForm()

    # and save to the database, then flash a success message to the user and
    # redirect to the homepage
    if authorForm.validate_on_submit():
        new_author = Author(name=authorForm.name, biography=authorForm.bio)
        db.session.add(new_author)
        db.session.commit()
        return redirect('main.homepage')
    return render_template('create_author.html', authorForm=authorForm)
示例#4
0
def create_author():
    form = AuthorForm()

    if form.validate_on_submit():
        new_author = Author(name=form.name.data, biography=form.biography.data)
        db.session.add(new_author)
        db.session.commit()

        flash("New Author was created succesfully.")
        return redirect("/")
    return render_template('create_author.html', form=form)
示例#5
0
 def test_list_all_authors_pagination(self):
     """
         Test first page retrieving all results possible for one page size, full page of authors
     """
     if len(self.AUTHORS) < drf_configs["PAGE_SIZE"]:
         Author.objects.bulk_create(
             (Author(name=f"author{x}")
              for x in range(drf_configs["PAGE_SIZE"] - len(self.AUTHORS))))
     response = self.client.get("/authors/?page=1")
     self.assertEquals(response.status_code, 200)
     content = json.loads(response.content)
     self.assertEquals(len(content['results']), drf_configs['PAGE_SIZE'])
def create_author():
    form = AuthorForm()
    if form.validate_on_submit():
        new_author = Author(name=form.name.data, biography=form.biography.data)
        db.session.add(new_author)
        db.session.commit()

        flash('New author created successfully.')
        return redirect(url_for('main.homepage'))

    # if form was not valid, or was not submitted yet
    return render_template('create_author.html', form=form)
示例#7
0
    def test_list_all_authors_page_with_less_results(self):
        """
            Test page with less than the page limit size
        """
        if len(self.AUTHORS) < drf_configs["PAGE_SIZE"]:
            Author.objects.bulk_create(
                (Author(name=f"author{x}")
                 for x in range(drf_configs["PAGE_SIZE"] + 1)))
        response = self.client.get("/authors/?page=2")

        self.assertEquals(response.status_code, 200)
        content = json.loads(response.content)
        self.assertTrue(len(content['results']) < drf_configs['PAGE_SIZE'])
示例#8
0
    def setUp(self):
        """
            Setting up test database
        """
        authors = [Author(name=name) for name in self.AUTHORS]
        Author.objects.bulk_create(authors, ignore_conflicts=True)

        books = [
            {
                'name': 'Macunaíma',
                'publication_year': 1928,
                'edition': 1,
                'authors': [1]
            },
            {
                'name': 'A Hora da Estrela',
                'publication_year': 1977,
                'edition': 1,
                'authors': [2]
            },
            {
                'name': 'The Minus Sign',
                'publication_year': 1980,
                'edition': 1,
                'authors': [3]
            },
            {
                'name': 'Sagarana',
                'publication_year': 1946,
                'edition': 2,
                'authors': [4]
            },
            {
                'name': 'Example Book',
                'publication_year': 1980,
                'edition': 1,
                'authors': [3, 4]
            },
            {
                'name': 'Other Example Book',
                'publication_year': 1995,
                'edition': 1,
                'authors': [3, 4]
            },
        ]
        for book in books:
            book_authors = book.pop('authors')
            book_object = Book.objects.create(**collections.OrderedDict(book))
            book_object.authors.set(book_authors)
            book_object.save()
示例#9
0
def create_author():
    form = AuthorForm()
    if form.validate_on_submit():
        new_author = Author(
            name=form.name.data,
            biography=form.biography.data,
            dob=form.dob.data,
            country=form.country.data,
        )
        db.session.add(new_author)
        db.session.commit()
        flash("New author was created successfully.")
        return redirect(url_for("main.homepage"))
    return render_template("create_author.html", form=form)
示例#10
0
    def handle(self, *args, **options):
        self.stdout.write("Init Authors Creation")
        csv_file = options.get('csv_entry')
        try:
            csv_content = csv.DictReader(csv_file)
            batch = [
                Author(name=author_row['name'].strip())
                for author_row in csv_content
            ]
        except Exception as e:
            self.stderr.write("Error on document format.")
            return

        res = Author.objects.bulk_create(batch, ignore_conflicts=True)
        self.stdout.write("Finish authors creation")
示例#11
0
def create_author():
    # TODO: Make an AuthorForm instance
    form = AuthorForm()

    # TODO: If the form was submitted and is valid, create a new Author object
    # and save to the database, then flash a success message to the user and
    # redirect to the homepage
    if form.validate_on_submit():
        new_author = Author(name=form.name.data, biography=form.biography.data)
        db.session.add(new_author)
        db.session.commit()

    # TODO: Send the form object to the template, and use it to render the form
    # fields
    return render_template('create_author.html', form=form)
示例#12
0
def create_author():
    form = AuthorForm()

    # if form was submitted and contained no errors
    if form.validate_on_submit():
        new_author = Author(
            name = form.name.data,
            biography = form.biography.data,
            birth_date = form.birth_date.data,
            country = form.country.data,
        )
        db.session.add(new_author)
        db.session.commit()

        flash('New author was created successfully.')
        return redirect(url_for('main.homepage'))
    return render_template('create_author.html', form=form)
示例#13
0
 def setUp(self):
     """
         Setting up test database
     """
     authors = [Author(name=name) for name in self.AUTHORS]
     Author.objects.bulk_create(authors, ignore_conflicts=True)