Revize 4911f0ea
Přidáno uživatelem Matěj Zeman před téměř 3 roky(ů)
server/doc/sql_app/api/devices.html | ||
---|---|---|
1 |
<!doctype html> |
|
2 |
<html lang="en"> |
|
3 |
<head> |
|
4 |
<meta charset="utf-8"> |
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" /> |
|
6 |
<meta name="generator" content="pdoc 0.10.0" /> |
|
7 |
<title>sql_app.api.devices API documentation</title> |
|
8 |
<meta name="description" content="" /> |
|
9 |
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/sanitize.min.css" integrity="sha256-PK9q560IAAa6WVRRh76LtCaI8pjTJ2z11v0miyNNjrs=" crossorigin> |
|
10 |
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/typography.min.css" integrity="sha256-7l/o7C8jubJiy74VsKTidCy1yBkRtiUGbVkYBylBqUg=" crossorigin> |
|
11 |
<link rel="stylesheet preload" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/styles/github.min.css" crossorigin> |
|
12 |
<style>:root{--highlight-color:#fe9}.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}#sidebar > *:last-child{margin-bottom:2cm}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}h1:target,h2:target,h3:target,h4:target,h5:target,h6:target{background:var(--highlight-color);padding:.2em 0}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{margin-top:.6em;font-weight:bold}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}dt:target .name{background:var(--highlight-color)}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}td{padding:0 .5em}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style> |
|
13 |
<style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%;height:100vh;overflow:auto;position:sticky;top:0}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style> |
|
14 |
<style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style> |
|
15 |
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/highlight.min.js" integrity="sha256-Uv3H6lx7dJmRfRvH8TH6kJD1TSK1aFcwgx+mdg3epi8=" crossorigin></script> |
|
16 |
<script>window.addEventListener('DOMContentLoaded', () => hljs.initHighlighting())</script> |
|
17 |
</head> |
|
18 |
<body> |
|
19 |
<main> |
|
20 |
<article id="content"> |
|
21 |
<header> |
|
22 |
<h1 class="title">Module <code>sql_app.api.devices</code></h1> |
|
23 |
</header> |
|
24 |
<section id="section-intro"> |
|
25 |
<details class="source"> |
|
26 |
<summary> |
|
27 |
<span>Expand source code</span> |
|
28 |
</summary> |
|
29 |
<pre><code class="python">from typing import List |
|
30 |
|
|
31 |
from fastapi import Depends, FastAPI, HTTPException, APIRouter |
|
32 |
from sqlalchemy.orm import Session |
|
33 |
from sql_app import crud, models, schemas |
|
34 |
from ..database import SessionLocal, engine |
|
35 |
|
|
36 |
models.Base.metadata.create_all(bind=engine) |
|
37 |
|
|
38 |
# prefix used for all endpoints in this file |
|
39 |
device = APIRouter(prefix="/api/v1") |
|
40 |
|
|
41 |
|
|
42 |
# Dependency |
|
43 |
def get_db(): |
|
44 |
db = SessionLocal() |
|
45 |
try: |
|
46 |
yield db |
|
47 |
finally: |
|
48 |
db.close() |
|
49 |
|
|
50 |
|
|
51 |
@device.post("/device", response_model=schemas.Device) |
|
52 |
def create_device(device: schemas.DeviceCreate, db: Session = Depends(get_db)): |
|
53 |
""" |
|
54 |
Endpoint used for creating new device |
|
55 |
""" |
|
56 |
print(crud.create_device(db=db, device=device)) |
|
57 |
|
|
58 |
|
|
59 |
@device.get("/devices", response_model=List[schemas.Device]) |
|
60 |
def read_devices(skip: int = 0, limit: int = 100, db: Session = Depends(get_db)): |
|
61 |
""" |
|
62 |
Endpoint returns all devices in database |
|
63 |
""" |
|
64 |
devices = crud.get_devices(db, skip=skip, limit=limit) |
|
65 |
return devices |
|
66 |
|
|
67 |
|
|
68 |
@device.get("/device/{device_id}", response_model=schemas.Device) |
|
69 |
def read_device(device_id: int, db: Session = Depends(get_db)): |
|
70 |
""" |
|
71 |
Returns one specific device by given id |
|
72 |
""" |
|
73 |
db_device = crud.get_device(db, device_id=device_id) |
|
74 |
if db_device is None: |
|
75 |
raise HTTPException(status_code=404, detail="Device not found") |
|
76 |
return db_device</code></pre> |
|
77 |
</details> |
|
78 |
</section> |
|
79 |
<section> |
|
80 |
</section> |
|
81 |
<section> |
|
82 |
</section> |
|
83 |
<section> |
|
84 |
<h2 class="section-title" id="header-functions">Functions</h2> |
|
85 |
<dl> |
|
86 |
<dt id="sql_app.api.devices.create_device"><code class="name flex"> |
|
87 |
<span>def <span class="ident">create_device</span></span>(<span>device: <a title="sql_app.schemas.DeviceCreate" href="../schemas.html#sql_app.schemas.DeviceCreate">DeviceCreate</a>, db: sqlalchemy.orm.session.Session = Depends(get_db))</span> |
|
88 |
</code></dt> |
|
89 |
<dd> |
|
90 |
<div class="desc"><p>Endpoint used for creating new device</p></div> |
|
91 |
<details class="source"> |
|
92 |
<summary> |
|
93 |
<span>Expand source code</span> |
|
94 |
</summary> |
|
95 |
<pre><code class="python">@device.post("/device", response_model=schemas.Device) |
|
96 |
def create_device(device: schemas.DeviceCreate, db: Session = Depends(get_db)): |
|
97 |
""" |
|
98 |
Endpoint used for creating new device |
|
99 |
""" |
|
100 |
print(crud.create_device(db=db, device=device))</code></pre> |
|
101 |
</details> |
|
102 |
</dd> |
|
103 |
<dt id="sql_app.api.devices.get_db"><code class="name flex"> |
|
104 |
<span>def <span class="ident">get_db</span></span>(<span>)</span> |
|
105 |
</code></dt> |
|
106 |
<dd> |
|
107 |
<div class="desc"></div> |
|
108 |
<details class="source"> |
|
109 |
<summary> |
|
110 |
<span>Expand source code</span> |
|
111 |
</summary> |
|
112 |
<pre><code class="python">def get_db(): |
|
113 |
db = SessionLocal() |
|
114 |
try: |
|
115 |
yield db |
|
116 |
finally: |
|
117 |
db.close()</code></pre> |
|
118 |
</details> |
|
119 |
</dd> |
|
120 |
<dt id="sql_app.api.devices.read_device"><code class="name flex"> |
|
121 |
<span>def <span class="ident">read_device</span></span>(<span>device_id: int, db: sqlalchemy.orm.session.Session = Depends(get_db))</span> |
|
122 |
</code></dt> |
|
123 |
<dd> |
|
124 |
<div class="desc"><p>Returns one specific device by given id</p></div> |
|
125 |
<details class="source"> |
|
126 |
<summary> |
|
127 |
<span>Expand source code</span> |
|
128 |
</summary> |
|
129 |
<pre><code class="python">@device.get("/device/{device_id}", response_model=schemas.Device) |
|
130 |
def read_device(device_id: int, db: Session = Depends(get_db)): |
|
131 |
""" |
|
132 |
Returns one specific device by given id |
|
133 |
""" |
|
134 |
db_device = crud.get_device(db, device_id=device_id) |
|
135 |
if db_device is None: |
|
136 |
raise HTTPException(status_code=404, detail="Device not found") |
|
137 |
return db_device</code></pre> |
|
138 |
</details> |
|
139 |
</dd> |
|
140 |
<dt id="sql_app.api.devices.read_devices"><code class="name flex"> |
|
141 |
<span>def <span class="ident">read_devices</span></span>(<span>skip: int = 0, limit: int = 100, db: sqlalchemy.orm.session.Session = Depends(get_db))</span> |
|
142 |
</code></dt> |
|
143 |
<dd> |
|
144 |
<div class="desc"><p>Endpoint returns all devices in database</p></div> |
|
145 |
<details class="source"> |
|
146 |
<summary> |
|
147 |
<span>Expand source code</span> |
|
148 |
</summary> |
|
149 |
<pre><code class="python">@device.get("/devices", response_model=List[schemas.Device]) |
|
150 |
def read_devices(skip: int = 0, limit: int = 100, db: Session = Depends(get_db)): |
|
151 |
""" |
|
152 |
Endpoint returns all devices in database |
|
153 |
""" |
|
154 |
devices = crud.get_devices(db, skip=skip, limit=limit) |
|
155 |
return devices</code></pre> |
|
156 |
</details> |
|
157 |
</dd> |
|
158 |
</dl> |
|
159 |
</section> |
|
160 |
<section> |
|
161 |
</section> |
|
162 |
</article> |
|
163 |
<nav id="sidebar"> |
|
164 |
<h1>Index</h1> |
|
165 |
<div class="toc"> |
|
166 |
<ul></ul> |
|
167 |
</div> |
|
168 |
<ul id="index"> |
|
169 |
<li><h3>Super-module</h3> |
|
170 |
<ul> |
|
171 |
<li><code><a title="sql_app.api" href="index.html">sql_app.api</a></code></li> |
|
172 |
</ul> |
|
173 |
</li> |
|
174 |
<li><h3><a href="#header-functions">Functions</a></h3> |
|
175 |
<ul class=""> |
|
176 |
<li><code><a title="sql_app.api.devices.create_device" href="#sql_app.api.devices.create_device">create_device</a></code></li> |
|
177 |
<li><code><a title="sql_app.api.devices.get_db" href="#sql_app.api.devices.get_db">get_db</a></code></li> |
|
178 |
<li><code><a title="sql_app.api.devices.read_device" href="#sql_app.api.devices.read_device">read_device</a></code></li> |
|
179 |
<li><code><a title="sql_app.api.devices.read_devices" href="#sql_app.api.devices.read_devices">read_devices</a></code></li> |
|
180 |
</ul> |
|
181 |
</li> |
|
182 |
</ul> |
|
183 |
</nav> |
|
184 |
</main> |
|
185 |
<footer id="footer"> |
|
186 |
<p>Generated by <a href="https://pdoc3.github.io/pdoc" title="pdoc: Python API documentation generator"><cite>pdoc</cite> 0.10.0</a>.</p> |
|
187 |
</footer> |
|
188 |
</body> |
|
189 |
</html> |
server/doc/sql_app/api/devices_web.html | ||
---|---|---|
1 |
<!doctype html> |
|
2 |
<html lang="en"> |
|
3 |
<head> |
|
4 |
<meta charset="utf-8"> |
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" /> |
|
6 |
<meta name="generator" content="pdoc 0.10.0" /> |
|
7 |
<title>sql_app.api.devices_web API documentation</title> |
|
8 |
<meta name="description" content="" /> |
|
9 |
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/sanitize.min.css" integrity="sha256-PK9q560IAAa6WVRRh76LtCaI8pjTJ2z11v0miyNNjrs=" crossorigin> |
|
10 |
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/typography.min.css" integrity="sha256-7l/o7C8jubJiy74VsKTidCy1yBkRtiUGbVkYBylBqUg=" crossorigin> |
|
11 |
<link rel="stylesheet preload" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/styles/github.min.css" crossorigin> |
|
12 |
<style>:root{--highlight-color:#fe9}.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}#sidebar > *:last-child{margin-bottom:2cm}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}h1:target,h2:target,h3:target,h4:target,h5:target,h6:target{background:var(--highlight-color);padding:.2em 0}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{margin-top:.6em;font-weight:bold}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}dt:target .name{background:var(--highlight-color)}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}td{padding:0 .5em}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style> |
|
13 |
<style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%;height:100vh;overflow:auto;position:sticky;top:0}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style> |
|
14 |
<style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style> |
|
15 |
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/highlight.min.js" integrity="sha256-Uv3H6lx7dJmRfRvH8TH6kJD1TSK1aFcwgx+mdg3epi8=" crossorigin></script> |
|
16 |
<script>window.addEventListener('DOMContentLoaded', () => hljs.initHighlighting())</script> |
|
17 |
</head> |
|
18 |
<body> |
|
19 |
<main> |
|
20 |
<article id="content"> |
|
21 |
<header> |
|
22 |
<h1 class="title">Module <code>sql_app.api.devices_web</code></h1> |
|
23 |
</header> |
|
24 |
<section id="section-intro"> |
|
25 |
<details class="source"> |
|
26 |
<summary> |
|
27 |
<span>Expand source code</span> |
|
28 |
</summary> |
|
29 |
<pre><code class="python">from typing import List |
|
30 |
|
|
31 |
from fastapi import Depends, FastAPI, HTTPException, APIRouter, Form |
|
32 |
from sqlalchemy.orm import Session |
|
33 |
from sql_app import crud, models, schemas |
|
34 |
from datetime import datetime |
|
35 |
from ..database import SessionLocal, engine |
|
36 |
from fastapi import FastAPI, Request |
|
37 |
from fastapi.responses import HTMLResponse |
|
38 |
from fastapi.staticfiles import StaticFiles |
|
39 |
from fastapi.templating import Jinja2Templates |
|
40 |
|
|
41 |
models.Base.metadata.create_all(bind=engine) |
|
42 |
|
|
43 |
# Path to html templates used in this file |
|
44 |
templates = Jinja2Templates(directory="../templates/devices") |
|
45 |
|
|
46 |
# prefix used for all endpoints in this file |
|
47 |
device_web = APIRouter(prefix="/api/v1") |
|
48 |
|
|
49 |
|
|
50 |
# Dependency |
|
51 |
def get_db(): |
|
52 |
db = SessionLocal() |
|
53 |
try: |
|
54 |
yield db |
|
55 |
finally: |
|
56 |
db.close() |
|
57 |
|
|
58 |
|
|
59 |
@device_web.get("/devices-web", response_class=HTMLResponse) |
|
60 |
async def read_devices(request: Request, skip: int = 0, limit: int = 100, db: Session = Depends(get_db)): |
|
61 |
""" |
|
62 |
Returns template with all devices and its current states |
|
63 |
""" |
|
64 |
devices = crud.get_devices(db, skip=skip, limit=limit) |
|
65 |
statuses = [] |
|
66 |
# adding state for each device in list |
|
67 |
for i in range(0, len(devices)): |
|
68 |
statuses.append(devices[i].logs[len(devices[i].logs)-1].status) |
|
69 |
licenses = crud.get_licenses(db, skip=skip, limit=limit) |
|
70 |
return templates.TemplateResponse("devices.html", {"request": request, "devs": len(devices), "devices": devices, |
|
71 |
"statuses": statuses, "licenses": licenses}) |
|
72 |
|
|
73 |
|
|
74 |
@device_web.post("/devices-web", response_class=HTMLResponse) |
|
75 |
async def filter_devices(request: Request, skip: int = 0, limit: int = 100, lic: str = Form("all"), |
|
76 |
db: Session = Depends(get_db)): |
|
77 |
""" |
|
78 |
Endpoint used for filtering devices by license. returns html template with only |
|
79 |
devices that has assigned license defined by user input |
|
80 |
""" |
|
81 |
devices = crud.get_devices(db, skip=skip, limit=limit) |
|
82 |
def_devices = [] |
|
83 |
for dev in devices: |
|
84 |
for l in dev.licenses: |
|
85 |
if dev not in def_devices and l.licenses.name == lic: |
|
86 |
def_devices.append(dev) |
|
87 |
# if input was default all |
|
88 |
if lic == "all": |
|
89 |
def_devices = devices |
|
90 |
statuses = [] |
|
91 |
for i in range(0, len(def_devices)): |
|
92 |
statuses.append(def_devices[i].logs[len(def_devices[i].logs) - 1].status) |
|
93 |
licenses = crud.get_licenses(db, skip=skip, limit=limit) |
|
94 |
return templates.TemplateResponse("devices.html", {"request": request, "devs": len(def_devices), "devices": def_devices, |
|
95 |
"statuses": statuses, "licenses": licenses}) |
|
96 |
|
|
97 |
|
|
98 |
@device_web.get("/device-license/{device_id}", response_class=HTMLResponse) |
|
99 |
async def connect_dev_lic(request: Request, device_id: int, db: Session = Depends(get_db)): |
|
100 |
""" |
|
101 |
Returns template with one device and all available licenses that can be assigned to it. |
|
102 |
""" |
|
103 |
device = crud.get_device(db, device_id) |
|
104 |
licenses = crud.get_licenses(db, 0, 100) |
|
105 |
return templates.TemplateResponse("devicelicense.html", |
|
106 |
{"request": request, "device": device, "licenses": licenses}) |
|
107 |
|
|
108 |
|
|
109 |
@device_web.post("/devices-web/{device_id}", response_class=HTMLResponse) |
|
110 |
async def connect_post(request: Request, device_id: int, lic: str = Form(...), skip: int = 0, limit: int = 100, |
|
111 |
db: Session = Depends(get_db)): |
|
112 |
""" |
|
113 |
Endpoint called from template for connecting device with license. Adds entry to devices_licenses |
|
114 |
table and returns template with all devices in database |
|
115 |
""" |
|
116 |
crud.create_device_license(db, device_id, int(lic), datetime.now()) |
|
117 |
devices = crud.get_devices(db, skip=skip, limit=limit) |
|
118 |
statuses = [] |
|
119 |
# adding state for each device in list |
|
120 |
for i in range(0, len(devices)): |
|
121 |
statuses.append(devices[i].logs[len(devices[i].logs) - 1].status) |
|
122 |
licenses = crud.get_licenses(db, skip=skip, limit=limit) |
|
123 |
return templates.TemplateResponse("devices.html", {"request": request, "devs": len(devices), "devices": devices, |
|
124 |
"statuses": statuses, "licenses": licenses})</code></pre> |
|
125 |
</details> |
|
126 |
</section> |
|
127 |
<section> |
|
128 |
</section> |
|
129 |
<section> |
|
130 |
</section> |
|
131 |
<section> |
|
132 |
<h2 class="section-title" id="header-functions">Functions</h2> |
|
133 |
<dl> |
|
134 |
<dt id="sql_app.api.devices_web.connect_dev_lic"><code class="name flex"> |
|
135 |
<span>async def <span class="ident">connect_dev_lic</span></span>(<span>request: starlette.requests.Request, device_id: int, db: sqlalchemy.orm.session.Session = Depends(get_db))</span> |
|
136 |
</code></dt> |
|
137 |
<dd> |
|
138 |
<div class="desc"><p>Returns template with one device and all available licenses that can be assigned to it.</p></div> |
|
139 |
<details class="source"> |
|
140 |
<summary> |
|
141 |
<span>Expand source code</span> |
|
142 |
</summary> |
|
143 |
<pre><code class="python">@device_web.get("/device-license/{device_id}", response_class=HTMLResponse) |
|
144 |
async def connect_dev_lic(request: Request, device_id: int, db: Session = Depends(get_db)): |
|
145 |
""" |
|
146 |
Returns template with one device and all available licenses that can be assigned to it. |
|
147 |
""" |
|
148 |
device = crud.get_device(db, device_id) |
|
149 |
licenses = crud.get_licenses(db, 0, 100) |
|
150 |
return templates.TemplateResponse("devicelicense.html", |
|
151 |
{"request": request, "device": device, "licenses": licenses})</code></pre> |
|
152 |
</details> |
|
153 |
</dd> |
|
154 |
<dt id="sql_app.api.devices_web.connect_post"><code class="name flex"> |
|
155 |
<span>async def <span class="ident">connect_post</span></span>(<span>request: starlette.requests.Request, device_id: int, lic: str = Form(Ellipsis), skip: int = 0, limit: int = 100, db: sqlalchemy.orm.session.Session = Depends(get_db))</span> |
|
156 |
</code></dt> |
|
157 |
<dd> |
|
158 |
<div class="desc"><p>Endpoint called from template for connecting device with license. Adds entry to devices_licenses |
|
159 |
table and returns template with all devices in database</p></div> |
|
160 |
<details class="source"> |
|
161 |
<summary> |
|
162 |
<span>Expand source code</span> |
|
163 |
</summary> |
|
164 |
<pre><code class="python">@device_web.post("/devices-web/{device_id}", response_class=HTMLResponse) |
|
165 |
async def connect_post(request: Request, device_id: int, lic: str = Form(...), skip: int = 0, limit: int = 100, |
|
166 |
db: Session = Depends(get_db)): |
|
167 |
""" |
|
168 |
Endpoint called from template for connecting device with license. Adds entry to devices_licenses |
|
169 |
table and returns template with all devices in database |
|
170 |
""" |
|
171 |
crud.create_device_license(db, device_id, int(lic), datetime.now()) |
|
172 |
devices = crud.get_devices(db, skip=skip, limit=limit) |
|
173 |
statuses = [] |
|
174 |
# adding state for each device in list |
|
175 |
for i in range(0, len(devices)): |
|
176 |
statuses.append(devices[i].logs[len(devices[i].logs) - 1].status) |
|
177 |
licenses = crud.get_licenses(db, skip=skip, limit=limit) |
|
178 |
return templates.TemplateResponse("devices.html", {"request": request, "devs": len(devices), "devices": devices, |
|
179 |
"statuses": statuses, "licenses": licenses})</code></pre> |
|
180 |
</details> |
|
181 |
</dd> |
|
182 |
<dt id="sql_app.api.devices_web.filter_devices"><code class="name flex"> |
|
183 |
<span>async def <span class="ident">filter_devices</span></span>(<span>request: starlette.requests.Request, skip: int = 0, limit: int = 100, lic: str = Form(all), db: sqlalchemy.orm.session.Session = Depends(get_db))</span> |
|
184 |
</code></dt> |
|
185 |
<dd> |
|
186 |
<div class="desc"><p>Endpoint used for filtering devices by license. returns html template with only |
|
187 |
devices that has assigned license defined by user input</p></div> |
|
188 |
<details class="source"> |
|
189 |
<summary> |
|
190 |
<span>Expand source code</span> |
|
191 |
</summary> |
|
192 |
<pre><code class="python">@device_web.post("/devices-web", response_class=HTMLResponse) |
|
193 |
async def filter_devices(request: Request, skip: int = 0, limit: int = 100, lic: str = Form("all"), |
|
194 |
db: Session = Depends(get_db)): |
|
195 |
""" |
|
196 |
Endpoint used for filtering devices by license. returns html template with only |
|
197 |
devices that has assigned license defined by user input |
|
198 |
""" |
|
199 |
devices = crud.get_devices(db, skip=skip, limit=limit) |
|
200 |
def_devices = [] |
|
201 |
for dev in devices: |
|
202 |
for l in dev.licenses: |
|
203 |
if dev not in def_devices and l.licenses.name == lic: |
|
204 |
def_devices.append(dev) |
|
205 |
# if input was default all |
|
206 |
if lic == "all": |
|
207 |
def_devices = devices |
|
208 |
statuses = [] |
|
209 |
for i in range(0, len(def_devices)): |
|
210 |
statuses.append(def_devices[i].logs[len(def_devices[i].logs) - 1].status) |
|
211 |
licenses = crud.get_licenses(db, skip=skip, limit=limit) |
|
212 |
return templates.TemplateResponse("devices.html", {"request": request, "devs": len(def_devices), "devices": def_devices, |
|
213 |
"statuses": statuses, "licenses": licenses})</code></pre> |
|
214 |
</details> |
|
215 |
</dd> |
|
216 |
<dt id="sql_app.api.devices_web.get_db"><code class="name flex"> |
|
217 |
<span>def <span class="ident">get_db</span></span>(<span>)</span> |
|
218 |
</code></dt> |
|
219 |
<dd> |
|
220 |
<div class="desc"></div> |
|
221 |
<details class="source"> |
|
222 |
<summary> |
|
223 |
<span>Expand source code</span> |
|
224 |
</summary> |
|
225 |
<pre><code class="python">def get_db(): |
|
226 |
db = SessionLocal() |
|
227 |
try: |
|
228 |
yield db |
|
229 |
finally: |
|
230 |
db.close()</code></pre> |
|
231 |
</details> |
|
232 |
</dd> |
|
233 |
<dt id="sql_app.api.devices_web.read_devices"><code class="name flex"> |
|
234 |
<span>async def <span class="ident">read_devices</span></span>(<span>request: starlette.requests.Request, skip: int = 0, limit: int = 100, db: sqlalchemy.orm.session.Session = Depends(get_db))</span> |
|
235 |
</code></dt> |
|
236 |
<dd> |
|
237 |
<div class="desc"><p>Returns template with all devices and its current states</p></div> |
|
238 |
<details class="source"> |
|
239 |
<summary> |
|
240 |
<span>Expand source code</span> |
|
241 |
</summary> |
|
242 |
<pre><code class="python">@device_web.get("/devices-web", response_class=HTMLResponse) |
|
243 |
async def read_devices(request: Request, skip: int = 0, limit: int = 100, db: Session = Depends(get_db)): |
|
244 |
""" |
|
245 |
Returns template with all devices and its current states |
|
246 |
""" |
|
247 |
devices = crud.get_devices(db, skip=skip, limit=limit) |
|
248 |
statuses = [] |
|
249 |
# adding state for each device in list |
|
250 |
for i in range(0, len(devices)): |
|
251 |
statuses.append(devices[i].logs[len(devices[i].logs)-1].status) |
|
252 |
licenses = crud.get_licenses(db, skip=skip, limit=limit) |
|
253 |
return templates.TemplateResponse("devices.html", {"request": request, "devs": len(devices), "devices": devices, |
|
254 |
"statuses": statuses, "licenses": licenses})</code></pre> |
|
255 |
</details> |
|
256 |
</dd> |
|
257 |
</dl> |
|
258 |
</section> |
|
259 |
<section> |
|
260 |
</section> |
|
261 |
</article> |
|
262 |
<nav id="sidebar"> |
|
263 |
<h1>Index</h1> |
|
264 |
<div class="toc"> |
|
265 |
<ul></ul> |
|
266 |
</div> |
|
267 |
<ul id="index"> |
|
268 |
<li><h3>Super-module</h3> |
|
269 |
<ul> |
|
270 |
<li><code><a title="sql_app.api" href="index.html">sql_app.api</a></code></li> |
|
271 |
</ul> |
|
272 |
</li> |
|
273 |
<li><h3><a href="#header-functions">Functions</a></h3> |
|
274 |
<ul class=""> |
|
275 |
<li><code><a title="sql_app.api.devices_web.connect_dev_lic" href="#sql_app.api.devices_web.connect_dev_lic">connect_dev_lic</a></code></li> |
|
276 |
<li><code><a title="sql_app.api.devices_web.connect_post" href="#sql_app.api.devices_web.connect_post">connect_post</a></code></li> |
|
277 |
<li><code><a title="sql_app.api.devices_web.filter_devices" href="#sql_app.api.devices_web.filter_devices">filter_devices</a></code></li> |
|
278 |
<li><code><a title="sql_app.api.devices_web.get_db" href="#sql_app.api.devices_web.get_db">get_db</a></code></li> |
|
279 |
<li><code><a title="sql_app.api.devices_web.read_devices" href="#sql_app.api.devices_web.read_devices">read_devices</a></code></li> |
|
280 |
</ul> |
|
281 |
</li> |
|
282 |
</ul> |
|
283 |
</nav> |
|
284 |
</main> |
|
285 |
<footer id="footer"> |
|
286 |
<p>Generated by <a href="https://pdoc3.github.io/pdoc" title="pdoc: Python API documentation generator"><cite>pdoc</cite> 0.10.0</a>.</p> |
|
287 |
</footer> |
|
288 |
</body> |
|
289 |
</html> |
server/doc/sql_app/api/index.html | ||
---|---|---|
1 |
<!doctype html> |
|
2 |
<html lang="en"> |
|
3 |
<head> |
|
4 |
<meta charset="utf-8"> |
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" /> |
|
6 |
<meta name="generator" content="pdoc 0.10.0" /> |
|
7 |
<title>sql_app.api API documentation</title> |
|
8 |
<meta name="description" content="" /> |
|
9 |
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/sanitize.min.css" integrity="sha256-PK9q560IAAa6WVRRh76LtCaI8pjTJ2z11v0miyNNjrs=" crossorigin> |
|
10 |
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/typography.min.css" integrity="sha256-7l/o7C8jubJiy74VsKTidCy1yBkRtiUGbVkYBylBqUg=" crossorigin> |
|
11 |
<link rel="stylesheet preload" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/styles/github.min.css" crossorigin> |
|
12 |
<style>:root{--highlight-color:#fe9}.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}#sidebar > *:last-child{margin-bottom:2cm}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}h1:target,h2:target,h3:target,h4:target,h5:target,h6:target{background:var(--highlight-color);padding:.2em 0}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{margin-top:.6em;font-weight:bold}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}dt:target .name{background:var(--highlight-color)}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}td{padding:0 .5em}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style> |
|
13 |
<style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%;height:100vh;overflow:auto;position:sticky;top:0}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style> |
|
14 |
<style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style> |
|
15 |
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/highlight.min.js" integrity="sha256-Uv3H6lx7dJmRfRvH8TH6kJD1TSK1aFcwgx+mdg3epi8=" crossorigin></script> |
|
16 |
<script>window.addEventListener('DOMContentLoaded', () => hljs.initHighlighting())</script> |
|
17 |
</head> |
|
18 |
<body> |
|
19 |
<main> |
|
20 |
<article id="content"> |
|
21 |
<header> |
|
22 |
<h1 class="title">Module <code>sql_app.api</code></h1> |
|
23 |
</header> |
|
24 |
<section id="section-intro"> |
|
25 |
</section> |
|
26 |
<section> |
|
27 |
<h2 class="section-title" id="header-submodules">Sub-modules</h2> |
|
28 |
<dl> |
|
29 |
<dt><code class="name"><a title="sql_app.api.devices" href="devices.html">sql_app.api.devices</a></code></dt> |
|
30 |
<dd> |
|
31 |
<div class="desc"></div> |
|
32 |
</dd> |
|
33 |
<dt><code class="name"><a title="sql_app.api.devices_web" href="devices_web.html">sql_app.api.devices_web</a></code></dt> |
|
34 |
<dd> |
|
35 |
<div class="desc"></div> |
|
36 |
</dd> |
|
37 |
<dt><code class="name"><a title="sql_app.api.licenses" href="licenses.html">sql_app.api.licenses</a></code></dt> |
|
38 |
<dd> |
|
39 |
<div class="desc"></div> |
|
40 |
</dd> |
|
41 |
<dt><code class="name"><a title="sql_app.api.licenses_web" href="licenses_web.html">sql_app.api.licenses_web</a></code></dt> |
|
42 |
<dd> |
|
43 |
<div class="desc"></div> |
|
44 |
</dd> |
|
45 |
<dt><code class="name"><a title="sql_app.api.pcs" href="pcs.html">sql_app.api.pcs</a></code></dt> |
|
46 |
<dd> |
|
47 |
<div class="desc"></div> |
|
48 |
</dd> |
|
49 |
<dt><code class="name"><a title="sql_app.api.pcs_web" href="pcs_web.html">sql_app.api.pcs_web</a></code></dt> |
|
50 |
<dd> |
|
51 |
<div class="desc"></div> |
|
52 |
</dd> |
|
53 |
<dt><code class="name"><a title="sql_app.api.teams" href="teams.html">sql_app.api.teams</a></code></dt> |
|
54 |
<dd> |
|
55 |
<div class="desc"></div> |
|
56 |
</dd> |
|
57 |
<dt><code class="name"><a title="sql_app.api.teams_web" href="teams_web.html">sql_app.api.teams_web</a></code></dt> |
|
58 |
<dd> |
|
59 |
<div class="desc"></div> |
|
60 |
</dd> |
|
61 |
<dt><code class="name"><a title="sql_app.api.usb_logs" href="usb_logs.html">sql_app.api.usb_logs</a></code></dt> |
|
62 |
<dd> |
|
63 |
<div class="desc"></div> |
|
64 |
</dd> |
|
65 |
<dt><code class="name"><a title="sql_app.api.usb_logs_web" href="usb_logs_web.html">sql_app.api.usb_logs_web</a></code></dt> |
|
66 |
<dd> |
|
67 |
<div class="desc"></div> |
|
68 |
</dd> |
|
69 |
</dl> |
|
70 |
</section> |
|
71 |
<section> |
|
72 |
</section> |
|
73 |
<section> |
|
74 |
</section> |
|
75 |
<section> |
|
76 |
</section> |
|
77 |
</article> |
|
78 |
<nav id="sidebar"> |
|
79 |
<h1>Index</h1> |
|
80 |
<div class="toc"> |
|
81 |
<ul></ul> |
|
82 |
</div> |
|
83 |
<ul id="index"> |
|
84 |
<li><h3>Super-module</h3> |
|
85 |
<ul> |
|
86 |
<li><code><a title="sql_app" href="../index.html">sql_app</a></code></li> |
|
87 |
</ul> |
|
88 |
</li> |
|
89 |
<li><h3><a href="#header-submodules">Sub-modules</a></h3> |
|
90 |
<ul> |
|
91 |
<li><code><a title="sql_app.api.devices" href="devices.html">sql_app.api.devices</a></code></li> |
|
92 |
<li><code><a title="sql_app.api.devices_web" href="devices_web.html">sql_app.api.devices_web</a></code></li> |
|
93 |
<li><code><a title="sql_app.api.licenses" href="licenses.html">sql_app.api.licenses</a></code></li> |
|
94 |
<li><code><a title="sql_app.api.licenses_web" href="licenses_web.html">sql_app.api.licenses_web</a></code></li> |
|
95 |
<li><code><a title="sql_app.api.pcs" href="pcs.html">sql_app.api.pcs</a></code></li> |
|
96 |
<li><code><a title="sql_app.api.pcs_web" href="pcs_web.html">sql_app.api.pcs_web</a></code></li> |
|
97 |
<li><code><a title="sql_app.api.teams" href="teams.html">sql_app.api.teams</a></code></li> |
|
98 |
<li><code><a title="sql_app.api.teams_web" href="teams_web.html">sql_app.api.teams_web</a></code></li> |
|
99 |
<li><code><a title="sql_app.api.usb_logs" href="usb_logs.html">sql_app.api.usb_logs</a></code></li> |
|
100 |
<li><code><a title="sql_app.api.usb_logs_web" href="usb_logs_web.html">sql_app.api.usb_logs_web</a></code></li> |
|
101 |
</ul> |
|
102 |
</li> |
|
103 |
</ul> |
|
104 |
</nav> |
|
105 |
</main> |
|
106 |
<footer id="footer"> |
|
107 |
<p>Generated by <a href="https://pdoc3.github.io/pdoc" title="pdoc: Python API documentation generator"><cite>pdoc</cite> 0.10.0</a>.</p> |
|
108 |
</footer> |
|
109 |
</body> |
|
110 |
</html> |
server/doc/sql_app/api/licenses.html | ||
---|---|---|
1 |
<!doctype html> |
|
2 |
<html lang="en"> |
|
3 |
<head> |
|
4 |
<meta charset="utf-8"> |
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" /> |
|
6 |
<meta name="generator" content="pdoc 0.10.0" /> |
|
7 |
<title>sql_app.api.licenses API documentation</title> |
|
8 |
<meta name="description" content="" /> |
|
9 |
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/sanitize.min.css" integrity="sha256-PK9q560IAAa6WVRRh76LtCaI8pjTJ2z11v0miyNNjrs=" crossorigin> |
|
10 |
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/typography.min.css" integrity="sha256-7l/o7C8jubJiy74VsKTidCy1yBkRtiUGbVkYBylBqUg=" crossorigin> |
|
11 |
<link rel="stylesheet preload" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/styles/github.min.css" crossorigin> |
|
12 |
<style>:root{--highlight-color:#fe9}.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}#sidebar > *:last-child{margin-bottom:2cm}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}h1:target,h2:target,h3:target,h4:target,h5:target,h6:target{background:var(--highlight-color);padding:.2em 0}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{margin-top:.6em;font-weight:bold}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}dt:target .name{background:var(--highlight-color)}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}td{padding:0 .5em}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style> |
|
13 |
<style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%;height:100vh;overflow:auto;position:sticky;top:0}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style> |
|
14 |
<style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style> |
|
15 |
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/highlight.min.js" integrity="sha256-Uv3H6lx7dJmRfRvH8TH6kJD1TSK1aFcwgx+mdg3epi8=" crossorigin></script> |
|
16 |
<script>window.addEventListener('DOMContentLoaded', () => hljs.initHighlighting())</script> |
|
17 |
</head> |
|
18 |
<body> |
|
19 |
<main> |
|
20 |
<article id="content"> |
|
21 |
<header> |
|
22 |
<h1 class="title">Module <code>sql_app.api.licenses</code></h1> |
|
23 |
</header> |
|
24 |
<section id="section-intro"> |
|
25 |
<details class="source"> |
|
26 |
<summary> |
|
27 |
<span>Expand source code</span> |
|
28 |
</summary> |
|
29 |
<pre><code class="python">from typing import List |
|
30 |
|
|
31 |
from fastapi import Depends, FastAPI, HTTPException, APIRouter, Form |
|
32 |
from sqlalchemy.orm import Session |
|
33 |
from datetime import datetime |
|
34 |
from sql_app import crud, models, schemas |
|
35 |
from ..database import SessionLocal, engine |
|
36 |
|
|
37 |
models.Base.metadata.create_all(bind=engine) |
|
38 |
|
|
39 |
# prefix used for all endpoints in this file |
|
40 |
licenses = APIRouter(prefix="/api/v1") |
|
41 |
|
|
42 |
|
|
43 |
# Dependency |
|
44 |
def get_db(): |
|
45 |
db = SessionLocal() |
|
46 |
try: |
|
47 |
yield db |
|
48 |
finally: |
|
49 |
db.close() |
|
50 |
|
|
51 |
|
|
52 |
@licenses.get("/licenses", response_model=List[schemas.License]) |
|
53 |
def read_licenses(skip: int = 0, limit: int = 100, db: Session = Depends(get_db)): |
|
54 |
""" |
|
55 |
Returns all licenses currently saved in database. |
|
56 |
""" |
|
57 |
licenses = crud.get_licenses(db, skip=skip, limit=limit) |
|
58 |
return licenses |
|
59 |
|
|
60 |
|
|
61 |
@licenses.post("/device-license", response_model=schemas.DeviceLicense) |
|
62 |
def create_device_license(device_license: schemas.DeviceLicenseCreate, db: Session = Depends(get_db)): |
|
63 |
""" |
|
64 |
Creates entry for devices_licenses table thus connecting device with its license. |
|
65 |
""" |
|
66 |
print(crud.create_device_license(db=db, device=device_license.device_id, license=device_license.license_id, |
|
67 |
time=datetime.now()))</code></pre> |
|
68 |
</details> |
|
69 |
</section> |
|
70 |
<section> |
|
71 |
</section> |
|
72 |
<section> |
|
73 |
</section> |
|
74 |
<section> |
|
75 |
<h2 class="section-title" id="header-functions">Functions</h2> |
|
76 |
<dl> |
|
77 |
<dt id="sql_app.api.licenses.create_device_license"><code class="name flex"> |
|
78 |
<span>def <span class="ident">create_device_license</span></span>(<span>device_license: <a title="sql_app.schemas.DeviceLicenseCreate" href="../schemas.html#sql_app.schemas.DeviceLicenseCreate">DeviceLicenseCreate</a>, db: sqlalchemy.orm.session.Session = Depends(get_db))</span> |
|
79 |
</code></dt> |
|
80 |
<dd> |
|
81 |
<div class="desc"><p>Creates entry for devices_licenses table thus connecting device with its license.</p></div> |
|
82 |
<details class="source"> |
|
83 |
<summary> |
|
84 |
<span>Expand source code</span> |
|
85 |
</summary> |
|
86 |
<pre><code class="python">@licenses.post("/device-license", response_model=schemas.DeviceLicense) |
|
87 |
def create_device_license(device_license: schemas.DeviceLicenseCreate, db: Session = Depends(get_db)): |
|
88 |
""" |
|
89 |
Creates entry for devices_licenses table thus connecting device with its license. |
|
90 |
""" |
|
91 |
print(crud.create_device_license(db=db, device=device_license.device_id, license=device_license.license_id, |
|
92 |
time=datetime.now()))</code></pre> |
|
93 |
</details> |
|
94 |
</dd> |
|
95 |
<dt id="sql_app.api.licenses.get_db"><code class="name flex"> |
|
96 |
<span>def <span class="ident">get_db</span></span>(<span>)</span> |
|
97 |
</code></dt> |
|
98 |
<dd> |
|
99 |
<div class="desc"></div> |
|
100 |
<details class="source"> |
|
101 |
<summary> |
|
102 |
<span>Expand source code</span> |
|
103 |
</summary> |
|
104 |
<pre><code class="python">def get_db(): |
|
105 |
db = SessionLocal() |
|
106 |
try: |
|
107 |
yield db |
|
108 |
finally: |
|
109 |
db.close()</code></pre> |
|
110 |
</details> |
|
111 |
</dd> |
|
112 |
<dt id="sql_app.api.licenses.read_licenses"><code class="name flex"> |
|
113 |
<span>def <span class="ident">read_licenses</span></span>(<span>skip: int = 0, limit: int = 100, db: sqlalchemy.orm.session.Session = Depends(get_db))</span> |
|
114 |
</code></dt> |
|
115 |
<dd> |
|
116 |
<div class="desc"><p>Returns all licenses currently saved in database.</p></div> |
|
117 |
<details class="source"> |
|
118 |
<summary> |
|
119 |
<span>Expand source code</span> |
|
120 |
</summary> |
|
121 |
<pre><code class="python">@licenses.get("/licenses", response_model=List[schemas.License]) |
|
122 |
def read_licenses(skip: int = 0, limit: int = 100, db: Session = Depends(get_db)): |
|
123 |
""" |
|
124 |
Returns all licenses currently saved in database. |
|
125 |
""" |
|
126 |
licenses = crud.get_licenses(db, skip=skip, limit=limit) |
|
127 |
return licenses</code></pre> |
|
128 |
</details> |
|
129 |
</dd> |
|
130 |
</dl> |
|
131 |
</section> |
|
132 |
<section> |
|
133 |
</section> |
|
134 |
</article> |
|
135 |
<nav id="sidebar"> |
|
136 |
<h1>Index</h1> |
|
137 |
<div class="toc"> |
|
138 |
<ul></ul> |
|
139 |
</div> |
|
140 |
<ul id="index"> |
|
141 |
<li><h3>Super-module</h3> |
|
142 |
<ul> |
|
143 |
<li><code><a title="sql_app.api" href="index.html">sql_app.api</a></code></li> |
|
144 |
</ul> |
|
145 |
</li> |
|
146 |
<li><h3><a href="#header-functions">Functions</a></h3> |
|
147 |
<ul class=""> |
|
148 |
<li><code><a title="sql_app.api.licenses.create_device_license" href="#sql_app.api.licenses.create_device_license">create_device_license</a></code></li> |
|
149 |
<li><code><a title="sql_app.api.licenses.get_db" href="#sql_app.api.licenses.get_db">get_db</a></code></li> |
|
150 |
<li><code><a title="sql_app.api.licenses.read_licenses" href="#sql_app.api.licenses.read_licenses">read_licenses</a></code></li> |
|
151 |
</ul> |
|
152 |
</li> |
|
153 |
</ul> |
|
154 |
</nav> |
|
155 |
</main> |
|
156 |
<footer id="footer"> |
|
157 |
<p>Generated by <a href="https://pdoc3.github.io/pdoc" title="pdoc: Python API documentation generator"><cite>pdoc</cite> 0.10.0</a>.</p> |
|
158 |
</footer> |
|
159 |
</body> |
|
160 |
</html> |
server/doc/sql_app/api/licenses_web.html | ||
---|---|---|
1 |
<!doctype html> |
|
2 |
<html lang="en"> |
|
3 |
<head> |
|
4 |
<meta charset="utf-8"> |
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" /> |
|
6 |
<meta name="generator" content="pdoc 0.10.0" /> |
|
7 |
<title>sql_app.api.licenses_web API documentation</title> |
|
8 |
<meta name="description" content="" /> |
|
9 |
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/sanitize.min.css" integrity="sha256-PK9q560IAAa6WVRRh76LtCaI8pjTJ2z11v0miyNNjrs=" crossorigin> |
|
10 |
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/typography.min.css" integrity="sha256-7l/o7C8jubJiy74VsKTidCy1yBkRtiUGbVkYBylBqUg=" crossorigin> |
|
11 |
<link rel="stylesheet preload" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/styles/github.min.css" crossorigin> |
|
12 |
<style>:root{--highlight-color:#fe9}.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}#sidebar > *:last-child{margin-bottom:2cm}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}h1:target,h2:target,h3:target,h4:target,h5:target,h6:target{background:var(--highlight-color);padding:.2em 0}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{margin-top:.6em;font-weight:bold}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}dt:target .name{background:var(--highlight-color)}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}td{padding:0 .5em}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style> |
|
13 |
<style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%;height:100vh;overflow:auto;position:sticky;top:0}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style> |
|
14 |
<style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style> |
|
15 |
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/highlight.min.js" integrity="sha256-Uv3H6lx7dJmRfRvH8TH6kJD1TSK1aFcwgx+mdg3epi8=" crossorigin></script> |
|
16 |
<script>window.addEventListener('DOMContentLoaded', () => hljs.initHighlighting())</script> |
|
17 |
</head> |
|
18 |
<body> |
|
19 |
<main> |
|
20 |
<article id="content"> |
|
21 |
<header> |
|
22 |
<h1 class="title">Module <code>sql_app.api.licenses_web</code></h1> |
|
23 |
</header> |
|
24 |
<section id="section-intro"> |
|
25 |
<details class="source"> |
|
26 |
<summary> |
|
27 |
<span>Expand source code</span> |
|
28 |
</summary> |
|
29 |
<pre><code class="python">from typing import List |
|
30 |
|
|
31 |
from fastapi import Depends, FastAPI, HTTPException, APIRouter, Form |
|
32 |
from sqlalchemy.orm import Session |
|
33 |
from datetime import date |
|
34 |
from sql_app import crud, models, schemas |
|
35 |
from ..database import SessionLocal, engine |
|
36 |
from fastapi import FastAPI, Request |
|
37 |
from fastapi.responses import HTMLResponse |
|
38 |
from fastapi.staticfiles import StaticFiles |
|
39 |
from fastapi.templating import Jinja2Templates |
|
40 |
|
|
41 |
models.Base.metadata.create_all(bind=engine) |
|
42 |
|
|
43 |
# Path to html templates used in this file |
|
44 |
templates = Jinja2Templates(directory="../templates/licenses") |
|
45 |
device_templates = Jinja2Templates(directory="../templates/devices") |
|
46 |
|
|
47 |
# prefix used for all endpoints in this file |
|
48 |
licenses_web = APIRouter(prefix="/api/v1") |
|
49 |
|
|
50 |
|
|
51 |
# Dependency |
|
52 |
def get_db(): |
|
53 |
db = SessionLocal() |
|
54 |
try: |
|
55 |
yield db |
|
56 |
finally: |
|
57 |
db.close() |
|
58 |
|
|
59 |
|
|
60 |
@licenses_web.get("/license-create", response_class=HTMLResponse) |
|
61 |
async def licenses_create_web(request: Request): |
|
62 |
""" |
|
63 |
Returns template with Form for creating new license. |
|
64 |
""" |
|
65 |
return templates.TemplateResponse("license_create.html", {"request": request}) |
|
66 |
|
|
67 |
|
|
68 |
@licenses_web.get("/licenses-web", response_class=HTMLResponse) |
|
69 |
async def read_licenses_web(request: Request, skip: int = 0, limit: int = 100, db: Session = Depends(get_db)): |
|
70 |
""" |
|
71 |
Returns template with all licenses currently saved in database |
|
72 |
""" |
|
73 |
licenses = crud.get_licenses(db, skip=skip, limit=limit) |
|
74 |
return templates.TemplateResponse("licenses.html", {"request": request, "licenses": licenses}) |
|
75 |
|
|
76 |
|
|
77 |
@licenses_web.post("/licenses-web", response_class=HTMLResponse) |
|
78 |
def create_license(request: Request, name: str = Form(...), expdate: date = Form(...), skip: int = 0, limit: int = 100, |
|
79 |
db: Session = Depends(get_db)): |
|
80 |
""" |
|
81 |
Endpoint called from create license form. Creates new license and returns template with all licenses in database |
|
82 |
""" |
|
83 |
db_license = crud.create_license(db, name, expdate) |
|
84 |
if db_license is None: |
|
85 |
print("something went wrong") |
|
86 |
devices = crud.get_devices(db, skip=skip, limit=limit) |
|
87 |
statuses = [] |
|
88 |
for i in range(0, len(devices)): |
|
89 |
statuses.append(devices[i].logs[len(devices[i].logs) - 1].status) |
|
90 |
licenses = crud.get_licenses(db, skip=skip, limit=limit) |
|
91 |
return device_templates.TemplateResponse("devices.html", {"request": request, "devs": len(devices), "devices": devices, |
|
92 |
"statuses": statuses, "licenses": licenses})</code></pre> |
|
93 |
</details> |
|
94 |
</section> |
|
95 |
<section> |
|
96 |
</section> |
|
97 |
<section> |
|
98 |
</section> |
|
99 |
<section> |
|
100 |
<h2 class="section-title" id="header-functions">Functions</h2> |
|
101 |
<dl> |
|
102 |
<dt id="sql_app.api.licenses_web.create_license"><code class="name flex"> |
|
103 |
<span>def <span class="ident">create_license</span></span>(<span>request: starlette.requests.Request, name: str = Form(Ellipsis), expdate: datetime.date = Form(Ellipsis), skip: int = 0, limit: int = 100, db: sqlalchemy.orm.session.Session = Depends(get_db))</span> |
|
104 |
</code></dt> |
|
105 |
<dd> |
|
106 |
<div class="desc"><p>Endpoint called from create license form. Creates new license and returns template with all licenses in database</p></div> |
|
107 |
<details class="source"> |
|
108 |
<summary> |
|
109 |
<span>Expand source code</span> |
|
110 |
</summary> |
|
111 |
<pre><code class="python">@licenses_web.post("/licenses-web", response_class=HTMLResponse) |
|
112 |
def create_license(request: Request, name: str = Form(...), expdate: date = Form(...), skip: int = 0, limit: int = 100, |
|
113 |
db: Session = Depends(get_db)): |
|
114 |
""" |
|
115 |
Endpoint called from create license form. Creates new license and returns template with all licenses in database |
|
116 |
""" |
|
117 |
db_license = crud.create_license(db, name, expdate) |
|
118 |
if db_license is None: |
|
119 |
print("something went wrong") |
|
120 |
devices = crud.get_devices(db, skip=skip, limit=limit) |
|
121 |
statuses = [] |
|
122 |
for i in range(0, len(devices)): |
|
123 |
statuses.append(devices[i].logs[len(devices[i].logs) - 1].status) |
|
124 |
licenses = crud.get_licenses(db, skip=skip, limit=limit) |
|
125 |
return device_templates.TemplateResponse("devices.html", {"request": request, "devs": len(devices), "devices": devices, |
|
126 |
"statuses": statuses, "licenses": licenses})</code></pre> |
|
127 |
</details> |
|
128 |
</dd> |
|
129 |
<dt id="sql_app.api.licenses_web.get_db"><code class="name flex"> |
|
130 |
<span>def <span class="ident">get_db</span></span>(<span>)</span> |
|
131 |
</code></dt> |
|
132 |
<dd> |
|
133 |
<div class="desc"></div> |
|
134 |
<details class="source"> |
|
135 |
<summary> |
|
136 |
<span>Expand source code</span> |
|
137 |
</summary> |
|
138 |
<pre><code class="python">def get_db(): |
|
139 |
db = SessionLocal() |
|
140 |
try: |
|
141 |
yield db |
|
142 |
finally: |
|
143 |
db.close()</code></pre> |
|
144 |
</details> |
|
145 |
</dd> |
|
146 |
<dt id="sql_app.api.licenses_web.licenses_create_web"><code class="name flex"> |
|
147 |
<span>async def <span class="ident">licenses_create_web</span></span>(<span>request: starlette.requests.Request)</span> |
|
148 |
</code></dt> |
|
149 |
<dd> |
|
150 |
<div class="desc"><p>Returns template with Form for creating new license.</p></div> |
|
151 |
<details class="source"> |
|
152 |
<summary> |
|
153 |
<span>Expand source code</span> |
|
154 |
</summary> |
|
155 |
<pre><code class="python">@licenses_web.get("/license-create", response_class=HTMLResponse) |
|
156 |
async def licenses_create_web(request: Request): |
|
157 |
""" |
|
158 |
Returns template with Form for creating new license. |
|
159 |
""" |
|
160 |
return templates.TemplateResponse("license_create.html", {"request": request})</code></pre> |
|
161 |
</details> |
|
162 |
</dd> |
|
163 |
<dt id="sql_app.api.licenses_web.read_licenses_web"><code class="name flex"> |
|
164 |
<span>async def <span class="ident">read_licenses_web</span></span>(<span>request: starlette.requests.Request, skip: int = 0, limit: int = 100, db: sqlalchemy.orm.session.Session = Depends(get_db))</span> |
|
165 |
</code></dt> |
|
166 |
<dd> |
|
167 |
<div class="desc"><p>Returns template with all licenses currently saved in database</p></div> |
|
168 |
<details class="source"> |
|
169 |
<summary> |
|
170 |
<span>Expand source code</span> |
|
171 |
</summary> |
|
172 |
<pre><code class="python">@licenses_web.get("/licenses-web", response_class=HTMLResponse) |
|
173 |
async def read_licenses_web(request: Request, skip: int = 0, limit: int = 100, db: Session = Depends(get_db)): |
|
174 |
""" |
|
175 |
Returns template with all licenses currently saved in database |
|
176 |
""" |
|
177 |
licenses = crud.get_licenses(db, skip=skip, limit=limit) |
|
178 |
return templates.TemplateResponse("licenses.html", {"request": request, "licenses": licenses})</code></pre> |
|
179 |
</details> |
|
180 |
</dd> |
|
181 |
</dl> |
|
182 |
</section> |
|
183 |
<section> |
|
184 |
</section> |
|
185 |
</article> |
|
186 |
<nav id="sidebar"> |
|
187 |
<h1>Index</h1> |
|
188 |
<div class="toc"> |
|
189 |
<ul></ul> |
|
190 |
</div> |
|
191 |
<ul id="index"> |
|
192 |
<li><h3>Super-module</h3> |
|
193 |
<ul> |
|
194 |
<li><code><a title="sql_app.api" href="index.html">sql_app.api</a></code></li> |
|
195 |
</ul> |
|
196 |
</li> |
|
197 |
<li><h3><a href="#header-functions">Functions</a></h3> |
|
198 |
<ul class=""> |
|
199 |
<li><code><a title="sql_app.api.licenses_web.create_license" href="#sql_app.api.licenses_web.create_license">create_license</a></code></li> |
|
200 |
<li><code><a title="sql_app.api.licenses_web.get_db" href="#sql_app.api.licenses_web.get_db">get_db</a></code></li> |
|
201 |
<li><code><a title="sql_app.api.licenses_web.licenses_create_web" href="#sql_app.api.licenses_web.licenses_create_web">licenses_create_web</a></code></li> |
|
202 |
<li><code><a title="sql_app.api.licenses_web.read_licenses_web" href="#sql_app.api.licenses_web.read_licenses_web">read_licenses_web</a></code></li> |
|
203 |
</ul> |
|
204 |
</li> |
|
205 |
</ul> |
|
206 |
</nav> |
|
207 |
</main> |
|
208 |
<footer id="footer"> |
|
209 |
<p>Generated by <a href="https://pdoc3.github.io/pdoc" title="pdoc: Python API documentation generator"><cite>pdoc</cite> 0.10.0</a>.</p> |
|
210 |
</footer> |
|
211 |
</body> |
|
212 |
</html> |
server/doc/sql_app/api/pcs.html | ||
---|---|---|
1 |
<!doctype html> |
|
2 |
<html lang="en"> |
|
3 |
<head> |
|
4 |
<meta charset="utf-8"> |
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" /> |
|
6 |
<meta name="generator" content="pdoc 0.10.0" /> |
|
7 |
<title>sql_app.api.pcs API documentation</title> |
|
8 |
<meta name="description" content="" /> |
|
9 |
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/sanitize.min.css" integrity="sha256-PK9q560IAAa6WVRRh76LtCaI8pjTJ2z11v0miyNNjrs=" crossorigin> |
|
10 |
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/typography.min.css" integrity="sha256-7l/o7C8jubJiy74VsKTidCy1yBkRtiUGbVkYBylBqUg=" crossorigin> |
|
11 |
<link rel="stylesheet preload" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/styles/github.min.css" crossorigin> |
|
12 |
<style>:root{--highlight-color:#fe9}.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}#sidebar > *:last-child{margin-bottom:2cm}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}h1:target,h2:target,h3:target,h4:target,h5:target,h6:target{background:var(--highlight-color);padding:.2em 0}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{margin-top:.6em;font-weight:bold}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}dt:target .name{background:var(--highlight-color)}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}td{padding:0 .5em}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style> |
|
13 |
<style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%;height:100vh;overflow:auto;position:sticky;top:0}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style> |
|
14 |
<style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style> |
|
15 |
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/highlight.min.js" integrity="sha256-Uv3H6lx7dJmRfRvH8TH6kJD1TSK1aFcwgx+mdg3epi8=" crossorigin></script> |
|
16 |
<script>window.addEventListener('DOMContentLoaded', () => hljs.initHighlighting())</script> |
|
17 |
</head> |
|
18 |
<body> |
|
19 |
<main> |
|
20 |
<article id="content"> |
|
21 |
<header> |
|
22 |
<h1 class="title">Module <code>sql_app.api.pcs</code></h1> |
|
23 |
</header> |
|
24 |
<section id="section-intro"> |
|
25 |
<details class="source"> |
|
26 |
<summary> |
|
27 |
<span>Expand source code</span> |
|
28 |
</summary> |
|
29 |
<pre><code class="python">from typing import List |
|
30 |
from fastapi import Depends, FastAPI, HTTPException, APIRouter |
|
31 |
from sqlalchemy.orm import Session |
|
32 |
from sql_app import crud, models, schemas |
|
33 |
from ..database import SessionLocal, engine |
|
34 |
|
|
35 |
models.Base.metadata.create_all(bind=engine) |
|
36 |
|
|
37 |
# prefix used for all endpoints in this file |
|
38 |
pcs = APIRouter(prefix="/api/v1") |
|
39 |
|
|
40 |
|
|
41 |
# Dependency |
|
42 |
def get_db(): |
|
43 |
db = SessionLocal() |
|
44 |
try: |
|
45 |
yield db |
|
46 |
finally: |
|
47 |
db.close() |
|
48 |
|
|
49 |
|
|
50 |
@pcs.post("/pc", response_model=schemas.PC) |
|
51 |
def create_pc(pc: schemas.PCCreate, db: Session = Depends(get_db)): |
|
52 |
""" |
|
53 |
Endpoint used for creating new pc |
|
54 |
""" |
|
55 |
print(crud.create_pc(db=db, user=pc.username, host=pc.hostname)) |
|
56 |
|
|
57 |
|
|
58 |
@pcs.get("/pcs", response_model=List[schemas.PC]) |
|
59 |
def read_pcs(skip: int = 0, limit: int = 100, db: Session = Depends(get_db)): |
|
60 |
""" |
|
61 |
Returns all pcs currently saved in database |
|
62 |
""" |
|
63 |
pcs = crud.get_pcs(db, skip=skip, limit=limit) |
|
64 |
return pcs |
|
65 |
|
|
66 |
|
|
67 |
@pcs.get("/pc/{pc_id}", response_model=schemas.PC) |
|
68 |
def read_pc(pc_id: int, db: Session = Depends(get_db)): |
|
69 |
""" |
|
70 |
Returns one specific pc by given id |
|
71 |
""" |
|
72 |
db_pc = crud.get_pc(db, pc_id=pc_id) |
|
73 |
if db_pc is None: |
|
74 |
raise HTTPException(status_code=404, detail="Device not found") |
|
75 |
return db_pc</code></pre> |
|
76 |
</details> |
|
77 |
</section> |
|
78 |
<section> |
|
79 |
</section> |
|
80 |
<section> |
|
81 |
</section> |
|
82 |
<section> |
|
83 |
<h2 class="section-title" id="header-functions">Functions</h2> |
|
84 |
<dl> |
|
85 |
<dt id="sql_app.api.pcs.create_pc"><code class="name flex"> |
|
86 |
<span>def <span class="ident">create_pc</span></span>(<span>pc: <a title="sql_app.schemas.PCCreate" href="../schemas.html#sql_app.schemas.PCCreate">PCCreate</a>, db: sqlalchemy.orm.session.Session = Depends(get_db))</span> |
|
87 |
</code></dt> |
|
88 |
<dd> |
|
89 |
<div class="desc"><p>Endpoint used for creating new pc</p></div> |
|
90 |
<details class="source"> |
|
91 |
<summary> |
|
92 |
<span>Expand source code</span> |
|
93 |
</summary> |
|
94 |
<pre><code class="python">@pcs.post("/pc", response_model=schemas.PC) |
|
95 |
def create_pc(pc: schemas.PCCreate, db: Session = Depends(get_db)): |
|
96 |
""" |
|
97 |
Endpoint used for creating new pc |
|
98 |
""" |
|
99 |
print(crud.create_pc(db=db, user=pc.username, host=pc.hostname))</code></pre> |
|
100 |
</details> |
|
101 |
</dd> |
|
102 |
<dt id="sql_app.api.pcs.get_db"><code class="name flex"> |
|
103 |
<span>def <span class="ident">get_db</span></span>(<span>)</span> |
|
104 |
</code></dt> |
|
105 |
<dd> |
|
106 |
<div class="desc"></div> |
|
107 |
<details class="source"> |
|
108 |
<summary> |
|
109 |
<span>Expand source code</span> |
|
110 |
</summary> |
|
111 |
<pre><code class="python">def get_db(): |
|
112 |
db = SessionLocal() |
|
113 |
try: |
|
114 |
yield db |
|
115 |
finally: |
|
116 |
db.close()</code></pre> |
|
117 |
</details> |
|
118 |
</dd> |
|
119 |
<dt id="sql_app.api.pcs.read_pc"><code class="name flex"> |
|
120 |
<span>def <span class="ident">read_pc</span></span>(<span>pc_id: int, db: sqlalchemy.orm.session.Session = Depends(get_db))</span> |
|
121 |
</code></dt> |
|
122 |
<dd> |
|
123 |
<div class="desc"><p>Returns one specific pc by given id</p></div> |
|
124 |
<details class="source"> |
|
125 |
<summary> |
|
126 |
<span>Expand source code</span> |
|
127 |
</summary> |
|
128 |
<pre><code class="python">@pcs.get("/pc/{pc_id}", response_model=schemas.PC) |
|
129 |
def read_pc(pc_id: int, db: Session = Depends(get_db)): |
|
130 |
""" |
|
131 |
Returns one specific pc by given id |
|
132 |
""" |
|
133 |
db_pc = crud.get_pc(db, pc_id=pc_id) |
|
134 |
if db_pc is None: |
|
135 |
raise HTTPException(status_code=404, detail="Device not found") |
|
136 |
return db_pc</code></pre> |
|
137 |
</details> |
|
138 |
</dd> |
|
139 |
<dt id="sql_app.api.pcs.read_pcs"><code class="name flex"> |
|
140 |
<span>def <span class="ident">read_pcs</span></span>(<span>skip: int = 0, limit: int = 100, db: sqlalchemy.orm.session.Session = Depends(get_db))</span> |
|
141 |
</code></dt> |
|
142 |
<dd> |
|
143 |
<div class="desc"><p>Returns all pcs currently saved in database</p></div> |
|
144 |
<details class="source"> |
|
145 |
<summary> |
|
146 |
<span>Expand source code</span> |
|
147 |
</summary> |
|
148 |
<pre><code class="python">@pcs.get("/pcs", response_model=List[schemas.PC]) |
|
149 |
def read_pcs(skip: int = 0, limit: int = 100, db: Session = Depends(get_db)): |
|
150 |
""" |
|
151 |
Returns all pcs currently saved in database |
|
152 |
""" |
|
153 |
pcs = crud.get_pcs(db, skip=skip, limit=limit) |
|
154 |
return pcs</code></pre> |
|
155 |
</details> |
|
156 |
</dd> |
|
157 |
</dl> |
|
158 |
</section> |
|
159 |
<section> |
|
160 |
</section> |
|
161 |
</article> |
|
162 |
<nav id="sidebar"> |
|
163 |
<h1>Index</h1> |
|
164 |
<div class="toc"> |
|
165 |
<ul></ul> |
|
166 |
</div> |
|
167 |
<ul id="index"> |
|
168 |
<li><h3>Super-module</h3> |
|
169 |
<ul> |
|
170 |
<li><code><a title="sql_app.api" href="index.html">sql_app.api</a></code></li> |
|
171 |
</ul> |
|
172 |
</li> |
|
173 |
<li><h3><a href="#header-functions">Functions</a></h3> |
|
174 |
<ul class=""> |
|
175 |
<li><code><a title="sql_app.api.pcs.create_pc" href="#sql_app.api.pcs.create_pc">create_pc</a></code></li> |
|
176 |
<li><code><a title="sql_app.api.pcs.get_db" href="#sql_app.api.pcs.get_db">get_db</a></code></li> |
|
177 |
<li><code><a title="sql_app.api.pcs.read_pc" href="#sql_app.api.pcs.read_pc">read_pc</a></code></li> |
|
178 |
<li><code><a title="sql_app.api.pcs.read_pcs" href="#sql_app.api.pcs.read_pcs">read_pcs</a></code></li> |
|
179 |
</ul> |
|
180 |
</li> |
|
181 |
</ul> |
|
182 |
</nav> |
|
183 |
</main> |
|
184 |
<footer id="footer"> |
|
185 |
<p>Generated by <a href="https://pdoc3.github.io/pdoc" title="pdoc: Python API documentation generator"><cite>pdoc</cite> 0.10.0</a>.</p> |
|
186 |
</footer> |
|
187 |
</body> |
|
188 |
</html> |
server/doc/sql_app/api/pcs_web.html | ||
---|---|---|
1 |
<!doctype html> |
|
2 |
<html lang="en"> |
|
3 |
<head> |
|
4 |
<meta charset="utf-8"> |
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" /> |
|
6 |
<meta name="generator" content="pdoc 0.10.0" /> |
|
7 |
<title>sql_app.api.pcs_web API documentation</title> |
|
8 |
<meta name="description" content="" /> |
|
9 |
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/sanitize.min.css" integrity="sha256-PK9q560IAAa6WVRRh76LtCaI8pjTJ2z11v0miyNNjrs=" crossorigin> |
|
10 |
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/typography.min.css" integrity="sha256-7l/o7C8jubJiy74VsKTidCy1yBkRtiUGbVkYBylBqUg=" crossorigin> |
|
11 |
<link rel="stylesheet preload" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/styles/github.min.css" crossorigin> |
|
12 |
<style>:root{--highlight-color:#fe9}.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}#sidebar > *:last-child{margin-bottom:2cm}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}h1:target,h2:target,h3:target,h4:target,h5:target,h6:target{background:var(--highlight-color);padding:.2em 0}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{margin-top:.6em;font-weight:bold}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}dt:target .name{background:var(--highlight-color)}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}td{padding:0 .5em}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style> |
|
13 |
<style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%;height:100vh;overflow:auto;position:sticky;top:0}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style> |
|
14 |
<style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style> |
|
15 |
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/highlight.min.js" integrity="sha256-Uv3H6lx7dJmRfRvH8TH6kJD1TSK1aFcwgx+mdg3epi8=" crossorigin></script> |
|
16 |
<script>window.addEventListener('DOMContentLoaded', () => hljs.initHighlighting())</script> |
|
17 |
</head> |
|
18 |
<body> |
|
19 |
<main> |
|
20 |
<article id="content"> |
|
21 |
<header> |
|
22 |
<h1 class="title">Module <code>sql_app.api.pcs_web</code></h1> |
|
23 |
</header> |
|
24 |
<section id="section-intro"> |
|
25 |
<details class="source"> |
|
26 |
<summary> |
|
27 |
<span>Expand source code</span> |
|
28 |
</summary> |
|
29 |
<pre><code class="python">from typing import List |
|
30 |
from fastapi import Depends, FastAPI, HTTPException, APIRouter, Form |
|
31 |
from sqlalchemy.orm import Session |
|
32 |
from sql_app import crud, models, schemas |
|
33 |
from ..database import SessionLocal, engine |
|
34 |
from fastapi import FastAPI, Request |
|
35 |
from fastapi.responses import HTMLResponse |
|
36 |
from fastapi.staticfiles import StaticFiles |
|
37 |
from fastapi.templating import Jinja2Templates |
|
38 |
|
|
39 |
models.Base.metadata.create_all(bind=engine) |
|
40 |
|
|
41 |
# Path to html templates used in this file |
|
42 |
templates = Jinja2Templates(directory="../templates/pcs") |
|
43 |
|
|
44 |
# prefix used for all endpoints in this file |
|
45 |
pcs_web = APIRouter(prefix="/api/v1") |
|
46 |
|
|
47 |
|
|
48 |
# Dependency |
|
49 |
def get_db(): |
|
50 |
db = SessionLocal() |
|
51 |
try: |
|
52 |
yield db |
|
53 |
finally: |
|
54 |
db.close() |
|
55 |
|
|
56 |
|
|
57 |
@pcs_web.get("/pcs-web", response_class=HTMLResponse) |
|
58 |
async def read_pcs(request: Request, skip: int = 0, limit: int = 100, db: Session = Depends(get_db)): |
|
59 |
""" |
|
60 |
Returns template with all pcs currently saved in database |
|
61 |
""" |
|
62 |
pcs = crud.get_pcs(db, skip=skip, limit=limit) |
|
63 |
return templates.TemplateResponse("pcs.html", {"request": request, "pcs": pcs}) |
|
64 |
|
|
65 |
|
|
66 |
@pcs_web.get("/pc-team/{pc_id}", response_class=HTMLResponse) |
|
67 |
async def connect_pc_team(request: Request, pc_id: int, db: Session = Depends(get_db)): |
|
68 |
""" |
|
69 |
Returns template with Form for connecting pc with team |
|
70 |
""" |
|
71 |
pc = crud.get_pc(db, pc_id) |
|
72 |
teams = crud.get_teams(db, 0, 100) |
|
73 |
return templates.TemplateResponse("pcteam.html", |
|
74 |
{"request": request, "pc": pc, "teams": teams}) |
|
75 |
|
|
76 |
|
|
77 |
@pcs_web.post("/pcs-web/{pc_id}", response_class=HTMLResponse) |
|
78 |
async def connect_post(request: Request, pc_id: int, team: str = Form(...), skip: int = 0, limit: int = 100, |
|
79 |
db: Session = Depends(get_db)): |
|
80 |
""" |
|
81 |
Endpoint called from within form for connecting pc with team. Updates certain pc with new team. |
|
82 |
""" |
|
83 |
old_pc = crud.update_pc(db, pc_id, team) |
|
84 |
pcs = crud.get_pcs(db, skip=skip, limit=limit) |
|
85 |
return templates.TemplateResponse("pcs.html", {"request": request, "pcs": pcs})</code></pre> |
|
86 |
</details> |
|
87 |
</section> |
|
88 |
<section> |
|
89 |
</section> |
|
90 |
<section> |
|
91 |
</section> |
|
92 |
<section> |
|
93 |
<h2 class="section-title" id="header-functions">Functions</h2> |
|
94 |
<dl> |
|
95 |
<dt id="sql_app.api.pcs_web.connect_pc_team"><code class="name flex"> |
|
96 |
<span>async def <span class="ident">connect_pc_team</span></span>(<span>request: starlette.requests.Request, pc_id: int, db: sqlalchemy.orm.session.Session = Depends(get_db))</span> |
|
97 |
</code></dt> |
|
98 |
<dd> |
|
99 |
<div class="desc"><p>Returns template with Form for connecting pc with team</p></div> |
|
100 |
<details class="source"> |
|
101 |
<summary> |
|
102 |
<span>Expand source code</span> |
|
103 |
</summary> |
|
104 |
<pre><code class="python">@pcs_web.get("/pc-team/{pc_id}", response_class=HTMLResponse) |
|
105 |
async def connect_pc_team(request: Request, pc_id: int, db: Session = Depends(get_db)): |
|
106 |
""" |
|
107 |
Returns template with Form for connecting pc with team |
|
108 |
""" |
|
109 |
pc = crud.get_pc(db, pc_id) |
|
110 |
teams = crud.get_teams(db, 0, 100) |
|
111 |
return templates.TemplateResponse("pcteam.html", |
|
112 |
{"request": request, "pc": pc, "teams": teams})</code></pre> |
|
113 |
</details> |
|
114 |
</dd> |
|
115 |
<dt id="sql_app.api.pcs_web.connect_post"><code class="name flex"> |
|
116 |
<span>async def <span class="ident">connect_post</span></span>(<span>request: starlette.requests.Request, pc_id: int, team: str = Form(Ellipsis), skip: int = 0, limit: int = 100, db: sqlalchemy.orm.session.Session = Depends(get_db))</span> |
|
117 |
</code></dt> |
|
118 |
<dd> |
|
119 |
<div class="desc"><p>Endpoint called from within form for connecting pc with team. Updates certain pc with new team.</p></div> |
|
120 |
<details class="source"> |
|
121 |
<summary> |
|
122 |
<span>Expand source code</span> |
|
123 |
</summary> |
|
124 |
<pre><code class="python">@pcs_web.post("/pcs-web/{pc_id}", response_class=HTMLResponse) |
|
125 |
async def connect_post(request: Request, pc_id: int, team: str = Form(...), skip: int = 0, limit: int = 100, |
|
126 |
db: Session = Depends(get_db)): |
|
127 |
""" |
|
128 |
Endpoint called from within form for connecting pc with team. Updates certain pc with new team. |
|
129 |
""" |
|
130 |
old_pc = crud.update_pc(db, pc_id, team) |
|
131 |
pcs = crud.get_pcs(db, skip=skip, limit=limit) |
|
132 |
return templates.TemplateResponse("pcs.html", {"request": request, "pcs": pcs})</code></pre> |
|
133 |
</details> |
|
134 |
</dd> |
|
135 |
<dt id="sql_app.api.pcs_web.get_db"><code class="name flex"> |
|
136 |
<span>def <span class="ident">get_db</span></span>(<span>)</span> |
|
137 |
</code></dt> |
|
138 |
<dd> |
|
139 |
<div class="desc"></div> |
|
140 |
<details class="source"> |
|
141 |
<summary> |
|
142 |
<span>Expand source code</span> |
|
143 |
</summary> |
|
144 |
<pre><code class="python">def get_db(): |
|
145 |
db = SessionLocal() |
|
146 |
try: |
|
147 |
yield db |
|
148 |
finally: |
|
149 |
db.close()</code></pre> |
|
150 |
</details> |
|
151 |
</dd> |
|
152 |
<dt id="sql_app.api.pcs_web.read_pcs"><code class="name flex"> |
|
153 |
<span>async def <span class="ident">read_pcs</span></span>(<span>request: starlette.requests.Request, skip: int = 0, limit: int = 100, db: sqlalchemy.orm.session.Session = Depends(get_db))</span> |
|
154 |
</code></dt> |
|
155 |
<dd> |
|
156 |
<div class="desc"><p>Returns template with all pcs currently saved in database</p></div> |
|
157 |
<details class="source"> |
|
158 |
<summary> |
|
159 |
<span>Expand source code</span> |
|
160 |
</summary> |
|
161 |
<pre><code class="python">@pcs_web.get("/pcs-web", response_class=HTMLResponse) |
|
162 |
async def read_pcs(request: Request, skip: int = 0, limit: int = 100, db: Session = Depends(get_db)): |
|
163 |
""" |
|
164 |
Returns template with all pcs currently saved in database |
|
165 |
""" |
|
166 |
pcs = crud.get_pcs(db, skip=skip, limit=limit) |
|
167 |
return templates.TemplateResponse("pcs.html", {"request": request, "pcs": pcs})</code></pre> |
|
168 |
</details> |
|
169 |
</dd> |
|
170 |
</dl> |
|
171 |
</section> |
|
172 |
<section> |
|
173 |
</section> |
|
174 |
</article> |
|
175 |
<nav id="sidebar"> |
|
176 |
<h1>Index</h1> |
|
177 |
<div class="toc"> |
|
178 |
<ul></ul> |
|
179 |
</div> |
|
180 |
<ul id="index"> |
|
181 |
<li><h3>Super-module</h3> |
|
182 |
<ul> |
|
183 |
<li><code><a title="sql_app.api" href="index.html">sql_app.api</a></code></li> |
|
184 |
</ul> |
|
185 |
</li> |
|
186 |
<li><h3><a href="#header-functions">Functions</a></h3> |
|
187 |
<ul class=""> |
|
188 |
<li><code><a title="sql_app.api.pcs_web.connect_pc_team" href="#sql_app.api.pcs_web.connect_pc_team">connect_pc_team</a></code></li> |
|
189 |
<li><code><a title="sql_app.api.pcs_web.connect_post" href="#sql_app.api.pcs_web.connect_post">connect_post</a></code></li> |
|
190 |
<li><code><a title="sql_app.api.pcs_web.get_db" href="#sql_app.api.pcs_web.get_db">get_db</a></code></li> |
|
191 |
<li><code><a title="sql_app.api.pcs_web.read_pcs" href="#sql_app.api.pcs_web.read_pcs">read_pcs</a></code></li> |
|
192 |
</ul> |
|
193 |
</li> |
|
194 |
</ul> |
|
195 |
</nav> |
|
196 |
</main> |
|
197 |
<footer id="footer"> |
|
198 |
<p>Generated by <a href="https://pdoc3.github.io/pdoc" title="pdoc: Python API documentation generator"><cite>pdoc</cite> 0.10.0</a>.</p> |
|
199 |
</footer> |
|
200 |
</body> |
|
201 |
</html> |
server/doc/sql_app/api/teams.html | ||
---|---|---|
1 |
<!doctype html> |
|
2 |
<html lang="en"> |
|
3 |
<head> |
|
4 |
<meta charset="utf-8"> |
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" /> |
|
6 |
<meta name="generator" content="pdoc 0.10.0" /> |
|
7 |
<title>sql_app.api.teams API documentation</title> |
|
8 |
<meta name="description" content="" /> |
|
9 |
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/sanitize.min.css" integrity="sha256-PK9q560IAAa6WVRRh76LtCaI8pjTJ2z11v0miyNNjrs=" crossorigin> |
|
10 |
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/typography.min.css" integrity="sha256-7l/o7C8jubJiy74VsKTidCy1yBkRtiUGbVkYBylBqUg=" crossorigin> |
|
11 |
<link rel="stylesheet preload" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/styles/github.min.css" crossorigin> |
|
12 |
<style>:root{--highlight-color:#fe9}.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}#sidebar > *:last-child{margin-bottom:2cm}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}h1:target,h2:target,h3:target,h4:target,h5:target,h6:target{background:var(--highlight-color);padding:.2em 0}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{margin-top:.6em;font-weight:bold}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}dt:target .name{background:var(--highlight-color)}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}td{padding:0 .5em}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style> |
|
13 |
<style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%;height:100vh;overflow:auto;position:sticky;top:0}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style> |
|
14 |
<style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style> |
|
15 |
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/highlight.min.js" integrity="sha256-Uv3H6lx7dJmRfRvH8TH6kJD1TSK1aFcwgx+mdg3epi8=" crossorigin></script> |
|
16 |
<script>window.addEventListener('DOMContentLoaded', () => hljs.initHighlighting())</script> |
|
17 |
</head> |
|
18 |
<body> |
|
19 |
<main> |
|
20 |
<article id="content"> |
|
21 |
<header> |
|
22 |
<h1 class="title">Module <code>sql_app.api.teams</code></h1> |
|
23 |
</header> |
|
24 |
<section id="section-intro"> |
|
25 |
<details class="source"> |
|
26 |
<summary> |
|
27 |
<span>Expand source code</span> |
|
28 |
</summary> |
|
29 |
<pre><code class="python">from typing import List |
|
30 |
|
|
31 |
from fastapi import Depends, FastAPI, HTTPException, APIRouter |
|
32 |
from sqlalchemy.orm import Session |
|
33 |
from sql_app import crud, models, schemas |
|
34 |
from ..database import SessionLocal, engine |
|
35 |
|
|
36 |
models.Base.metadata.create_all(bind=engine) |
|
37 |
|
|
38 |
# prefix used for all endpoints in this file |
|
39 |
teams = APIRouter(prefix="/api/v1") |
|
40 |
|
|
41 |
# Dependency |
|
42 |
def get_db(): |
|
43 |
db = SessionLocal() |
|
44 |
try: |
|
45 |
yield db |
|
46 |
finally: |
|
47 |
db.close() |
|
48 |
|
|
49 |
|
|
50 |
@teams.post("/team", response_model=schemas.Team) |
|
51 |
def create_device(team: schemas.TeamCreate, db: Session = Depends(get_db)): |
|
52 |
""" |
|
53 |
Endpoint used for creating new pc |
|
54 |
""" |
|
55 |
print(crud.create_team(db=db, name=team.name)) |
|
56 |
|
|
57 |
|
|
58 |
@teams.get("/teams", response_model=List[schemas.Device]) |
|
59 |
def read_devices(skip: int = 0, limit: int = 100, db: Session = Depends(get_db)): |
|
60 |
""" |
|
61 |
Returns all pcs saved in database |
|
62 |
""" |
|
63 |
teams = crud.get_teams(db, skip=skip, limit=limit) |
|
64 |
return teams |
|
65 |
|
|
66 |
|
|
67 |
@teams.get("/team/{team_id}", response_model=schemas.Device) |
|
68 |
def read_device(team_id: int, db: Session = Depends(get_db)): |
|
69 |
""" |
|
70 |
Returns one specific team by given id |
|
71 |
""" |
|
72 |
db_team = crud.get_team(db, team_id=team_id) |
|
73 |
if db_team is None: |
|
74 |
raise HTTPException(status_code=404, detail="Device not found") |
|
75 |
return db_team</code></pre> |
|
76 |
</details> |
|
77 |
</section> |
|
78 |
<section> |
|
79 |
</section> |
|
80 |
<section> |
|
81 |
</section> |
|
82 |
<section> |
|
83 |
<h2 class="section-title" id="header-functions">Functions</h2> |
|
84 |
<dl> |
|
85 |
<dt id="sql_app.api.teams.create_device"><code class="name flex"> |
|
86 |
<span>def <span class="ident">create_device</span></span>(<span>team: <a title="sql_app.schemas.TeamCreate" href="../schemas.html#sql_app.schemas.TeamCreate">TeamCreate</a>, db: sqlalchemy.orm.session.Session = Depends(get_db))</span> |
|
87 |
</code></dt> |
|
88 |
<dd> |
|
89 |
<div class="desc"><p>Endpoint used for creating new pc</p></div> |
|
90 |
<details class="source"> |
|
91 |
<summary> |
Také k dispozici: Unified diff
re #9577 Api code documentation.