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
d4a0b8a7
Commit
d4a0b8a7
authored
Jul 15, 2024
by
Ilham Maulana
💻
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: book loans overview
parent
8e91d0ef
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
169 additions
and
2 deletions
+169
-2
urls.py
config/urls.py
+1
-0
forms.py
loans/forms.py
+49
-0
book_loan_table_data.html
loans/templates/book_loan_table_data.html
+46
-0
loans.html
loans/templates/loans.html
+12
-0
urls.py
loans/urls.py
+14
-0
views.py
loans/views.py
+47
-2
No files found.
config/urls.py
View file @
d4a0b8a7
...
...
@@ -26,6 +26,7 @@ urlpatterns = [
path
(
"dashboard/"
,
include
(
"dashboard.urls"
)),
path
(
"books/"
,
include
(
"book.urls"
)),
path
(
"users/"
,
include
(
"users.urls"
)),
path
(
"book-loans/"
,
include
(
"loans.urls"
)),
# api
path
(
"api/v1/"
,
include
(
"api.urls"
),
name
=
"API_V1"
),
# 3rd party
...
...
loans/forms.py
0 → 100644
View file @
d4a0b8a7
from
django
import
forms
from
loans.models
import
BookLoan
class
BookLoanForm
(
forms
.
ModelForm
):
class
Meta
:
model
=
BookLoan
fields
=
"__all__"
widgets
=
{
"book"
:
forms
.
Select
(
attrs
=
{
"class"
:
"form-control"
,
}
),
"member"
:
forms
.
Select
(
attrs
=
{
"class"
:
"form-control"
,
}
),
"librarian"
:
forms
.
Select
(
attrs
=
{
"class"
:
"form-control"
,
}
),
"loan_date"
:
forms
.
DateTimeInput
(
attrs
=
{
"type"
:
"datetime-local"
,
"class"
:
"form-control"
,
}
),
"due_date"
:
forms
.
DateTimeInput
(
attrs
=
{
"type"
:
"datetime-local"
,
"class"
:
"form-control"
,
}
),
"return_date"
:
forms
.
DateTimeInput
(
attrs
=
{
"type"
:
"datetime-local"
,
"class"
:
"form-control"
,
}
),
"notes"
:
forms
.
Textarea
(
attrs
=
{
"placeholder"
:
"Note"
,
"class"
:
"form-control"
,
}
),
}
loans/templates/book_loan_table_data.html
0 → 100644
View file @
d4a0b8a7
<table
class=
"table table-hover"
>
<thead>
<tr
class=
"table-primary"
>
<th
scope=
"col"
>
Book
</th>
<th
scope=
"col"
>
Member
</th>
<th
scope=
"col"
>
Loan Date
</th>
<th
scope=
"col"
>
Due Date
</th>
<th
scope=
"col"
>
Return Date
</th>
<th
scope=
"col"
></th>
</tr>
</thead>
<tbody>
{% if object_list %} {% for loan in object_list %}
<tr>
<td>
{{ loan.book.title }}
</td>
<td>
{{ loan.member.name }}
</td>
<td>
{{ loan.loan_date }}
</td>
<td>
{{ loan.due_date }}
</td>
<td>
{{ loan.return_date }}
</td>
<td
class=
"d-flex gap-2 py-4"
>
<a
class=
"btn btn-success"
href=
"/book-loans/{{ loan.id }}/"
>
<i
class=
"bi bi-pencil-square"
></i>
</a>
<a
class=
"btn btn-danger"
href=
"/book-loans/{{ loan.id }}/delete/"
>
<i
class=
"bi bi-trash3-fill"
></i>
</a>
</td>
</tr>
{% endfor %} {% else %}
<tr
class=
"w-100"
>
<td></td>
<td></td>
<td></td>
<td>
<p>
Data Empty
</p>
</td>
<td></td>
<td></td>
</tr>
{% endif %}
</tbody>
</table>
{% include "pagination.html" %}
loans/templates/loans.html
0 → 100644
View file @
d4a0b8a7
{% extends "layout.html" %} {% block dashboard %}
<div
class=
"w-100 p-4"
>
<div
class=
"d-flex gap-2 mb-4"
>
{% include "order_form.html" %}
<a
type=
"button"
class=
"btn btn-primary"
href=
"/book-loans/add/"
>
<i
class=
"bi bi-plus-circle"
></i>
Add Book Loan
</a>
{% include "search_form.html" %}
</div>
{% include "book_loan_table_data.html" %}
</div>
{% endblock dashboard %}
loans/urls.py
0 → 100644
View file @
d4a0b8a7
from
django.urls
import
path
from
.views
import
(
BookLoanListView
,
BookLoanCreateView
,
BookLoanUpdateView
,
BookLoanDeleteView
,
)
urlpatterns
=
[
path
(
""
,
BookLoanListView
.
as_view
(),
name
=
"book_loan_lists"
),
path
(
"add/"
,
BookLoanCreateView
.
as_view
(),
name
=
"add_book_loan"
),
path
(
"<int:pk>/"
,
BookLoanUpdateView
.
as_view
(),
name
=
"update_book_loan"
),
path
(
"<int:pk>/delete/"
,
BookLoanDeleteView
.
as_view
(),
name
=
"delete_book_loan"
),
]
loans/views.py
View file @
d4a0b8a7
from
django.shortcuts
import
render
from
django.db.models
import
Q
from
django.views
import
generic
from
.models
import
BookLoan
from
.forms
import
BookLoanForm
# Create your views here.
class
BookLoanListView
(
generic
.
ListView
):
model
=
BookLoan
template_name
=
"loans.html"
paginate_by
=
5
def
get_queryset
(
self
):
queryset
=
super
()
.
get_queryset
()
keyword
=
self
.
request
.
GET
.
get
(
"q"
)
order
=
self
.
request
.
GET
.
get
(
"o"
)
if
keyword
:
queryset
=
queryset
.
filter
(
Q
(
book__title__icontains
=
keyword
)
|
Q
(
member__name__icontains
=
keyword
)
)
.
order_by
(
"-loan_date"
)
if
order
:
if
order
==
"new"
:
queryset
=
queryset
.
order_by
(
"-loan_date"
)
elif
order
==
"old"
:
queryset
=
queryset
.
order_by
(
"loan_date"
)
return
queryset
.
order_by
(
"-loan_date"
)
class
BookLoanCreateView
(
generic
.
edit
.
CreateView
):
model
=
BookLoan
form_class
=
BookLoanForm
success_url
=
"/dashboard/book-loans/"
template_name
=
"form/create_form.html"
class
BookLoanUpdateView
(
generic
.
edit
.
UpdateView
):
model
=
BookLoan
form_class
=
BookLoanForm
success_url
=
"/dashboard/book-loans"
template_name
=
"form/update_form.html"
class
BookLoanDeleteView
(
generic
.
edit
.
DeleteView
):
model
=
BookLoan
success_url
=
"/dashboard/book-loans"
template_name
=
"form/delete_form.html"
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