Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 4911f0ea

Přidáno uživatelem Matěj Zeman před asi 2 roky(ů)

re #9577 Api code documentation.

Zobrazit rozdíly:

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=&#34;/api/v1&#34;)
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(&#34;/device&#34;, response_model=schemas.Device)
52
def create_device(device: schemas.DeviceCreate, db: Session = Depends(get_db)):
53
    &#34;&#34;&#34;
54
    Endpoint used for creating new device
55
    &#34;&#34;&#34;
56
    print(crud.create_device(db=db, device=device))
57

  
58

  
59
@device.get(&#34;/devices&#34;, response_model=List[schemas.Device])
60
def read_devices(skip: int = 0, limit: int = 100, db: Session = Depends(get_db)):
61
    &#34;&#34;&#34;
62
    Endpoint returns all devices in database
63
    &#34;&#34;&#34;
64
    devices = crud.get_devices(db, skip=skip, limit=limit)
65
    return devices
66

  
67

  
68
@device.get(&#34;/device/{device_id}&#34;, response_model=schemas.Device)
69
def read_device(device_id: int, db: Session = Depends(get_db)):
70
    &#34;&#34;&#34;
71
    Returns one specific device by given id
72
    &#34;&#34;&#34;
73
    db_device = crud.get_device(db, device_id=device_id)
74
    if db_device is None:
75
        raise HTTPException(status_code=404, detail=&#34;Device not found&#34;)
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(&#34;/device&#34;, response_model=schemas.Device)
96
def create_device(device: schemas.DeviceCreate, db: Session = Depends(get_db)):
97
    &#34;&#34;&#34;
98
    Endpoint used for creating new device
99
    &#34;&#34;&#34;
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(&#34;/device/{device_id}&#34;, response_model=schemas.Device)
130
def read_device(device_id: int, db: Session = Depends(get_db)):
131
    &#34;&#34;&#34;
132
    Returns one specific device by given id
133
    &#34;&#34;&#34;
134
    db_device = crud.get_device(db, device_id=device_id)
135
    if db_device is None:
136
        raise HTTPException(status_code=404, detail=&#34;Device not found&#34;)
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(&#34;/devices&#34;, response_model=List[schemas.Device])
150
def read_devices(skip: int = 0, limit: int = 100, db: Session = Depends(get_db)):
151
    &#34;&#34;&#34;
152
    Endpoint returns all devices in database
153
    &#34;&#34;&#34;
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=&#34;../templates/devices&#34;)
45

  
46
# prefix used for all endpoints in this file
47
device_web = APIRouter(prefix=&#34;/api/v1&#34;)
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(&#34;/devices-web&#34;, response_class=HTMLResponse)
60
async def read_devices(request: Request, skip: int = 0, limit: int = 100, db: Session = Depends(get_db)):
61
    &#34;&#34;&#34;
62
    Returns template with all devices and its current states
63
    &#34;&#34;&#34;
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(&#34;devices.html&#34;, {&#34;request&#34;: request, &#34;devs&#34;: len(devices), &#34;devices&#34;: devices,
71
                                                       &#34;statuses&#34;: statuses, &#34;licenses&#34;: licenses})
72

  
73

  
74
@device_web.post(&#34;/devices-web&#34;, response_class=HTMLResponse)
75
async def filter_devices(request: Request, skip: int = 0, limit: int = 100, lic: str = Form(&#34;all&#34;),
76
                         db: Session = Depends(get_db)):
77
    &#34;&#34;&#34;
78
    Endpoint used for filtering devices by license. returns html template with only
79
    devices that has assigned license defined by user input
80
    &#34;&#34;&#34;
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 == &#34;all&#34;:
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(&#34;devices.html&#34;, {&#34;request&#34;: request, &#34;devs&#34;: len(def_devices), &#34;devices&#34;: def_devices,
95
                                                       &#34;statuses&#34;: statuses, &#34;licenses&#34;: licenses})
96

  
97

  
98
@device_web.get(&#34;/device-license/{device_id}&#34;, response_class=HTMLResponse)
99
async def connect_dev_lic(request: Request, device_id: int, db: Session = Depends(get_db)):
100
    &#34;&#34;&#34;
101
    Returns template with one device and all available licenses that can be assigned to it.
102
    &#34;&#34;&#34;
103
    device = crud.get_device(db, device_id)
104
    licenses = crud.get_licenses(db, 0, 100)
105
    return templates.TemplateResponse(&#34;devicelicense.html&#34;,
106
                                      {&#34;request&#34;: request, &#34;device&#34;: device, &#34;licenses&#34;: licenses})
107

  
108

  
109
@device_web.post(&#34;/devices-web/{device_id}&#34;, 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
    &#34;&#34;&#34;
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
    &#34;&#34;&#34;
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(&#34;devices.html&#34;, {&#34;request&#34;: request, &#34;devs&#34;: len(devices), &#34;devices&#34;: devices,
124
                                                       &#34;statuses&#34;: statuses, &#34;licenses&#34;: 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(&#34;/device-license/{device_id}&#34;, response_class=HTMLResponse)
144
async def connect_dev_lic(request: Request, device_id: int, db: Session = Depends(get_db)):
145
    &#34;&#34;&#34;
146
    Returns template with one device and all available licenses that can be assigned to it.
147
    &#34;&#34;&#34;
148
    device = crud.get_device(db, device_id)
149
    licenses = crud.get_licenses(db, 0, 100)
150
    return templates.TemplateResponse(&#34;devicelicense.html&#34;,
151
                                      {&#34;request&#34;: request, &#34;device&#34;: device, &#34;licenses&#34;: 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(&#34;/devices-web/{device_id}&#34;, 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
    &#34;&#34;&#34;
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
    &#34;&#34;&#34;
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(&#34;devices.html&#34;, {&#34;request&#34;: request, &#34;devs&#34;: len(devices), &#34;devices&#34;: devices,
179
                                                       &#34;statuses&#34;: statuses, &#34;licenses&#34;: 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(&#34;/devices-web&#34;, response_class=HTMLResponse)
193
async def filter_devices(request: Request, skip: int = 0, limit: int = 100, lic: str = Form(&#34;all&#34;),
194
                         db: Session = Depends(get_db)):
195
    &#34;&#34;&#34;
196
    Endpoint used for filtering devices by license. returns html template with only
197
    devices that has assigned license defined by user input
198
    &#34;&#34;&#34;
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 == &#34;all&#34;:
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(&#34;devices.html&#34;, {&#34;request&#34;: request, &#34;devs&#34;: len(def_devices), &#34;devices&#34;: def_devices,
213
                                                       &#34;statuses&#34;: statuses, &#34;licenses&#34;: 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(&#34;/devices-web&#34;, response_class=HTMLResponse)
243
async def read_devices(request: Request, skip: int = 0, limit: int = 100, db: Session = Depends(get_db)):
244
    &#34;&#34;&#34;
245
    Returns template with all devices and its current states
246
    &#34;&#34;&#34;
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(&#34;devices.html&#34;, {&#34;request&#34;: request, &#34;devs&#34;: len(devices), &#34;devices&#34;: devices,
254
                                                       &#34;statuses&#34;: statuses, &#34;licenses&#34;: 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=&#34;/api/v1&#34;)
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(&#34;/licenses&#34;, response_model=List[schemas.License])
53
def read_licenses(skip: int = 0, limit: int = 100, db: Session = Depends(get_db)):
54
    &#34;&#34;&#34;
55
    Returns all licenses currently saved in database.
56
    &#34;&#34;&#34;
57
    licenses = crud.get_licenses(db, skip=skip, limit=limit)
58
    return licenses
59

  
60

  
61
@licenses.post(&#34;/device-license&#34;, response_model=schemas.DeviceLicense)
62
def create_device_license(device_license: schemas.DeviceLicenseCreate, db: Session = Depends(get_db)):
63
    &#34;&#34;&#34;
64
    Creates entry for devices_licenses table thus connecting device with its license.
65
    &#34;&#34;&#34;
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(&#34;/device-license&#34;, response_model=schemas.DeviceLicense)
87
def create_device_license(device_license: schemas.DeviceLicenseCreate, db: Session = Depends(get_db)):
88
    &#34;&#34;&#34;
89
    Creates entry for devices_licenses table thus connecting device with its license.
90
    &#34;&#34;&#34;
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(&#34;/licenses&#34;, response_model=List[schemas.License])
122
def read_licenses(skip: int = 0, limit: int = 100, db: Session = Depends(get_db)):
123
    &#34;&#34;&#34;
124
    Returns all licenses currently saved in database.
125
    &#34;&#34;&#34;
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=&#34;../templates/licenses&#34;)
45
device_templates = Jinja2Templates(directory=&#34;../templates/devices&#34;)
46

  
47
# prefix used for all endpoints in this file
48
licenses_web = APIRouter(prefix=&#34;/api/v1&#34;)
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(&#34;/license-create&#34;, response_class=HTMLResponse)
61
async def licenses_create_web(request: Request):
62
    &#34;&#34;&#34;
63
    Returns template with Form for creating new license.
64
    &#34;&#34;&#34;
65
    return templates.TemplateResponse(&#34;license_create.html&#34;, {&#34;request&#34;: request})
66

  
67

  
68
@licenses_web.get(&#34;/licenses-web&#34;, response_class=HTMLResponse)
69
async def read_licenses_web(request: Request, skip: int = 0, limit: int = 100, db: Session = Depends(get_db)):
70
    &#34;&#34;&#34;
71
    Returns template with all licenses currently saved in database
72
    &#34;&#34;&#34;
73
    licenses = crud.get_licenses(db, skip=skip, limit=limit)
74
    return templates.TemplateResponse(&#34;licenses.html&#34;, {&#34;request&#34;: request, &#34;licenses&#34;: licenses})
75

  
76

  
77
@licenses_web.post(&#34;/licenses-web&#34;, 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
    &#34;&#34;&#34;
81
    Endpoint called from create license form. Creates new license and returns template with all licenses in database
82
    &#34;&#34;&#34;
83
    db_license = crud.create_license(db, name, expdate)
84
    if db_license is None:
85
        print(&#34;something went wrong&#34;)
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(&#34;devices.html&#34;, {&#34;request&#34;: request, &#34;devs&#34;: len(devices), &#34;devices&#34;: devices,
92
                                                       &#34;statuses&#34;: statuses, &#34;licenses&#34;: 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(&#34;/licenses-web&#34;, 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
    &#34;&#34;&#34;
115
    Endpoint called from create license form. Creates new license and returns template with all licenses in database
116
    &#34;&#34;&#34;
117
    db_license = crud.create_license(db, name, expdate)
118
    if db_license is None:
119
        print(&#34;something went wrong&#34;)
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(&#34;devices.html&#34;, {&#34;request&#34;: request, &#34;devs&#34;: len(devices), &#34;devices&#34;: devices,
126
                                                       &#34;statuses&#34;: statuses, &#34;licenses&#34;: 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(&#34;/license-create&#34;, response_class=HTMLResponse)
156
async def licenses_create_web(request: Request):
157
    &#34;&#34;&#34;
158
    Returns template with Form for creating new license.
159
    &#34;&#34;&#34;
160
    return templates.TemplateResponse(&#34;license_create.html&#34;, {&#34;request&#34;: 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(&#34;/licenses-web&#34;, response_class=HTMLResponse)
173
async def read_licenses_web(request: Request, skip: int = 0, limit: int = 100, db: Session = Depends(get_db)):
174
    &#34;&#34;&#34;
175
    Returns template with all licenses currently saved in database
176
    &#34;&#34;&#34;
177
    licenses = crud.get_licenses(db, skip=skip, limit=limit)
178
    return templates.TemplateResponse(&#34;licenses.html&#34;, {&#34;request&#34;: request, &#34;licenses&#34;: 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=&#34;/api/v1&#34;)
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(&#34;/pc&#34;, response_model=schemas.PC)
51
def create_pc(pc: schemas.PCCreate, db: Session = Depends(get_db)):
52
    &#34;&#34;&#34;
53
    Endpoint used for creating new pc
54
    &#34;&#34;&#34;
55
    print(crud.create_pc(db=db, user=pc.username, host=pc.hostname))
56

  
57

  
58
@pcs.get(&#34;/pcs&#34;, response_model=List[schemas.PC])
59
def read_pcs(skip: int = 0, limit: int = 100, db: Session = Depends(get_db)):
60
    &#34;&#34;&#34;
61
    Returns all pcs currently saved in database
62
    &#34;&#34;&#34;
63
    pcs = crud.get_pcs(db, skip=skip, limit=limit)
64
    return pcs
65

  
66

  
67
@pcs.get(&#34;/pc/{pc_id}&#34;, response_model=schemas.PC)
68
def read_pc(pc_id: int, db: Session = Depends(get_db)):
69
    &#34;&#34;&#34;
70
    Returns one specific pc by given id
71
    &#34;&#34;&#34;
72
    db_pc = crud.get_pc(db, pc_id=pc_id)
73
    if db_pc is None:
74
        raise HTTPException(status_code=404, detail=&#34;Device not found&#34;)
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(&#34;/pc&#34;, response_model=schemas.PC)
95
def create_pc(pc: schemas.PCCreate, db: Session = Depends(get_db)):
96
    &#34;&#34;&#34;
97
    Endpoint used for creating new pc
98
    &#34;&#34;&#34;
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(&#34;/pc/{pc_id}&#34;, response_model=schemas.PC)
129
def read_pc(pc_id: int, db: Session = Depends(get_db)):
130
    &#34;&#34;&#34;
131
    Returns one specific pc by given id
132
    &#34;&#34;&#34;
133
    db_pc = crud.get_pc(db, pc_id=pc_id)
134
    if db_pc is None:
135
        raise HTTPException(status_code=404, detail=&#34;Device not found&#34;)
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(&#34;/pcs&#34;, response_model=List[schemas.PC])
149
def read_pcs(skip: int = 0, limit: int = 100, db: Session = Depends(get_db)):
150
    &#34;&#34;&#34;
151
    Returns all pcs currently saved in database
152
    &#34;&#34;&#34;
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=&#34;../templates/pcs&#34;)
43

  
44
# prefix used for all endpoints in this file
45
pcs_web = APIRouter(prefix=&#34;/api/v1&#34;)
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(&#34;/pcs-web&#34;, response_class=HTMLResponse)
58
async def read_pcs(request: Request, skip: int = 0, limit: int = 100, db: Session = Depends(get_db)):
59
    &#34;&#34;&#34;
60
    Returns template with all pcs currently saved in database
61
    &#34;&#34;&#34;
62
    pcs = crud.get_pcs(db, skip=skip, limit=limit)
63
    return templates.TemplateResponse(&#34;pcs.html&#34;, {&#34;request&#34;: request, &#34;pcs&#34;: pcs})
64

  
65

  
66
@pcs_web.get(&#34;/pc-team/{pc_id}&#34;, response_class=HTMLResponse)
67
async def connect_pc_team(request: Request, pc_id: int, db: Session = Depends(get_db)):
68
    &#34;&#34;&#34;
69
    Returns template with Form for connecting pc with team
70
    &#34;&#34;&#34;
71
    pc = crud.get_pc(db, pc_id)
72
    teams = crud.get_teams(db, 0, 100)
73
    return templates.TemplateResponse(&#34;pcteam.html&#34;,
74
                                      {&#34;request&#34;: request, &#34;pc&#34;: pc, &#34;teams&#34;: teams})
75

  
76

  
77
@pcs_web.post(&#34;/pcs-web/{pc_id}&#34;, 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
    &#34;&#34;&#34;
81
    Endpoint called from within form for connecting pc with team. Updates certain pc with new team.
82
    &#34;&#34;&#34;
83
    old_pc = crud.update_pc(db, pc_id, team)
84
    pcs = crud.get_pcs(db, skip=skip, limit=limit)
85
    return templates.TemplateResponse(&#34;pcs.html&#34;, {&#34;request&#34;: request, &#34;pcs&#34;: 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(&#34;/pc-team/{pc_id}&#34;, response_class=HTMLResponse)
105
async def connect_pc_team(request: Request, pc_id: int, db: Session = Depends(get_db)):
106
    &#34;&#34;&#34;
107
    Returns template with Form for connecting pc with team
108
    &#34;&#34;&#34;
109
    pc = crud.get_pc(db, pc_id)
110
    teams = crud.get_teams(db, 0, 100)
111
    return templates.TemplateResponse(&#34;pcteam.html&#34;,
112
                                      {&#34;request&#34;: request, &#34;pc&#34;: pc, &#34;teams&#34;: 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(&#34;/pcs-web/{pc_id}&#34;, 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
    &#34;&#34;&#34;
128
    Endpoint called from within form for connecting pc with team. Updates certain pc with new team.
129
    &#34;&#34;&#34;
130
    old_pc = crud.update_pc(db, pc_id, team)
131
    pcs = crud.get_pcs(db, skip=skip, limit=limit)
132
    return templates.TemplateResponse(&#34;pcs.html&#34;, {&#34;request&#34;: request, &#34;pcs&#34;: 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(&#34;/pcs-web&#34;, response_class=HTMLResponse)
162
async def read_pcs(request: Request, skip: int = 0, limit: int = 100, db: Session = Depends(get_db)):
163
    &#34;&#34;&#34;
164
    Returns template with all pcs currently saved in database
165
    &#34;&#34;&#34;
166
    pcs = crud.get_pcs(db, skip=skip, limit=limit)
167
    return templates.TemplateResponse(&#34;pcs.html&#34;, {&#34;request&#34;: request, &#34;pcs&#34;: 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=&#34;/api/v1&#34;)
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(&#34;/team&#34;, response_model=schemas.Team)
51
def create_device(team: schemas.TeamCreate, db: Session = Depends(get_db)):
52
    &#34;&#34;&#34;
53
    Endpoint used for creating new pc
54
    &#34;&#34;&#34;
55
    print(crud.create_team(db=db, name=team.name))
56

  
57

  
58
@teams.get(&#34;/teams&#34;, response_model=List[schemas.Device])
59
def read_devices(skip: int = 0, limit: int = 100, db: Session = Depends(get_db)):
60
    &#34;&#34;&#34;
61
    Returns all pcs saved in database
62
    &#34;&#34;&#34;
63
    teams = crud.get_teams(db, skip=skip, limit=limit)
64
    return teams
65

  
66

  
67
@teams.get(&#34;/team/{team_id}&#34;, response_model=schemas.Device)
68
def read_device(team_id: int, db: Session = Depends(get_db)):
69
    &#34;&#34;&#34;
70
    Returns one specific team by given id
71
    &#34;&#34;&#34;
72
    db_team = crud.get_team(db, team_id=team_id)
73
    if db_team is None:
74
        raise HTTPException(status_code=404, detail=&#34;Device not found&#34;)
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>
... Rozdílový soubor je zkrácen, protože jeho délka přesahuje max. limit.

Také k dispozici: Unified diff