Skip to content

Commit

Permalink
video end
Browse files Browse the repository at this point in the history
  • Loading branch information
NagariaHussain committed Feb 15, 2024
1 parent cf203b2 commit ec61211
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 0 deletions.
Empty file.
Empty file.
8 changes: 8 additions & 0 deletions htmx_portal/htmx_portal/doctype/book/book.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright (c) 2024, BWH and contributors
// For license information, please see license.txt

// frappe.ui.form.on("Book", {
// refresh(frm) {

// },
// });
45 changes: 45 additions & 0 deletions htmx_portal/htmx_portal/doctype/book/book.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"actions": [],
"allow_rename": 1,
"autoname": "prompt",
"creation": "2024-02-15 15:59:11.763852",
"doctype": "DocType",
"engine": "InnoDB",
"field_order": [
"author"
],
"fields": [
{
"fieldname": "author",
"fieldtype": "Data",
"in_list_view": 1,
"label": "Author",
"reqd": 1
}
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2024-02-15 15:59:37.277501",
"modified_by": "Administrator",
"module": "Htmx Portal",
"name": "Book",
"naming_rule": "Set by user",
"owner": "Administrator",
"permissions": [
{
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "System Manager",
"share": 1,
"write": 1
}
],
"sort_field": "modified",
"sort_order": "DESC",
"states": []
}
25 changes: 25 additions & 0 deletions htmx_portal/htmx_portal/doctype/book/book.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright (c) 2024, BWH and contributors
# For license information, please see license.txt

import frappe
from frappe.model.document import Document
from werkzeug.wrappers import Response


class Book(Document):
pass

@frappe.whitelist()
def new_book():
data = frappe.form_dict
book = frappe.new_doc("Book")
book.name = data.get("name")
book.author = data.get("author")
book.insert()

return books_list()

@frappe.whitelist()
def books_list():
books_list_html = frappe.render_template("templates/includes/book_list.html")
return Response(books_list_html)
9 changes: 9 additions & 0 deletions htmx_portal/htmx_portal/doctype/book/test_book.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright (c) 2024, BWH and Contributors
# See license.txt

# import frappe
from frappe.tests.utils import FrappeTestCase


class TestBook(FrappeTestCase):
pass
1 change: 1 addition & 0 deletions htmx_portal/public/js/htmx.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions htmx_portal/templates/includes/book_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{% set books = frappe.db.get_all("Book", fields=["name", "author"], order_by="creation desc") %}
<ol>
{% for book in books %}
<li>{{ book.name }} | {{ book.author }}</li>
{% endfor %}
</ol>
52 changes: 52 additions & 0 deletions htmx_portal/www/book-shelf.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Book Shelf</title>
<script src="/assets/htmx_portal/js/htmx.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.lime.min.css" />
</head>

<body class="container">
<nav>
<ul>
<li><strong>My Book Shelf</strong></li>
</ul>
<ul>
<li><a href="#">About</a></li>
</ul>
</nav>

<main class="grid">
<form hx-post="/api/v2/method/Book/new_book" hx-target="#book-list">
<fieldset>
<label>
Book Title
<input name="name" placeholder="Harry Potter..." required />
</label>
<label>
Author
<input name="author" placeholder="J.K. Rowling" required />
</label>
</fieldset>

<input type="submit" value="Create" />
</form>

<div>
<article id="book-list">
{% include "templates/includes/book_list.html" %}
</article>

<button
class="secondary"
hx-get="/api/v2/method/Book/books_list"
hx-target="#book-list">Refresh
</button>
</div>
</main>
</body>

</html>

0 comments on commit ec61211

Please sign in to comment.