staticdash 0.1.2__py3-none-any.whl → 0.1.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -98,3 +98,17 @@ tr:hover {
98
98
  width: 100% !important;
99
99
  height: auto !important;
100
100
  }
101
+
102
+ .download-button {
103
+ display: inline-block;
104
+ padding: 0.5em 1em;
105
+ margin: 1em 0;
106
+ background-color: #2c3e50;
107
+ color: white;
108
+ text-decoration: none;
109
+ border-radius: 5px;
110
+ font-weight: bold;
111
+ }
112
+ .download-button:hover {
113
+ background-color: #547a9f;
114
+ }
@@ -40,4 +40,4 @@ document.addEventListener("DOMContentLoaded", () => {
40
40
  if (sections.length > 0) {
41
41
  showPage(sections[0].id);
42
42
  }
43
- });
43
+ });
staticdash/dashboard.py CHANGED
@@ -26,6 +26,11 @@ class Page:
26
26
  table_id = f"table-{len(self.elements)}"
27
27
  html = df.to_html(classes="table-hover table-striped", index=False, border=0, table_id=table_id)
28
28
  self.elements.append(("table", (html, table_id)))
29
+
30
+ def add_download(self, file_path, label=None):
31
+ if not os.path.isfile(file_path):
32
+ raise FileNotFoundError(f"File not found: {file_path}")
33
+ self.elements.append(("download", (file_path, label)))
29
34
 
30
35
  def add(self, element):
31
36
  if isinstance(element, str):
@@ -59,15 +64,18 @@ class Dashboard:
59
64
  self.pages.append(page)
60
65
 
61
66
  def publish(self, output_dir="output"):
62
- os.makedirs(output_dir, exist_ok=True)
67
+ output_dir = os.path.abspath(output_dir)
63
68
  pages_dir = os.path.join(output_dir, "pages")
64
- os.makedirs(pages_dir, exist_ok=True)
65
-
66
- # Copy assets
69
+ downloads_dir = os.path.join(output_dir, "downloads")
67
70
  assets_src = os.path.join(os.path.dirname(__file__), "assets")
68
71
  assets_dst = os.path.join(output_dir, "assets")
72
+
73
+ # Ensure directories exist
74
+ os.makedirs(pages_dir, exist_ok=True)
75
+ os.makedirs(downloads_dir, exist_ok=True)
69
76
  shutil.copytree(assets_src, assets_dst, dirs_exist_ok=True)
70
77
 
78
+
71
79
  # Generate each page
72
80
  for page in self.pages:
73
81
  doc = document(title=page.title)
@@ -113,7 +121,34 @@ class Dashboard:
113
121
  elif kind == "table":
114
122
  table_html, _ = content
115
123
  div(raw_util(table_html))
124
+ # elif kind == "download":
125
+ # src_path, label = content
126
+ # file_uuid = f"{uuid.uuid4().hex}_{os.path.basename(src_path)}"
127
+ # dst_path = os.path.join(downloads_dir, file_uuid)
128
+ # shutil.copy2(src_path, dst_path)
129
+ # a(label or os.path.basename(src_path),
130
+ # href=f"{downloads_dir}/{file_uuid}",
131
+ # cls="download-button",
132
+ # download=True)
133
+ elif kind == "download":
134
+ src_path, label = content
135
+ file_uuid = f"{uuid.uuid4().hex}_{os.path.basename(src_path)}"
136
+ dst_path = os.path.join(downloads_dir, file_uuid)
137
+ shutil.copy2(src_path, dst_path)
138
+
139
+ # Use relative link from HTML to downloads/ folder
140
+ download_link = f"downloads/{file_uuid}"
141
+
142
+ # Create button and append it to the current div
143
+ btn = a(label or os.path.basename(src_path),
144
+ href=download_link,
145
+ cls="download-button",
146
+ download=True)
147
+
148
+ div(btn)
149
+ div(raw_util("<br>"))
150
+
116
151
 
117
152
 
118
153
  with open(os.path.join(output_dir, "index.html"), "w") as f:
119
- f.write(str(index_doc))
154
+ f.write(str(index_doc))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: staticdash
3
- Version: 0.1.2
3
+ Version: 0.1.4
4
4
  Summary: A lightweight static HTML dashboard generator with Plotly and pandas support.
5
5
  Author-email: Brian Day <brian.day1@gmail.com>
6
6
  License: CC0-1.0
@@ -70,10 +70,17 @@ page3 = Page("summary", "Summary")
70
70
  page3.add("Summary and notes can be added here.")
71
71
  page3.add("StaticDash is a lightweight static dashboard generator.")
72
72
 
73
+ # Page 4: Download
74
+ page4 = Page("download", "Download")
75
+ page4.add("Here is a button to download a file.")
76
+ page4.add_download('./test_file.txt', "Download File")
77
+ page4.add_download('./test_file2.txt', "Download Another File")
78
+
73
79
  # Register pages
74
80
  dashboard.add_page(page1)
75
81
  dashboard.add_page(page2)
76
82
  dashboard.add_page(page3)
83
+ dashboard.add_page(page4)
77
84
 
78
85
  # Export
79
86
  dashboard.publish(output_dir="output")
@@ -0,0 +1,8 @@
1
+ staticdash/__init__.py,sha256=KqViaDkiQnhBI8-j3hr14umLDmPgddvdB_G1nJeC5Xs,38
2
+ staticdash/dashboard.py,sha256=Pj5or33xXyOJCxyvOVQTs8rDuYcqOYBVy11Z7ViRUuo,6557
3
+ staticdash/assets/css/style.css,sha256=pXKDi54gcDaxF5ABji5zfAS3ckHK4DhQU0onSBKkmWo,1587
4
+ staticdash/assets/js/script.js,sha256=rAGEB9sgv8LGdpA1JLQwYAZVRimpEfFSELKb0fFeATI,1222
5
+ staticdash-0.1.4.dist-info/METADATA,sha256=Dv6QYAxvJ31nrdpqohJ8BTEkXTvN-9jCLfnp6LHPmcI,2409
6
+ staticdash-0.1.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
7
+ staticdash-0.1.4.dist-info/top_level.txt,sha256=3MzZU6SptkUkjcHV1cvPji0H4aRzPphLHnpStgGEcxM,11
8
+ staticdash-0.1.4.dist-info/RECORD,,
@@ -1,8 +0,0 @@
1
- staticdash/__init__.py,sha256=KqViaDkiQnhBI8-j3hr14umLDmPgddvdB_G1nJeC5Xs,38
2
- staticdash/dashboard.py,sha256=DFTPvqSOI00c2qVS4MvOyia1ly-Ph8-oSlbQDT9TSj8,4644
3
- staticdash/assets/css/style.css,sha256=OIcaUe9z3uQjfnisZiyxV-UodHQLq4kIWKxtq7BL2-Q,1315
4
- staticdash/assets/js/script.js,sha256=GA6dd--Z_gvsLylOHZX73FkPPkznuFzsFGYYKL-sDxM,1223
5
- staticdash-0.1.2.dist-info/METADATA,sha256=Mir0l0LNUGiusMsNv2lCOSB2y-sYwzmY10aUVUD5Gfg,2157
6
- staticdash-0.1.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
7
- staticdash-0.1.2.dist-info/top_level.txt,sha256=3MzZU6SptkUkjcHV1cvPji0H4aRzPphLHnpStgGEcxM,11
8
- staticdash-0.1.2.dist-info/RECORD,,