Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
library-app-django
Project
Project
Details
Activity
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
Ilham Maulana
library-app-django
Commits
ba7e9563
Commit
ba7e9563
authored
Jul 09, 2024
by
impfundev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: book app shifting to class based view
parent
10c8a8ea
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
94 additions
and
178 deletions
+94
-178
pagination.html
dashboards/templates/pagination.html
+2
-0
forms.py
librarians/forms.py
+1
-1
models.py
librarians/models.py
+1
-0
librarians.html
librarians/templates/librarians.html
+3
-9
librarians_create_form.html
librarians/templates/librarians_create_form.html
+17
-32
librarians_delete_form.html
librarians/templates/librarians_delete_form.html
+15
-35
librarians_table_data.html
librarians/templates/librarians_table_data.html
+4
-5
librarians_update_form.html
librarians/templates/librarians_update_form.html
+1
-1
urls.py
librarians/urls.py
+10
-4
views.py
librarians/views.py
+40
-91
No files found.
dashboards/templates/pagination.html
View file @
ba7e9563
{% if is_paginated %}
<nav
aria-label=
"Page navigation example"
>
<ul
class=
"pagination"
>
{% if page_obj.has_previous %}
...
...
@@ -27,3 +28,4 @@
{% endif %}
</ul>
</nav>
{% endif %}
librarians/forms.py
View file @
ba7e9563
...
...
@@ -19,7 +19,7 @@ class LibrarianForm(forms.ModelForm):
"class"
:
"form-control"
,
}
),
"password"
:
forms
.
Text
Input
(
"password"
:
forms
.
Password
Input
(
attrs
=
{
"placeholder"
:
"Password"
,
"class"
:
"form-control"
,
...
...
librarians/models.py
View file @
ba7e9563
from
django.db
import
models
from
django.contrib.auth.models
import
User
class
Librarians
(
models
.
Model
):
...
...
librarians/templates/librarians.html
View file @
ba7e9563
{% extends "layout.html" %} {% block dashboard %}
<div
style=
"max-width: 80vw"
class=
"w-100 p-4"
>
{% include "librarians_create_form.html" %}
<div
class=
"d-flex gap-2 mb-4"
>
{% include "order_form.html" %}
<button
type=
"button"
class=
"btn btn-primary"
data-bs-toggle=
"modal"
data-bs-target=
"#librarian_modal_create"
>
<a
type=
"button"
class=
"btn btn-primary"
href=
"/dashboard/librarians/add/"
>
<i
class=
"bi bi-plus-circle"
></i>
Add Librarian
</
button
>
</
a
>
{% include "search_form.html" %}
</div>
{% include "librarians_table_data.html" %}
</div>
{%
include "librarians_delete_form.html" %} {%
endblock dashboard %}
{% endblock dashboard %}
librarians/templates/librarians_create_form.html
View file @
ba7e9563
<form
class=
"modal fade"
id=
"librarian_modal_create"
tabindex=
"-1"
aria-labelledby=
"librarian_modal_label"
aria-hidden=
"true"
action=
"/dashboard/librarians/"
method=
"POST"
>
<div
class=
"modal-dialog modal-dialog-centered"
>
<div
class=
"modal-content"
>
<div
class=
"modal-header"
>
<h1
class=
"modal-title fs-5"
id=
"exampleModalLabel"
>
Input Data
</h1>
<button
type=
"button"
class=
"btn-close"
data-bs-dismiss=
"modal"
aria-label=
"Close"
></button>
{% extends "layout.html" %} {% block dashboard %}
<div
style=
"max-width: 80vw"
class=
"w-100 p-4"
>
<div
class=
"d-flex flex-column gap-2 mb-4"
>
<h1
class=
"h3"
>
Create Librarian Account
</h1>
<form
id=
"librarian_update_modal_{{ librarian_id }}"
action=
"/dashboard/librarians/add/"
method=
"POST"
>
{% csrf_token %}
<div
class=
"d-flex flex-column gap-1"
>
{{ form }}
</div>
<div
class=
"d-flex gap-2 my-3"
>
<a
href=
"/dashboard/librarians/"
class=
"btn btn-secondary"
>
Cancel
</a>
<button
class=
"btn btn-primary"
>
Submit
</button>
</div>
<div
class=
"modal-body"
>
{% csrf_token %} {% for field in form %}
<div
class=
"form-outline form-white mb-3"
>
{{ field }}
</div>
{% endfor %}
</div>
<div
class=
"modal-footer"
>
<button
type=
"button"
class=
"btn btn-secondary"
data-bs-dismiss=
"modal"
>
Close
</button>
<button
type=
"submit"
class=
"btn btn-primary"
>
Submit
</button>
</div>
</div>
</form>
</div>
</form>
</div>
{% endblock dashboard %}
librarians/templates/librarians_delete_form.html
View file @
ba7e9563
{% for librarian in librarians %}
<form
class=
"modal fade"
id=
"librarian_delete_modal_{{ librarian.id }}"
tabindex=
"-1"
aria-labelledby=
"librarian_delete_label"
aria-hidden=
"true"
action=
"/dashboard/librarians/{{ librarian.id }}/delete/"
method=
"POST"
>
{% csrf_token %}
<div
class=
"modal-dialog modal-dialog-centered"
>
<div
class=
"modal-content"
>
<div
class=
"modal-header"
>
<h1
class=
"modal-title fs-5"
id=
"exampleModalLabel"
>
Are you sure want to delete
<b>
{{ librarian.title }}
</b>
?
</h1>
<button
type=
"button"
class=
"btn-close"
data-bs-dismiss=
"modal"
aria-label=
"Close"
></button>
</div>
<div
class=
"modal-body"
>
Once data is deleted, it cannot be restored.
<input
type=
"hidden"
name=
"id"
id=
"almacen_id"
/>
</div>
<div
class=
"modal-footer"
>
<button
type=
"button"
class=
"btn btn-secondary"
data-bs-dismiss=
"modal"
>
Cancel
</button>
{% extends "layout.html" %} {% block dashboard %}
<div
style=
"max-width: 80vw"
class=
"w-100 p-4"
>
<div
class=
"d-flex flex-column gap-2 mb-4"
>
<h1
class=
"h3"
>
Are you sure want to delete this data
<form
action=
""
method=
"POST"
>
{% csrf_token %}
<div
class=
"d-flex flex-column gap-1"
>
Once data is deleted, it cannot be restored.
</div>
<div
class=
"d-flex gap-2 my-3"
>
<a
href=
"/dashboard/librarians/"
class=
"btn btn-secondary"
>
Cancel
</a>
<button
type=
"submit"
class=
"btn btn-danger"
>
Continue
</button>
</div>
</
div
>
</
form
>
</div>
</
form
>
{% end
for
%}
</
div
>
{% end
block dashboard
%}
librarians/templates/librarians_table_data.html
View file @
ba7e9563
...
...
@@ -18,17 +18,16 @@
<td
class=
"d-flex gap-2"
>
<a
class=
"btn btn-success"
href=
"/dashboard/librarians/{{ librarian.id }}/
update/
"
href=
"/dashboard/librarians/{{ librarian.id }}/"
>
<i
class=
"bi bi-pencil-square"
></i>
</a>
<
button
<
a
class=
"btn btn-danger"
data-bs-toggle=
"modal"
data-bs-target=
"#librarian_delete_modal_{{ librarian.id }}"
href=
"/dashboard/librarians/{{ librarian.id }}/delete/"
>
<i
class=
"bi bi-trash3-fill"
></i>
</
button
>
</
a
>
</td>
</tr>
{% endfor %} {% else %}
...
...
librarians/templates/librarians_update_form.html
View file @
ba7e9563
...
...
@@ -4,7 +4,7 @@
<h1
class=
"h3"
>
Update Data
</h1>
<form
id=
"librarian_update_modal_{{ librarian_id }}"
action=
"
/dashboard/librarians/{{ librarian_id }}/update/
"
action=
""
method=
"POST"
>
{% csrf_token %}
...
...
librarians/urls.py
View file @
ba7e9563
from
django.urls
import
path
from
librarians.views
import
index
,
update
,
delete
from
librarians.views
import
(
LibrarianListView
,
LibrarianCreateView
,
LibrarianUpdateView
,
LibrarianDeleteView
,
)
urlpatterns
=
[
path
(
""
,
index
,
name
=
"librarian_lists"
),
path
(
"<id>/update/"
,
update
,
name
=
"update_librarian"
),
path
(
"<id>/delete/"
,
delete
,
name
=
"delete_librarian"
),
path
(
""
,
LibrarianListView
.
as_view
(),
name
=
"librarian_lists"
),
path
(
"add/"
,
LibrarianCreateView
.
as_view
(),
name
=
"create_librarian"
),
path
(
"<int:pk>/"
,
LibrarianUpdateView
.
as_view
(),
name
=
"update_librarian"
),
path
(
"<int:pk>/delete/"
,
LibrarianDeleteView
.
as_view
(),
name
=
"delete_librarian"
),
]
librarians/views.py
View file @
ba7e9563
from
authentications.utils
import
Hasher
from
django.shortcuts
import
get_object_or_404
,
render
from
django.http
import
HttpResponseRedirect
from
django.db.models
import
Q
from
django.views
import
generic
from
django.http
import
HttpResponseRedirect
from
django.shortcuts
import
render
,
redirect
,
get_object_or_404
from
datetime
import
datetime
from
authentications.utils
import
Hasher
from
librarians.models
import
Librarians
from
librarians.forms
import
LibrarianForm
from
django.core.paginator
import
Paginator
,
PageNotAnInteger
,
EmptyPage
def
index
(
request
):
librarians
=
Librarians
.
objects
.
all
()
context
=
{
"librarians"
:
librarians
,
"form"
:
LibrarianForm
()}
default_page
=
1
page
=
request
.
GET
.
get
(
"page"
,
default_page
)
items_per_page
=
5
paginator
=
Paginator
(
librarians
,
items_per_page
)
try
:
page_obj
=
paginator
.
page
(
page
)
context
[
"page_obj"
]
=
page_obj
context
[
"librarians"
]
=
page_obj
except
PageNotAnInteger
:
page_obj
=
paginator
.
page
(
default_page
)
context
[
"page_obj"
]
=
page_obj
context
[
"librarians"
]
=
page_obj
except
EmptyPage
:
page_obj
=
paginator
.
page
(
paginator
.
num_pages
)
context
[
"page_obj"
]
=
page_obj
context
[
"librarians"
]
=
page_obj
class
LibrarianListView
(
generic
.
ListView
):
model
=
Librarians
template_name
=
"librarians.html"
paginate_by
=
5
context_object_name
=
"librarians"
if
request
.
method
==
"POST"
:
form
=
LibrarianForm
(
request
.
POST
)
if
form
.
is_valid
:
name
=
form
.
data
[
"name"
]
email
=
form
.
data
[
"email"
]
password
=
form
.
data
[
"password"
]
hashed_password
=
Hasher
.
encode
(
password
=
password
)
def
get_queryset
(
self
):
queryset
=
super
()
.
get_queryset
()
keyword
=
self
.
request
.
GET
.
get
(
"q"
)
order
=
self
.
request
.
GET
.
get
(
"o"
)
Librarians
.
objects
.
create
(
name
=
name
,
email
=
email
,
password
=
hashed_password
)
if
request
.
method
==
"GET"
:
keyword
=
request
.
GET
.
get
(
"q"
)
order
=
request
.
GET
.
get
(
"o"
)
if
keyword
is
not
None
:
filtered_book_list
=
Librarians
.
objects
.
filter
(
if
keyword
:
queryset
=
queryset
.
filter
(
Q
(
name__icontains
=
keyword
)
|
Q
(
email__icontains
=
keyword
)
)
.
order_by
(
"-created_at"
)
context
[
"librarians"
]
=
filtered_book_list
if
order
==
"new"
:
context
[
"librarians"
]
=
Librarians
.
objects
.
all
()
.
order_by
(
"-updated_at"
)[
:
10
]
elif
order
==
"old"
:
context
[
"librarians"
]
=
Librarians
.
objects
.
all
()
.
order_by
(
"updated_at"
)
return
render
(
request
,
"librarians.html"
,
context
)
def
update
(
request
,
id
):
latest_librarian_list
=
Librarians
.
objects
.
order_by
(
"created_at"
)
context
=
{
"librarians"
:
latest_librarian_list
}
librarian
=
Librarians
.
objects
.
get
(
id
=
id
)
initial
=
{
"name"
:
librarian
.
name
,
"email"
:
librarian
.
email
,
}
form
=
LibrarianForm
(
request
.
POST
or
None
,
initial
=
initial
)
if
request
.
method
==
"POST"
:
if
form
.
is_valid
:
name
=
form
.
data
[
"name"
]
email
=
form
.
data
[
"email"
]
password
=
form
.
data
[
"password"
]
hashed_password
=
Hasher
.
encode
(
password
=
password
)
librarian
=
Librarians
.
objects
.
filter
(
id
=
id
)
librarian
.
update
(
name
=
name
,
email
=
email
,
password
=
hashed_password
,
updated_at
=
datetime
.
now
(),
)
if
order
:
if
order
==
"new"
:
queryset
=
queryset
.
order_by
(
"-created_at"
)
elif
order
==
"old"
:
queryset
=
queryset
.
order_by
(
"created_at"
)
return
HttpResponseRedirect
(
"/dashboard/librarians"
)
return
queryset
context
[
"form"
]
=
form
context
[
"librarian_id"
]
=
id
return
render
(
request
,
"librarians_update_form.html"
,
context
)
class
LibrarianCreateView
(
generic
.
edit
.
CreateView
):
model
=
Librarians
form_class
=
LibrarianForm
success_url
=
"/dashboard/librarians/"
template_name
=
"librarians_create_form.html"
success_message
=
"Librarian created successfully!"
def
delete
(
request
,
id
):
context
=
{}
librarian
=
get_object_or_404
(
Librarians
,
id
=
id
)
if
request
.
method
==
"POST"
:
librarian
.
delete
()
class
LibrarianUpdateView
(
generic
.
edit
.
UpdateView
):
model
=
Librarians
form_class
=
LibrarianForm
success_url
=
"/dashboard/librarians"
template_name
=
"librarians_update_form.html"
success_message
=
"Librarian updated successfully!"
return
HttpResponseRedirect
(
"/dashboard/librarians"
)
return
render
(
request
,
"librarians.html"
,
context
)
class
LibrarianDeleteView
(
generic
.
edit
.
DeleteView
):
model
=
Librarians
success_url
=
"/dashboard/librarians"
template_name
=
"librarians_delete_form.html"
success_message
=
"Librarian deleted successfully!"
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