Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
ianaragoza_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
Ian Rafael T. Aragoza
ianaragoza_reading
Commits
ba8bd205
Commit
ba8bd205
authored
Apr 25, 2023
by
Ian Rafael T. Aragoza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Edited home and details pages, added add and edit functionalities
parent
499d5403
Changes
15
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
170 additions
and
5 deletions
+170
-5
forms.cpython-311.pyc
...agoza_reading/bookshelf/__pycache__/forms.cpython-311.pyc
+0
-0
urls.cpython-311.pyc
...ragoza_reading/bookshelf/__pycache__/urls.cpython-311.pyc
+0
-0
views.cpython-311.pyc
...agoza_reading/bookshelf/__pycache__/views.cpython-311.pyc
+0
-0
forms.py
ianaragoza_reading/bookshelf/forms.py
+19
-0
base.html
ianaragoza_reading/bookshelf/templates/base.html
+0
-1
add-author.html
...oza_reading/bookshelf/templates/bookshelf/add-author.html
+20
-0
add-book.html
...agoza_reading/bookshelf/templates/bookshelf/add-book.html
+20
-0
author_details.html
...reading/bookshelf/templates/bookshelf/author_details.html
+2
-0
book_detais.html
...za_reading/bookshelf/templates/bookshelf/book_detais.html
+3
-0
edit-author.html
...za_reading/bookshelf/templates/bookshelf/edit-author.html
+20
-0
edit-book.html
...goza_reading/bookshelf/templates/bookshelf/edit-book.html
+20
-0
home.html
ianaragoza_reading/bookshelf/templates/home.html
+9
-1
urls.py
ianaragoza_reading/bookshelf/urls.py
+6
-1
views.py
ianaragoza_reading/bookshelf/views.py
+51
-2
urls.cpython-311.pyc
...ading/ianaragoza_reading/__pycache__/urls.cpython-311.pyc
+0
-0
No files found.
ianaragoza_reading/bookshelf/__pycache__/forms.cpython-311.pyc
0 → 100644
View file @
ba8bd205
File added
ianaragoza_reading/bookshelf/__pycache__/urls.cpython-311.pyc
View file @
ba8bd205
No preview for this file type
ianaragoza_reading/bookshelf/__pycache__/views.cpython-311.pyc
View file @
ba8bd205
No preview for this file type
ianaragoza_reading/bookshelf/forms.py
0 → 100644
View file @
ba8bd205
from
django
import
forms
from
.models
import
Author
,
Book
author_list
=
[]
for
author
in
Author
.
objects
.
all
():
author_list
.
append
(
author
)
class
AuthorForm
(
forms
.
ModelForm
):
class
Meta
:
model
=
Author
fields
=
'__all__'
class
BookForm
(
forms
.
ModelForm
):
class
Meta
:
model
=
Book
fields
=
'__all__'
\ No newline at end of file
ianaragoza_reading/bookshelf/templates/base.html
View file @
ba8bd205
...
@@ -5,7 +5,6 @@
...
@@ -5,7 +5,6 @@
{% bootstrap_css %}
{% bootstrap_css %}
{% bootstrap_javascript %}
{% bootstrap_javascript %}
<title>
{% block title %}{% endblock %}
</title>
<title>
{% block title %}{% endblock %}
</title>
{% block styles %}{% bootstrap_css %}{% endblock %}
{% block styles %}{% bootstrap_css %}{% endblock %}
</head>
</head>
<body>
<body>
...
...
ianaragoza_reading/bookshelf/templates/bookshelf/add-author.html
0 → 100644
View file @
ba8bd205
{% extends 'base.html' %}
{% load static %}
{% block title %}Add New Author{% endblock %}
{% block content %}
{{ form.non_field_errors }}
<div
class=
"container-fluid p-3 bg-dark text-white text-center"
>
<br>
<h1
class=
"display-4"
>
Add a New Author to the Database
</h1>
<br>
</div>
<div
class=
"container my-5 text-center"
>
<form
method=
"post"
>
{% csrf_token %}
{% for field in form %}
{{ field.label }}
<br>
{{ field }}
<br><br>
{% endfor %}
<input
type=
"submit"
value=
"Add Author"
class=
"btn btn-primary"
>
</form>
</div>
{% endblock %}
ianaragoza_reading/bookshelf/templates/bookshelf/add-book.html
0 → 100644
View file @
ba8bd205
{% extends 'base.html' %}
{% load static %}
{% block title %}Add New Book{% endblock %}
{% block content %}
{{ form.non_field_errors }}
<div
class=
"container-fluid p-3 bg-dark text-white text-center"
>
<br>
<h1
class=
"display-4"
>
Add a New Book to the Database
</h1>
<br>
</div>
<div
class=
"container my-5 text-center"
>
<form
method=
"post"
>
{% csrf_token %}
{% for field in form %}
{{ field.label }}
<br>
{{ field }}
<br><br>
{% endfor %}
<input
type=
"submit"
value=
"Add Book"
class=
"btn btn-primary"
>
</form>
</div>
{% endblock %}
ianaragoza_reading/bookshelf/templates/bookshelf/author_details.html
View file @
ba8bd205
...
@@ -31,6 +31,8 @@
...
@@ -31,6 +31,8 @@
</div>
</div>
</div>
</div>
<p><i>
{{ object.bio | linebreaks }}
</i></p>
<p><i>
{{ object.bio | linebreaks }}
</i></p>
<br>
<a
href=
"/authors/{{ object.pk }}/edit/"
class=
"btn btn-primary"
>
Edit Author
</a>
</div>
</div>
<div
class=
"container my-5 text-center"
>
<div
class=
"container my-5 text-center"
>
<h3>
Books by {{ object.first_name }} {{ object.last_name }} I Love:
</h3>
<h3>
Books by {{ object.first_name }} {{ object.last_name }} I Love:
</h3>
...
...
ianaragoza_reading/bookshelf/templates/bookshelf/book_detais.html
View file @
ba8bd205
...
@@ -30,6 +30,9 @@
...
@@ -30,6 +30,9 @@
</div>
</div>
</div>
</div>
</div>
</div>
<br>
<a
href=
"/books/{{ object.pk }}/edit"
class=
"btn btn-primary"
>
Edit Book
</a>
<br><br>
</div>
</div>
<div
class=
"container my-5 text-center"
>
<div
class=
"container my-5 text-center"
>
<p><i>
{{ object.blurb | linebreaks}}
</i></p>
<p><i>
{{ object.blurb | linebreaks}}
</i></p>
...
...
ianaragoza_reading/bookshelf/templates/bookshelf/edit-author.html
0 → 100644
View file @
ba8bd205
{% extends 'base.html' %}
{% load static %}
{% block title %}Edit Author{% endblock %}
{% block content %}
{{ form.non_field_errors }}
<div
class=
"container-fluid p-3 bg-dark text-white text-center"
>
<br>
<h1
class=
"display-4"
>
Edit Author's Details
</h1>
<br>
</div>
<div
class=
"container my-5 text-center"
>
<form
method=
"post"
>
{% csrf_token %}
{% for field in form %}
{{ field.label }}
<br>
{{ field }}
<br><br>
{% endfor %}
<input
type=
"submit"
value=
"Save Changes"
class=
"btn btn-primary"
href=
"/books/{{ object.pk }}/edit"
>
</form>
</div>
{% endblock %}
ianaragoza_reading/bookshelf/templates/bookshelf/edit-book.html
0 → 100644
View file @
ba8bd205
{% extends 'base.html' %}
{% load static %}
{% block title %}Edit Book{% endblock %}
{% block content %}
{{ form.non_field_errors }}
<div
class=
"container-fluid p-3 bg-dark text-white text-center"
>
<br>
<h1
class=
"display-4"
>
Edit Book's Details
</h1>
<br>
</div>
<div
class=
"container my-5 text-center"
>
<form
method=
"post"
>
{% csrf_token %}
{% for field in form %}
{{ field.label }}
<br>
{{ field }}
<br><br>
{% endfor %}
<input
type=
"submit"
value=
"Save Changes"
class=
"btn btn-primary"
>
</form>
</div>
{% endblock %}
ianaragoza_reading/bookshelf/templates/home.html
View file @
ba8bd205
...
@@ -24,7 +24,7 @@
...
@@ -24,7 +24,7 @@
No matter the case, I've had adventures with each of these books, and even though I don't remember them well, they've still left a mark on me.
</p>
No matter the case, I've had adventures with each of these books, and even though I don't remember them well, they've still left a mark on me.
</p>
<br><br>
<br><br>
<div
class=
"container"
>
<div
class=
"container"
>
<div
class=
"row"
>
<div
class=
"row
p-3
"
>
<div
class=
"col-6"
>
<div
class=
"col-6"
>
<a
href=
"/books"
><button
type=
"button"
class=
"btn btn-primary"
>
Books
</button></a>
<a
href=
"/books"
><button
type=
"button"
class=
"btn btn-primary"
>
Books
</button></a>
</div>
</div>
...
@@ -32,6 +32,14 @@
...
@@ -32,6 +32,14 @@
<a
href=
"/authors"
><button
type=
"button"
class=
"btn btn-primary"
>
Authors
</button></a>
<a
href=
"/authors"
><button
type=
"button"
class=
"btn btn-primary"
>
Authors
</button></a>
</div>
</div>
</div>
</div>
<div
class=
"row p-3"
>
<div
class=
"col-6"
>
<a
href=
"/books/add"
><button
type=
"button"
class=
"btn btn-primary"
>
Add Book
</button></a>
</div>
<div
class=
"col-6"
>
<a
href=
"/authors/add"
><button
type=
"button"
class=
"btn btn-primary"
>
Add Author
</button></a>
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
{% endblock %}
\ No newline at end of file
ianaragoza_reading/bookshelf/urls.py
View file @
ba8bd205
# <appname>/urls.py
# <appname>/urls.py
from
django.urls
import
path
from
django.urls
import
path
from
.views
import
home
,
AuthorsView
,
AuthorDetailsView
,
BooksView
,
BookDetailsView
from
django.views.generic
import
RedirectView
from
.views
import
home
,
AuthorsView
,
AuthorDetailsView
,
BooksView
,
BookDetailsView
,
BookCreateView
,
BookUpdateView
,
AuthorCreateView
,
AuthorUpdateView
urlpatterns
=
[
urlpatterns
=
[
path
(
'home/'
,
home
,
name
=
'home'
),
path
(
'home/'
,
home
,
name
=
'home'
),
path
(
'authors/'
,
AuthorsView
.
as_view
(),
name
=
'author-list'
),
path
(
'authors/'
,
AuthorsView
.
as_view
(),
name
=
'author-list'
),
path
(
'authors/add/'
,
AuthorCreateView
.
as_view
(),
name
=
'add-author'
),
path
(
'authors/<int:pk>/details/'
,
AuthorDetailsView
.
as_view
(),
name
=
'author-detail'
),
path
(
'authors/<int:pk>/details/'
,
AuthorDetailsView
.
as_view
(),
name
=
'author-detail'
),
path
(
'authors/<int:pk>/edit/'
,
AuthorUpdateView
.
as_view
(),
name
=
'edit-author'
),
path
(
'books/'
,
BooksView
.
as_view
(),
name
=
'books'
),
path
(
'books/'
,
BooksView
.
as_view
(),
name
=
'books'
),
path
(
'books/add/'
,
BookCreateView
.
as_view
(),
name
=
'add-book'
),
path
(
'books/<int:pk>/details/'
,
BookDetailsView
.
as_view
(),
name
=
'books-detail'
),
path
(
'books/<int:pk>/details/'
,
BookDetailsView
.
as_view
(),
name
=
'books-detail'
),
path
(
'books/<int:pk>/edit/'
,
BookUpdateView
.
as_view
(),
name
=
'edit-book'
),
]
]
...
...
ianaragoza_reading/bookshelf/views.py
View file @
ba8bd205
from
django.shortcuts
import
render
from
django.shortcuts
import
render
from
django.http.response
import
HttpResponseRedirect
from
django.views.generic.edit
import
CreateView
,
UpdateView
from
django.views.generic.detail
import
DetailView
from
django.views.generic.detail
import
DetailView
from
django.views.generic.list
import
ListView
from
django.views.generic.list
import
ListView
from
.models
import
Author
,
Book
from
.models
import
Author
,
Book
from
.forms
import
AuthorForm
,
BookForm
# Create your views here.
# Create your views here.
def
home
(
request
):
def
home
(
request
):
...
@@ -21,6 +22,30 @@ class BookDetailsView(DetailView):
...
@@ -21,6 +22,30 @@ class BookDetailsView(DetailView):
template_name
=
"bookshelf/book_detais.html"
template_name
=
"bookshelf/book_detais.html"
class
BookCreateView
(
CreateView
):
model
=
Book
fields
=
'__all__'
template_name
=
"bookshelf/add-book.html"
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
form
=
BookForm
(
request
.
POST
)
if
form
.
is_valid
():
new_book
=
form
.
save
()
redirect_link
=
"../"
+
new_book
.
get_absolute_url
()
+
"/details/"
return
HttpResponseRedirect
(
redirect_link
)
else
:
return
render
(
request
,
self
.
template_name
,
{
'form'
:
form
})
class
BookUpdateView
(
UpdateView
):
model
=
Book
fields
=
'__all__'
template_name
=
'bookshelf/edit-book.html'
success_url
=
"../details/"
class
AuthorsView
(
ListView
):
class
AuthorsView
(
ListView
):
model
=
Author
model
=
Author
template_name
=
"bookshelf/authors.html"
template_name
=
"bookshelf/authors.html"
...
@@ -29,3 +54,27 @@ class AuthorsView(ListView):
...
@@ -29,3 +54,27 @@ class AuthorsView(ListView):
class
AuthorDetailsView
(
DetailView
):
class
AuthorDetailsView
(
DetailView
):
model
=
Author
model
=
Author
template_name
=
"bookshelf/author_details.html"
template_name
=
"bookshelf/author_details.html"
class
AuthorCreateView
(
CreateView
):
model
=
Author
fields
=
'__all__'
template_name
=
"bookshelf/add-author.html"
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
form
=
AuthorForm
(
request
.
POST
)
if
form
.
is_valid
():
new_author
=
form
.
save
()
redirect_link
=
"../"
+
new_author
.
get_absolute_url
()
+
"/details/"
return
HttpResponseRedirect
(
redirect_link
)
else
:
return
render
(
request
,
self
.
template_name
,
{
'form'
:
form
})
class
AuthorUpdateView
(
UpdateView
):
model
=
Author
fields
=
'__all__'
template_name
=
'bookshelf/edit-book.html'
success_url
=
"../details/"
ianaragoza_reading/ianaragoza_reading/__pycache__/urls.cpython-311.pyc
View file @
ba8bd205
No preview for this file type
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