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
4ee10367
Commit
4ee10367
authored
Jul 01, 2024
by
impfundev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: CRUD Librarian
parent
82477bc6
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
276 additions
and
4 deletions
+276
-4
layout.html
dashboards/templates/layout.html
+1
-1
urls.py
dashboards/urls.py
+2
-1
forms.py
librarians/forms.py
+31
-0
librarians.html
librarians/templates/librarians.html
+17
-0
librarians_create_form.html
librarians/templates/librarians_create_form.html
+34
-0
librarians_delete_form.html
librarians/templates/librarians_delete_form.html
+38
-0
librarians_table_data.html
librarians/templates/librarians_table_data.html
+66
-0
librarians_update_form.html
librarians/templates/librarians_update_form.html
+19
-0
urls.py
librarians/urls.py
+8
-0
views.py
librarians/views.py
+60
-2
No files found.
dashboards/templates/layout.html
View file @
4ee10367
...
@@ -25,7 +25,7 @@
...
@@ -25,7 +25,7 @@
<a
<a
href=
"/dashboard/librarians"
href=
"/dashboard/librarians"
class=
"btn btn-outline-primary text-start w-100"
class=
"btn btn-outline-primary text-start w-100"
><i
class=
"bi bi-person-fill-lock"
></i>
Librarian
Access
</a
><i
class=
"bi bi-person-fill-lock"
></i>
Librarian
</a
>
>
</div>
</div>
</div>
</div>
...
...
dashboards/urls.py
View file @
4ee10367
from
django.urls
import
path
,
include
from
django.urls
import
path
,
include
from
dashboards.views
import
home
,
index
from
dashboards.views
import
index
urlpatterns
=
[
urlpatterns
=
[
path
(
""
,
index
,
name
=
"dashboard"
),
path
(
""
,
index
,
name
=
"dashboard"
),
path
(
"books/"
,
include
(
"books.urls"
)),
path
(
"books/"
,
include
(
"books.urls"
)),
path
(
"members/"
,
include
(
"members.urls"
)),
path
(
"members/"
,
include
(
"members.urls"
)),
path
(
"librarians/"
,
include
(
"librarians.urls"
)),
]
]
librarians/forms.py
0 → 100644
View file @
4ee10367
from
django
import
forms
class
LibrarianForm
(
forms
.
Form
):
name
=
forms
.
CharField
(
max_length
=
50
,
widget
=
forms
.
TextInput
(
attrs
=
{
"placeholder"
:
"Name"
,
"class"
:
"form-control"
,
}
),
)
email
=
forms
.
CharField
(
max_length
=
255
,
widget
=
forms
.
EmailInput
(
attrs
=
{
"placeholder"
:
"Email"
,
"class"
:
"form-control"
,
}
),
)
password
=
forms
.
CharField
(
max_length
=
255
,
widget
=
forms
.
TextInput
(
attrs
=
{
"placeholder"
:
"Password"
,
"class"
:
"form-control"
,
}
),
)
librarians/templates/librarians.html
0 → 100644
View file @
4ee10367
{% extends "layout.html" %} {% block dashboard %}
<div
style=
"max-width: 80vw"
class=
"w-100 p-4"
>
{% include "librarians_delete_form.html" %}
<div
class=
"d-flex flex-column gap-2 mb-4"
>
<button
type=
"button"
class=
"btn btn-primary"
data-bs-toggle=
"modal"
data-bs-target=
"#librarian_modal_create"
>
<i
class=
"bi bi-plus-circle"
></i>
Add Librarian
</button>
{% include "librarians_create_form.html" %}
</div>
{% include "librarians_table_data.html" %}
</div>
{% endblock dashboard %}
librarians/templates/librarians_create_form.html
0 → 100644
View file @
4ee10367
<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>
</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>
</div>
</form>
librarians/templates/librarians_delete_form.html
0 → 100644
View file @
4ee10367
{% 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>
<button
type=
"submit"
class=
"btn btn-danger"
>
Continue
</button>
</div>
</div>
</div>
</form>
{% endfor %}
librarians/templates/librarians_table_data.html
0 → 100644
View file @
4ee10367
<table
class=
"table table-hover"
>
<thead>
<tr
class=
"table-primary"
>
<th
scope=
"col"
>
<button
class=
"btn"
>
<i
class=
"bi bi-arrow-down-up"
></i>
</button>
Name
</th>
<th
scope=
"col"
>
<button
class=
"btn"
>
<i
class=
"bi bi-arrow-down-up"
></i>
</button>
Email
</th>
<th
scope=
"col"
>
<button
class=
"btn"
>
<i
class=
"bi bi-arrow-down-up"
></i>
</button>
Created At
</th>
<th
scope=
"col"
>
<button
class=
"btn"
>
<i
class=
"bi bi-arrow-down-up"
></i>
</button>
Updated At
</th>
<th
scope=
"col"
></th>
</tr>
</thead>
<tbody>
{% if librarians %} {% for librarian in librarians %}
<tr>
<td>
{{ librarian.name }}
</td>
<td>
{{ librarian.email }}
</td>
<td>
{{ librarian.created_at }}
</td>
<td>
{{ librarian.updated_at }}
</td>
<td
class=
"d-flex gap-2"
>
<a
class=
"btn btn-success"
href=
"/dashboard/librarians/{{ librarian.id }}/update/"
>
<i
class=
"bi bi-pencil-square"
></i>
</a>
<button
class=
"btn btn-danger"
data-bs-toggle=
"modal"
data-bs-target=
"#librarian_delete_modal_{{ librarian.id }}"
>
<i
class=
"bi bi-trash3-fill"
></i>
</button>
</td>
</tr>
{% endfor %} {% else %}
<tr
class=
"w-100"
>
<td></td>
<td></td>
<td>
<p>
Data Empty
</p>
</td>
<td></td>
<td></td>
</tr>
{% endif %}
</tbody>
</table>
librarians/templates/librarians_update_form.html
0 → 100644
View file @
4ee10367
{% 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"
>
Update Data
</h1>
<form
id=
"librarian_update_modal_{{ librarian_id }}"
action=
"/dashboard/librarians/{{ librarian_id }}/update/"
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>
</form>
</div>
</div>
{% endblock dashboard %}
librarians/urls.py
0 → 100644
View file @
4ee10367
from
django.urls
import
path
from
librarians.views
import
index
,
update
,
delete
urlpatterns
=
[
path
(
""
,
index
,
name
=
"librarian_lists"
),
path
(
"<id>/update/"
,
update
,
name
=
"update_librarian"
),
path
(
"<id>/delete/"
,
delete
,
name
=
"delete_librarian"
),
]
librarians/views.py
View file @
4ee10367
from
django.shortcuts
import
render
from
django.shortcuts
import
get_object_or_404
,
render
from
django.http
import
HttpResponseRedirect
from
datetime
import
datetime
# Create your views here.
from
librarians.models
import
Librarians
from
librarians.forms
import
LibrarianForm
def
index
(
request
):
latest_librarian_list
=
Librarians
.
objects
.
order_by
(
"created_at"
)[:
10
]
context
=
{
"librarians"
:
latest_librarian_list
,
"form"
:
LibrarianForm
()}
if
request
.
method
==
"POST"
:
form
=
LibrarianForm
(
request
.
POST
)
if
form
.
is_valid
:
name
=
form
.
data
[
"name"
]
email
=
form
.
data
[
"email"
]
password
=
form
.
data
[
"password"
]
Librarians
.
objects
.
create
(
name
=
name
,
email
=
email
,
password
=
password
)
return
render
(
request
,
"librarians.html"
,
context
)
def
update
(
request
,
id
):
latest_librarian_list
=
Librarians
.
objects
.
order_by
(
"created_at"
)[:
10
]
context
=
{
"librarians"
:
latest_librarian_list
}
librarian
=
Librarians
.
objects
.
get
(
id
=
id
)
initial
=
{
"name"
:
librarian
.
name
,
"email"
:
librarian
.
email
,
"password"
:
librarian
.
password
,
}
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"
]
librarian
=
Librarians
.
objects
.
filter
(
id
=
id
)
librarian
.
update
(
name
=
name
,
email
=
email
,
password
=
password
,
updated_at
=
datetime
.
now
()
)
return
HttpResponseRedirect
(
"/dashboard/librarians"
)
context
[
"form"
]
=
form
context
[
"librarian_id"
]
=
id
return
render
(
request
,
"librarians_update_form.html"
,
context
)
def
delete
(
request
,
id
):
context
=
{}
librarian
=
get_object_or_404
(
Librarians
,
id
=
id
)
if
request
.
method
==
"POST"
:
librarian
.
delete
()
return
HttpResponseRedirect
(
"/dashboard/librarians"
)
return
render
(
request
,
"librarians.html"
,
context
)
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