Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
albomediano_reading
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Al Vincent E. Bomediano
albomediano_reading
Commits
065ce47b
Commit
065ce47b
authored
Apr 25, 2023
by
Al Vincent E. Bomediano
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add addbook page with get request implementation
parent
76a8436a
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
89 additions
and
5 deletions
+89
-5
forms.cpython-311.pyc
...diano_reading/bookshelf/__pycache__/forms.cpython-311.pyc
+0
-0
urls.cpython-311.pyc
...ediano_reading/bookshelf/__pycache__/urls.cpython-311.pyc
+0
-0
views.cpython-311.pyc
...diano_reading/bookshelf/__pycache__/views.cpython-311.pyc
+0
-0
forms.py
albomediano_reading/bookshelf/forms.py
+16
-0
add-book.html
...diano_reading/bookshelf/templates/bookshelf/add-book.html
+18
-0
home.html
albomediano_reading/bookshelf/templates/bookshelf/home.html
+3
-1
tests.py
albomediano_reading/bookshelf/tests.py
+0
-3
urls.py
albomediano_reading/bookshelf/urls.py
+5
-1
views.py
albomediano_reading/bookshelf/views.py
+47
-0
No files found.
albomediano_reading/bookshelf/__pycache__/forms.cpython-311.pyc
0 → 100644
View file @
065ce47b
File added
albomediano_reading/bookshelf/__pycache__/urls.cpython-311.pyc
View file @
065ce47b
No preview for this file type
albomediano_reading/bookshelf/__pycache__/views.cpython-311.pyc
View file @
065ce47b
No preview for this file type
albomediano_reading/bookshelf/forms.py
0 → 100644
View file @
065ce47b
from
django
import
forms
class
IndexCardForm
(
forms
.
Form
):
name
=
forms
.
CharField
(
label
=
'Full Name'
,
max_length
=
100
)
section
=
forms
.
CharField
(
label
=
'CSCI40 Section'
,
max_length
=
5
)
age
=
forms
.
IntegerField
(
label
=
'Current Age'
)
class
AddBookForm
(
forms
.
Form
):
title
=
forms
.
CharField
(
label
=
'Title'
,
max_length
=
100
)
# author = forms.ForeignKey(Author, on_delete=forms.CASCADE)
publisher
=
forms
.
CharField
(
label
=
'Publisher'
,
max_length
=
100
)
year_published
=
forms
.
IntegerField
(
label
=
'Year Published'
)
ISBN
=
forms
.
IntegerField
(
label
=
'ISBN'
)
blurb
=
forms
.
CharField
(
label
=
'Blurb'
,
max_length
=
200
)
albomediano_reading/bookshelf/templates/bookshelf/add-book.html
0 → 100644
View file @
065ce47b
{% block content %}
{{ form.non_field_errors }}
{% for field in form %}
{% if field.errors %}
<p>
{{ field.label }} has the following errors:
</p>
<ul>
{% for error in field.errors %}
<li>
{{ error }}
</li>
{% endfor %}
</ul>
{% endif %}
{% endfor %}
<form
action=
"/books/add/"
method=
"post"
>
{% csrf_token %}
{{ form }}
<input
type=
"submit"
value=
"Submit"
>
</form>
{% endblock %}
\ No newline at end of file
albomediano_reading/bookshelf/templates/bookshelf/home.html
View file @
065ce47b
...
@@ -5,6 +5,8 @@
...
@@ -5,6 +5,8 @@
{% block content %}
{% block content %}
<h1>
Welcome to Al's Database of
<h1>
Welcome to Al's Database of
Favorite Books and Authors
</h1>
Favorite Books and Authors
</h1>
<h3>
I barel read books, and when I do, they are mostly Japanese Light Novels or Manga. But recently I have been into Webtoons!
</h3>
<h3>
I barel
y
read books, and when I do, they are mostly Japanese Light Novels or Manga. But recently I have been into Webtoons!
</h3>
<a
href=
"/books"
>
Books
</a>
<a
href=
"/authors"
>
Authors
</a>
<a
href=
"/books"
>
Books
</a>
<a
href=
"/authors"
>
Authors
</a>
<br>
<a
href=
"/books/add"
>
Add Book
</a>
<a
href=
"/authors/add"
>
Add Author
</a>
{% endblock %}
{% endblock %}
\ No newline at end of file
albomediano_reading/bookshelf/tests.py
View file @
065ce47b
from
django.test
import
TestCase
# Create your tests here.
albomediano_reading/bookshelf/urls.py
View file @
065ce47b
...
@@ -2,7 +2,8 @@ from django.urls import path
...
@@ -2,7 +2,8 @@ from django.urls import path
from
.
import
views
from
.
import
views
from
.views
import
(
from
.views
import
(
BooksView
,
BooksDetailsView
,
BooksView
,
BooksDetailsView
,
AuthorsView
,
AuthorsDetailsView
AuthorsView
,
AuthorsDetailsView
,
index_card_view
,
add_book_view
)
)
urlpatterns
=
[
urlpatterns
=
[
...
@@ -11,6 +12,9 @@ urlpatterns = [
...
@@ -11,6 +12,9 @@ urlpatterns = [
path
(
'books/<int:pk>/details'
,
BooksDetailsView
.
as_view
(),
name
=
'book-details'
),
path
(
'books/<int:pk>/details'
,
BooksDetailsView
.
as_view
(),
name
=
'book-details'
),
path
(
'authors/'
,
AuthorsView
.
as_view
(),
name
=
'authors-list'
),
path
(
'authors/'
,
AuthorsView
.
as_view
(),
name
=
'authors-list'
),
path
(
'authors/<int:pk>/details'
,
AuthorsDetailsView
.
as_view
(),
name
=
'author-details'
),
path
(
'authors/<int:pk>/details'
,
AuthorsDetailsView
.
as_view
(),
name
=
'author-details'
),
path
(
'index_card'
,
index_card_view
,
name
=
'index_card'
),
path
(
'books/add/'
,
add_book_view
,
name
=
'add-book'
),
]
]
app_name
=
"bookshelf"
app_name
=
"bookshelf"
albomediano_reading/bookshelf/views.py
View file @
065ce47b
from
django.forms
import
NameForm
,
HttpResponse
from
django.shortcuts
import
render
from
django.shortcuts
import
render
from
django.views.generic.list
import
ListView
from
django.views.generic.list
import
ListView
from
django.views.generic.detail
import
DetailView
from
django.views.generic.detail
import
DetailView
from
.models
import
Books
,
Author
from
.models
import
Books
,
Author
from
.forms
import
IndexCardForm
,
AddBookForm
def
home_view
(
request
):
def
home_view
(
request
):
...
@@ -26,3 +28,48 @@ class AuthorsView(ListView):
...
@@ -26,3 +28,48 @@ class AuthorsView(ListView):
class
AuthorsDetailsView
(
DetailView
):
class
AuthorsDetailsView
(
DetailView
):
model
=
Author
model
=
Author
template_name
=
'bookshelf/author_details.html'
template_name
=
'bookshelf/author_details.html'
def
index_card_view
(
request
):
# Checking for POST request
if
request
.
method
==
'POST'
:
# Creating a Form object
form
=
NameForm
(
request
.
POST
)
# Checking if the inputs are valid
if
form
.
is_valid
():
return
HttpResponse
(
'Hello {} from Section {}'
.
format
(
# Getting data from our form that have been validated
form
.
cleaned_data
[
'name'
],
form
.
cleanded_data
[
'section'
]
)
)
else
:
# returning the same form object in the context allows
# for rendering the errors that are in the form object
return
render
(
request
,
'index.html'
,
{
'form'
:
form
})
else
:
form
=
IndexCardForm
()
return
render
(
request
,
'index.html'
,
{
'form'
:
form
})
def
add_book_view
(
request
):
if
request
.
method
==
'POST'
:
form
=
NameForm
(
request
.
POST
)
if
form
.
is_valid
():
return
HttpResponse
(
'Author: {}, Publisher: {}, Year Published: {}, ISBN: {}, Blurb: {}'
.
format
(
form
.
cleaned_data
[
'author'
],
form
.
cleaned_data
[
'publisher'
],
form
.
cleaned_data
[
'year_published'
],
form
.
cleaned_data
[
'ISBN'
],
form
.
cleaned_data
[
'blurb'
],
)
)
else
:
return
render
(
request
,
'index.html'
,
{
'form'
:
form
})
else
:
form
=
AddBookForm
()
return
render
(
request
,
'index.html'
,
{
'form'
:
form
})
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment