delete files

This commit is contained in:
WorldTeacher
2024-10-10 15:00:17 +02:00
parent 5af4286270
commit 0a294830fa
25 changed files with 0 additions and 12920 deletions

View File

View File

@@ -1,18 +0,0 @@
from src.backend.database import Database
from src.logic.dataclass import ApparatData
apparat = ApparatData()
apparat.appname = "testapparat123"
apparat.appnr = 155
apparat.dauerapp = True
apparat.profname = "Mustermanns, Max"
apparat.subject = "Physik"
apparat.semester = "SoSe 2021"
files = {"name": "test.png", "type": "png", "path": r"C:\Users\aky547\Desktop\test.png"}
db = Database()
# print(db.recreate_file("testfile.pdf",files,3))
# db.insert_file(files,3)
# recreate_file("test.pdf",files,1))#insert_file(files,1))
db.get_apparats_name(70)

View File

@@ -1,45 +0,0 @@
from codebase import Database
from codebase.pickles import load_pickle, make_pickle
from omegaconf import OmegaConf
from webrequest import BibTextTransformer, WebRequest
config = OmegaConf.load("config.yaml")
db = Database()
# # # f = db.get_media(1, 1)
# # # dataclass_objects = []
# # # for dataclass_str in f:
# # # print(f"dataclass {dataclass_str}")
# # # # dataclass_obj = ast.literal_eval(dataclass_str[0])
# # # dataclass_objects.append(dataclass_str)
# # # cla = BookData().from_string(dataclass_objects[0])
# # # print(type(cla))
# # book = (
# # BibTextTransformer("ARRAY")
# # .get_data(WebRequest().get_ppn("ST 250 U42 (15)").get_data())
# # .return_data()
# # )
# # print(book)
# # bpickle = make_pickle(book)
# # print(bpickle)
# # print(load_pickle(bpickle))
# # # print(pickle.dumps(book), type(pickle.dumps(book)))
# # # db.add_medium(book, "2", "1")
# # # db.get_app_data("1", "Testapparat")
# # books = db.get_media(1, 1, 0)
# # print(len(books))
# book = db.get_specific_book(16)
# print(book)
if __name__ == "__main__":
print(db.get_media(15, 2))

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@@ -1,327 +0,0 @@
Module database
===============
Classes
-------
`Database(db_path: str = None)`
: Initialize the database and create the tables if they do not exist.
Default constructor for the database class
Args:
db_path (str, optional): Optional Path for testing / specific purposes. Defaults to None.
### Methods
`addBookToDatabase(self, bookdata: src.logic.dataclass.BookData, app_id: str, prof_id: str)`
: Add books to the database. Both app_id and prof_id are required to add the book to the database, as the app_id and prof_id are used to select the books later on.
Args:
bookdata (BookData): The metadata of the book to be added
app_id (str): The apparat id where the book should be added to
prof_id (str): The id of the professor where the book should be added to.
`addMessage(self, message: dict, user, appnr)`
:
`changePassword(self, user, new_password)`
:
`checkApparatExists(self, apparat_name)`
:
`checkApparatExistsById(self, apparat_id)`
:
`checkUsername(self, user)`
:
`close_connection(self, conn: sqlite3.Connection)`
: closes the connection to the database
Args:
----
- conn (sql.Connection): the connection to be closed
`connect(self) > sqlite3.Connection`
: Connect to the database
Returns:
sql.Connection: The active connection to the database
`createApparat(self, apparat: src.logic.dataclass.ApparatData) > Union[src.errors.DatabaseErrors.AppPresentError, ForwardRef(None), int]`
:
`createProf(self, prof_details: dict)`
:
`createUser(self, user, password, role, salt)`
: Create a user based on passed data.
Args:
----
- username (str): Username to be used
- password (str): the salted password
- role (str): Role of the user
- salt (str): a random salt for the user
`create_tables(self)`
: Create the tables in the database
`deleteApparat(self, appnr, semester)`
:
`deleteBook(self, book_id)`
: Delete a book from the database
Args:
book_id (str): ID of the book
`deleteMessage(self, message_id)`
:
`deleteUser(self, user)`
:
`getAllAparats(self, deleted=0)`
:
`getApparatCountBySemester(self) > tuple[list[str], list[int]]`
:
`getApparatData(self, appnr, appname) > src.logic.dataclass.ApparatData`
:
`getApparatId(self, apparat_name)`
:
`getApparatName(self, app_id, prof_id)`
:
`getApparatsByProf(self, prof_id: int) > list[tuple]`
:
`getApparatsBySemester(self, semester: str) > dict`
:
`getBlob(self, filename, app_id)`
: Get a blob from the database
Args:
filename (str): The name of the file
app_id (str): ID of the apparat
Returns:
bytes: The file stored in
`getBook(self, book_id: int) > src.logic.dataclass.BookData`
: Get the book based on the id in the database
Args:
book_id (int): The id of the book
Returns:
BookData: The metadata of the book wrapped in a BookData object
`getBookBasedOnSignature(self, app_id: str, prof_id: str, signature: str) > src.logic.dataclass.BookData`
: Get the book based on the signature of the book.
Args:
app_id (str): The apparat id the book should be associated with
prof_id (str): The professor id the book should be associated with
signature (str): The signature of the book
Returns:
BookData: The total metadata of the book wrapped in a BookData object
`getBookId(self, bookdata: src.logic.dataclass.BookData, app_id, prof_id) > int`
: Get the id of a book based on the metadata of the book
Args:
bookdata (BookData): The wrapped metadata of the book
app_id (str): The apparat id the book should be associated with
prof_id (str): The professor id the book should be associated with
Returns:
int: ID of the book
`getBookIdBasedOnSignature(self, app_id: str, prof_id: str, signature: str) > int`
: Get a book id based on the signature of the book.
Args:
app_id (str): The apparat id the book should be associated with
prof_id (str): The professor id the book should be associated with
signature (str): The signature of the book
Returns:
int: The id of the book
`getBooks(self, app_id, prof_id, deleted=0) > list[dict[int, src.logic.dataclass.BookData, int]]`
: Get the Books based on the apparat id and the professor id
Args:
app_id (str): The ID of the apparat
prof_id (str): The ID of the professor
deleted (int, optional): The state of the book. Set to 1 to include deleted ones. Defaults to 0.
Returns:
list[dict[int, BookData, int]]: A list of dictionaries containing the id, the metadata of the book and the availability of the book
`getFacultyMember(self, name: str)`
:
`getFacultyMembers(self)`
:
`getFiles(self, app_id: int, prof_id: int) > list[tuple]`
:
`getLastBookId(self) > int`
: Get the last book id in the database
Returns:
int: ID of the last book in the database
`getMessages(self, date: str)`
:
`getProfByName(self, prof_name: str)`
:
`getProfData(self, profname: str)`
:
`getProfId(self, prof_name: str)`
: getProfId _summary_
:param prof_name: _description_
:type prof_name: str
:return: _description_
:rtype: _type_
`getProfNameById(self, prof_id: int, add_title: bool = False)`
:
`getProfs(self)`
:
`getRole(self, user)`
:
`getRoles(self)`
:
`getSemersters(self)`
:
`getSpecificProfData(self, prof_id: int, fields: List[str])`
: getSpecificProfData _summary_
Args:
----
- prof_id (int): _description_
- fields (List[str]): _description_
Returns:
-------
- _type_: _description_
`getSubjects(self)`
:
`getTitleById(self, prof_id: int)`
:
`getUnavailableApparatNumbers(self) > List[int]`
: getUnavailableApparatNumbers returns a list of all currently used ApparatNumbers
Returns:
-------
- number(List[int]): a list of all currently used apparat numbers
`getUser(self)`
:
`getUsers(self)`
:
`get_db_contents(self) > Optional[List[Tuple]]`
: Get the contents of the
Returns:
Union[List[Tuple], None]: _description_
`insertFile(self, file: list[dict], app_id: int, prof_id)`
:
`insertInto(self, query: str, params: Tuple) > None`
: Insert sent data into the database
Args:
query (str): The query to be executed
params (Tuple): the parameters to be inserted into the database
`isEternal(self, id)`
:
`login(self, user, hashed_password)`
:
`query_db(self, query: str, args: Tuple = (), one: bool = False) > Union[Tuple, List[Tuple]]`
: Query the Database for the sent query.
Args:
query (str): The query to be executed
args (Tuple, optional): The arguments for the query. Defaults to ().
one (bool, optional): Return the first result only. Defaults to False.
Returns:
Union[Typle|List[Tuple]]: Returns the result of the query
`recreateFile(self, filename, app_id, filetype)`
:
`searchBook(self, data: dict[str, str]) > list[tuple[src.logic.dataclass.BookData, int]]`
: Search a book in the database based on the sent data.
Args:
data (dict[str, str]): A dictionary containing the data to be searched for. The dictionary can contain the following:
- signature: The signature of the book
- title: The title of the book
Returns:
list[tuple[BookData, int]]: A list of tuples containing the wrapped Metadata and the id of the book
`setAvailability(self, book_id: str, available: str)`
: Set the availability of a book in the database
Args:
book_id (str): The id of the book
available (str): The availability of the book
`setNewSemesterDate(self, appnr, newDate, dauerapp=False)`
:
`statistic_request(self, **kwargs: Any)`
:
`updateApparat(self, apparat_data: src.logic.dataclass.ApparatData)`
:
`updateBookdata(self, book_id, bookdata: src.logic.dataclass.BookData)`
: Update the bookdata in the database
Args:
book_id (str): The id of the book
bookdata (BookData): The new metadata of the book
`updateFacultyMember(self, data, oldlname, oldfname)`
:
`updateUser(self, username, data: dict[str, str])`
:

View File

@@ -1,132 +0,0 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
<meta name="generator" content="pdoc 0.10.0" />
<title>db API documentation</title>
<meta name="description" content="" />
<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>
<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>
<link rel="stylesheet preload" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/styles/github.min.css" crossorigin>
<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>
<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>
<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>
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/highlight.min.js" integrity="sha256-Uv3H6lx7dJmRfRvH8TH6kJD1TSK1aFcwgx+mdg3epi8=" crossorigin></script>
<script>window.addEventListener('DOMContentLoaded', () => hljs.initHighlighting())</script>
</head>
<body>
<main>
<article id="content">
<header>
<h1 class="title">Module <code>db</code></h1>
</header>
<section>
<p>Module <code>db</code> provides the database schema for the semesterapparat application.</p>
</section>
<section id="section-intro">
<details class="source" open="">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">CREATE_TABLE_APPARAT = &#34;&#34;&#34;CREATE TABLE semesterapparat (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
name TEXT,
prof_id INTEGER,
fach TEXT,
appnr INTEGER,
erstellsemester TEXT,
verlängert_am TEXT,
dauer BOOLEAN,
verlängerung_bis TEXT,
deletion_status INTEGER,
deleted_date TEXT,
apparat_id_adis INTEGER,
prof_id_adis INTEGER,
konto INTEGER REFERENCES app_kontos (id),
FOREIGN KEY (prof_id) REFERENCES prof (id)
)&#34;&#34;&#34;
CREATE_TABLE_MEDIA = &#34;&#34;&#34;CREATE TABLE media (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
bookdata BLOB,
app_id INTEGER,
prof_id INTEGER,
deleted INTEGER DEFAULT (0),
available BOOLEAN,
reservation BOOLEAN,
FOREIGN KEY (prof_id) REFERENCES prof (id),
FOREIGN KEY (app_id) REFERENCES semesterapparat (id)
)&#34;&#34;&#34;
CREATE_TABLE_APPKONTOS = &#34;&#34;&#34;CREATE TABLE app_kontos (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
app_id INTEGER,
konto INTEGER,
passwort TEXT,
FOREIGN KEY (app_id) REFERENCES semesterapparat (id)
)&#34;&#34;&#34;
CREATE_TABLE_FILES = &#34;&#34;&#34;CREATE TABLE files (
id INTEGER PRIMARY KEY,
filename TEXT,
fileblob BLOB,
app_id INTEGER,
filetyp TEXT,
prof_id INTEGER REFERENCES prof (id),
FOREIGN KEY (app_id) REFERENCES semesterapparat (id)
)&#34;&#34;&#34;
CREATE_TABLE_MESSAGES = &#34;&#34;&#34;CREATE TABLE messages (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
created_at date NOT NULL DEFAULT CURRENT_TIMESTAMP,
message TEXT NOT NULL,
remind_at date NOT NULL DEFAULT CURRENT_TIMESTAMP,
user_id INTEGER NOT NULL,
appnr INTEGER,
FOREIGN KEY (user_id) REFERENCES user (id)
)&#34;&#34;&#34;
CREATE_TABLE_PROF = &#34;&#34;&#34;CREATE TABLE prof (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
titel TEXT,
fname TEXT,
lname TEXT,
fullname TEXT NOT NULL UNIQUE,
mail TEXT,
telnr TEXT
)&#34;&#34;&#34;
CREATE_TABLE_USER = &#34;&#34;&#34;CREATE TABLE user (
id integer NOT NULL PRIMARY KEY AUTOINCREMENT,
created_at datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
username TEXT NOT NULL UNIQUE,
password TEXT NOT NULL,
salt TEXT NOT NULL,
role TEXT NOT NULL,
email TEXT UNIQUE,
name TEXT
)&#34;&#34;&#34;
CREATE_TABLE_SUBJECTS = &#34;&#34;&#34;CREATE TABLE subjects (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
name TEXT NOT NULL UNIQUE
)&#34;&#34;&#34;</code></pre>
</details>
</section>
<section>
</section>
<section>
</section>
<section>
</section>
<section>
</section>
</article>
<nav id="sidebar">
<h1>Index</h1>
<div class="toc">
<ul></ul>
</div>
<ul id="index">
</ul>
</nav>
</main>
<footer id="footer">
<p>Generated by <a href="https://pdoc3.github.io/pdoc" title="pdoc: Python API documentation generator"><cite>pdoc</cite> 0.10.0</a>.</p>
</footer>
</body>
</html>

View File

View File

@@ -1,18 +0,0 @@
# Welcome to MkDocs
For full documentation visit [mkdocs.org](https://www.mkdocs.org).
## Commands
* `mkdocs new [dir-name]` - Create a new project.
* `mkdocs serve` - Start the live-reloading docs server.
* `mkdocs build` - Build the documentation site.
* `mkdocs -h` - Print help message and exit.
## Project layout
mkdocs.yml # The configuration file.
docs/
index.md # The documentation homepage.
database.md # Documentation of the Database and it's tables
... # Other markdown pages, images and other files.

File diff suppressed because it is too large Load Diff

View File

@@ -1,132 +0,0 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
<meta name="generator" content="pdoc 0.10.0" />
<title>db API documentation</title>
<meta name="description" content="" />
<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>
<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>
<link rel="stylesheet preload" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/styles/github.min.css" crossorigin>
<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>
<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>
<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>
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/highlight.min.js" integrity="sha256-Uv3H6lx7dJmRfRvH8TH6kJD1TSK1aFcwgx+mdg3epi8=" crossorigin></script>
<script>window.addEventListener('DOMContentLoaded', () => hljs.initHighlighting())</script>
</head>
<body>
<main>
<article id="content">
<header>
<h1 class="title">Module <code>db</code></h1>
</header>
<section>
<p>Module <code>db</code> provides the database schema for the semesterapparat application.</p>
</section>
<section id="section-intro">
<details class="source" open="">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">CREATE_TABLE_APPARAT = &#34;&#34;&#34;CREATE TABLE semesterapparat (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
name TEXT,
prof_id INTEGER,
fach TEXT,
appnr INTEGER,
erstellsemester TEXT,
verlängert_am TEXT,
dauer BOOLEAN,
verlängerung_bis TEXT,
deletion_status INTEGER,
deleted_date TEXT,
apparat_id_adis INTEGER,
prof_id_adis INTEGER,
konto INTEGER REFERENCES app_kontos (id),
FOREIGN KEY (prof_id) REFERENCES prof (id)
)&#34;&#34;&#34;
CREATE_TABLE_MEDIA = &#34;&#34;&#34;CREATE TABLE media (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
bookdata BLOB,
app_id INTEGER,
prof_id INTEGER,
deleted INTEGER DEFAULT (0),
available BOOLEAN,
reservation BOOLEAN,
FOREIGN KEY (prof_id) REFERENCES prof (id),
FOREIGN KEY (app_id) REFERENCES semesterapparat (id)
)&#34;&#34;&#34;
CREATE_TABLE_APPKONTOS = &#34;&#34;&#34;CREATE TABLE app_kontos (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
app_id INTEGER,
konto INTEGER,
passwort TEXT,
FOREIGN KEY (app_id) REFERENCES semesterapparat (id)
)&#34;&#34;&#34;
CREATE_TABLE_FILES = &#34;&#34;&#34;CREATE TABLE files (
id INTEGER PRIMARY KEY,
filename TEXT,
fileblob BLOB,
app_id INTEGER,
filetyp TEXT,
prof_id INTEGER REFERENCES prof (id),
FOREIGN KEY (app_id) REFERENCES semesterapparat (id)
)&#34;&#34;&#34;
CREATE_TABLE_MESSAGES = &#34;&#34;&#34;CREATE TABLE messages (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
created_at date NOT NULL DEFAULT CURRENT_TIMESTAMP,
message TEXT NOT NULL,
remind_at date NOT NULL DEFAULT CURRENT_TIMESTAMP,
user_id INTEGER NOT NULL,
appnr INTEGER,
FOREIGN KEY (user_id) REFERENCES user (id)
)&#34;&#34;&#34;
CREATE_TABLE_PROF = &#34;&#34;&#34;CREATE TABLE prof (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
titel TEXT,
fname TEXT,
lname TEXT,
fullname TEXT NOT NULL UNIQUE,
mail TEXT,
telnr TEXT
)&#34;&#34;&#34;
CREATE_TABLE_USER = &#34;&#34;&#34;CREATE TABLE user (
id integer NOT NULL PRIMARY KEY AUTOINCREMENT,
created_at datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
username TEXT NOT NULL UNIQUE,
password TEXT NOT NULL,
salt TEXT NOT NULL,
role TEXT NOT NULL,
email TEXT UNIQUE,
name TEXT
)&#34;&#34;&#34;
CREATE_TABLE_SUBJECTS = &#34;&#34;&#34;CREATE TABLE subjects (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
name TEXT NOT NULL UNIQUE
)&#34;&#34;&#34;</code></pre>
</details>
</section>
<section>
</section>
<section>
</section>
<section>
</section>
<section>
</section>
</article>
<nav id="sidebar">
<h1>Index</h1>
<div class="toc">
<ul></ul>
</div>
<ul id="index">
</ul>
</nav>
</main>
<footer id="footer">
<p>Generated by <a href="https://pdoc3.github.io/pdoc" title="pdoc: Python API documentation generator"><cite>pdoc</cite> 0.10.0</a>.</p>
</footer>
</body>
</html>

File diff suppressed because it is too large Load Diff

View File

@@ -1,327 +0,0 @@
Module database
===============
Classes
-------
`Database(db_path: str = None)`
: Initialize the database and create the tables if they do not exist.
Default constructor for the database class
Args:
db_path (str, optional): Optional Path for testing / specific purposes. Defaults to None.
### Methods
`addBookToDatabase(self, bookdata: src.logic.dataclass.BookData, app_id: str, prof_id: str)`
: Add books to the database. Both app_id and prof_id are required to add the book to the database, as the app_id and prof_id are used to select the books later on.
Args:
bookdata (BookData): The metadata of the book to be added
app_id (str): The apparat id where the book should be added to
prof_id (str): The id of the professor where the book should be added to.
`addMessage(self, message: dict, user, appnr)`
:
`changePassword(self, user, new_password)`
:
`checkApparatExists(self, apparat_name)`
:
`checkApparatExistsById(self, apparat_id)`
:
`checkUsername(self, user)`
:
`close_connection(self, conn: sqlite3.Connection)`
: closes the connection to the database
Args:
----
- conn (sql.Connection): the connection to be closed
`connect(self) > sqlite3.Connection`
: Connect to the database
Returns:
sql.Connection: The active connection to the database
`createApparat(self, apparat: src.logic.dataclass.ApparatData) > Union[src.errors.DatabaseErrors.AppPresentError, ForwardRef(None), int]`
:
`createProf(self, prof_details: dict)`
:
`createUser(self, user, password, role, salt)`
: Create a user based on passed data.
Args:
----
- username (str): Username to be used
- password (str): the salted password
- role (str): Role of the user
- salt (str): a random salt for the user
`create_tables(self)`
: Create the tables in the database
`deleteApparat(self, appnr, semester)`
:
`deleteBook(self, book_id)`
: Delete a book from the database
Args:
book_id (str): ID of the book
`deleteMessage(self, message_id)`
:
`deleteUser(self, user)`
:
`getAllAparats(self, deleted=0)`
:
`getApparatCountBySemester(self) > tuple[list[str], list[int]]`
:
`getApparatData(self, appnr, appname) > src.logic.dataclass.ApparatData`
:
`getApparatId(self, apparat_name)`
:
`getApparatName(self, app_id, prof_id)`
:
`getApparatsByProf(self, prof_id: int) > list[tuple]`
:
`getApparatsBySemester(self, semester: str) > dict`
:
`getBlob(self, filename, app_id)`
: Get a blob from the database
Args:
filename (str): The name of the file
app_id (str): ID of the apparat
Returns:
bytes: The file stored in
`getBook(self, book_id: int) > src.logic.dataclass.BookData`
: Get the book based on the id in the database
Args:
book_id (int): The id of the book
Returns:
BookData: The metadata of the book wrapped in a BookData object
`getBookBasedOnSignature(self, app_id: str, prof_id: str, signature: str) > src.logic.dataclass.BookData`
: Get the book based on the signature of the book.
Args:
app_id (str): The apparat id the book should be associated with
prof_id (str): The professor id the book should be associated with
signature (str): The signature of the book
Returns:
BookData: The total metadata of the book wrapped in a BookData object
`getBookId(self, bookdata: src.logic.dataclass.BookData, app_id, prof_id) > int`
: Get the id of a book based on the metadata of the book
Args:
bookdata (BookData): The wrapped metadata of the book
app_id (str): The apparat id the book should be associated with
prof_id (str): The professor id the book should be associated with
Returns:
int: ID of the book
`getBookIdBasedOnSignature(self, app_id: str, prof_id: str, signature: str) > int`
: Get a book id based on the signature of the book.
Args:
app_id (str): The apparat id the book should be associated with
prof_id (str): The professor id the book should be associated with
signature (str): The signature of the book
Returns:
int: The id of the book
`getBooks(self, app_id, prof_id, deleted=0) > list[dict[int, src.logic.dataclass.BookData, int]]`
: Get the Books based on the apparat id and the professor id
Args:
app_id (str): The ID of the apparat
prof_id (str): The ID of the professor
deleted (int, optional): The state of the book. Set to 1 to include deleted ones. Defaults to 0.
Returns:
list[dict[int, BookData, int]]: A list of dictionaries containing the id, the metadata of the book and the availability of the book
`getFacultyMember(self, name: str)`
:
`getFacultyMembers(self)`
:
`getFiles(self, app_id: int, prof_id: int) > list[tuple]`
:
`getLastBookId(self) > int`
: Get the last book id in the database
Returns:
int: ID of the last book in the database
`getMessages(self, date: str)`
:
`getProfByName(self, prof_name: str)`
:
`getProfData(self, profname: str)`
:
`getProfId(self, prof_name: str)`
: getProfId _summary_
:param prof_name: _description_
:type prof_name: str
:return: _description_
:rtype: _type_
`getProfNameById(self, prof_id: int, add_title: bool = False)`
:
`getProfs(self)`
:
`getRole(self, user)`
:
`getRoles(self)`
:
`getSemersters(self)`
:
`getSpecificProfData(self, prof_id: int, fields: List[str])`
: getSpecificProfData _summary_
Args:
----
- prof_id (int): _description_
- fields (List[str]): _description_
Returns:
-------
- _type_: _description_
`getSubjects(self)`
:
`getTitleById(self, prof_id: int)`
:
`getUnavailableApparatNumbers(self) > List[int]`
: getUnavailableApparatNumbers returns a list of all currently used ApparatNumbers
Returns:
-------
- number(List[int]): a list of all currently used apparat numbers
`getUser(self)`
:
`getUsers(self)`
:
`get_db_contents(self) > Optional[List[Tuple]]`
: Get the contents of the
Returns:
Union[List[Tuple], None]: _description_
`insertFile(self, file: list[dict], app_id: int, prof_id)`
:
`insertInto(self, query: str, params: Tuple) > None`
: Insert sent data into the database
Args:
query (str): The query to be executed
params (Tuple): the parameters to be inserted into the database
`isEternal(self, id)`
:
`login(self, user, hashed_password)`
:
`query_db(self, query: str, args: Tuple = (), one: bool = False) > Union[Tuple, List[Tuple]]`
: Query the Database for the sent query.
Args:
query (str): The query to be executed
args (Tuple, optional): The arguments for the query. Defaults to ().
one (bool, optional): Return the first result only. Defaults to False.
Returns:
Union[Typle|List[Tuple]]: Returns the result of the query
`recreateFile(self, filename, app_id, filetype)`
:
`searchBook(self, data: dict[str, str]) > list[tuple[src.logic.dataclass.BookData, int]]`
: Search a book in the database based on the sent data.
Args:
data (dict[str, str]): A dictionary containing the data to be searched for. The dictionary can contain the following:
- signature: The signature of the book
- title: The title of the book
Returns:
list[tuple[BookData, int]]: A list of tuples containing the wrapped Metadata and the id of the book
`setAvailability(self, book_id: str, available: str)`
: Set the availability of a book in the database
Args:
book_id (str): The id of the book
available (str): The availability of the book
`setNewSemesterDate(self, appnr, newDate, dauerapp=False)`
:
`statistic_request(self, **kwargs: Any)`
:
`updateApparat(self, apparat_data: src.logic.dataclass.ApparatData)`
:
`updateBookdata(self, book_id, bookdata: src.logic.dataclass.BookData)`
: Update the bookdata in the database
Args:
book_id (str): The id of the book
bookdata (BookData): The new metadata of the book
`updateFacultyMember(self, data, oldlname, oldfname)`
:
`updateUser(self, username, data: dict[str, str])`
:

View File

@@ -1,16 +0,0 @@
<RCC>
<qresource prefix="icons">
<file>resources/logo_SAP.ico</file>
<file>resources/logo_SAP.png</file>
<file>resources/1f4e7.svg</file>
<file>resources/1f510.svg</file>
<file>resources/2795.svg</file>
<file>resources/VZjRNn1k.ico</file>
</qresource>
<qresource prefix="notifications">
<file>resources/critical.png</file>
<file>resources/information.png</file>
<file>resources/question.png</file>
<file>resources/warning.png</file>
</qresource>
</RCC>

View File

@@ -1,77 +0,0 @@
# Exclude a variety of commonly ignored directories.
exclude = [
".bzr",
".direnv",
".eggs",
".git",
".git-rewrite",
".hg",
".ipynb_checkpoints",
".mypy_cache",
".nox",
".pants.d",
".pyenv",
".pytest_cache",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
".vscode",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"site-packages",
"venv",
]
# Same as Black.
line-length = 88
indent-width = 4
# Assume Python 3.8
target-version = "py312"
[lint]
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
# Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or
# McCabe complexity (`C901`) by default.
select = ["E4", "E7", "E9", "F"]
ignore = []
# Allow fix for all enabled rules (when `--fix`) is provided.
fixable = ["ALL"]
unfixable = []
# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
[format]
# Like Black, use double quotes for strings.
quote-style = "double"
# Like Black, indent with spaces, rather than tabs.
indent-style = "space"
# Like Black, respect magic trailing commas.
skip-magic-trailing-comma = false
# Like Black, automatically detect the appropriate line ending.
line-ending = "auto"
# Enable auto-formatting of code examples in docstrings. Markdown,
# reStructuredText code/literal blocks and doctests are all supported.
#
# This is currently disabled by default, but it is planned for this
# to be opt-out in the future.
docstring-code-format = false
# Set the line length limit used when formatting code snippets in
# docstrings.
#
# This only has an effect when the `docstring-code-format` setting is
# enabled.
docstring-code-line-length = "dynamic"

BIN
sap.db

Binary file not shown.

View File

View File

View File

@@ -1,66 +0,0 @@
from src.backend.database import Database
from src.logic.webrequest import BibTextTransformer, WebRequest
import sqlite3
class BookGrabber:
def __init__(
self,
mode: str = None,
data: list = None,
app_id: int = None,
prof_id: int = None,
):
self.app_id = app_id
self.prof_id = prof_id
self.mode = mode
self.data = data
self.book_id = None
def run(self):
self.db = Database()
item = 0
for entry in self.data:
signature = str(entry)
self.logger.log_info("Processing entry: " + signature)
webdata = WebRequest().get_ppn(entry).get_data()
if webdata == "error":
continue
bd = BibTextTransformer(self.mode).get_data(webdata).return_data()
transformer = BibTextTransformer("RDS")
rds = transformer.get_data(webdata).return_data("rds_availability")
bd.signature = entry
# confirm lock is acquired
print("lock acquired, adding book to database")
self.db.addBookToDatabase(bd, self.app_id, self.prof_id)
# get latest book id
self.book_id = self.db.getLastBookId()
self.logger.log_info("Added book to database")
state = 0
for rds_item in rds.items:
sign = rds_item.superlocation
loc = rds_item.location
# print(item.location)
if self.app_id in sign or self.app_id in loc:
state = 1
book_id = None
# for book in self.books:
# if book["bookdata"].signature == entry:
# book_id = book["id"]
# break
self.logger.log_info(f"State of {signature}: {state}")
print(
"lock acquired, updating availability of "
+ str(book_id)
+ " to "
+ str(state)
)
try:
self.db.setAvailability(self.book_id, state)
except sqlite3.OperationalError as e:
self.logger.log_error(f"Failed to update availability: {e}")
break
# time.sleep(5)
item += 1

View File

@@ -1,17 +0,0 @@
import pytest
from src.backend.database import Database
def test_prof():
assert Database().getProfNameById(1, add_title=True) == "Karoß Sabine"
assert Database().getProfNameById(1, add_title=False) == "Karoß Sabine"
assert Database().getProfId("Karoß Sabine") == 1
def test_apparat():
assert Database().getApparatName(3, 1) == "Theorie und Praxis Gymnastik"
def test_admin():
assert len(Database().getUser()) >= 1 and "admin" in Database().getUser()

View File

@@ -1,10 +0,0 @@
from test.webrequest_test import test_webdata_bibtexttransform
def many_test_webdata():
test_webdata_bibtexttransform("RIS")
test_webdata_bibtexttransform("BibTeX")
test_webdata_bibtexttransform("COinS")
test_webdata_bibtexttransform("ARRAY")
test_webdata_bibtexttransform("RDS")
assert True is True

View File

@@ -1,103 +0,0 @@
def contact_prof(self):
dialog = QtWidgets.QDialog()
mail_prev = Mail_Dialog()
mail_prev.setupUi(dialog)
mail_prevs = os.listdir("mail_vorlagen")
if self.app_name.text() == "":
mail_prevs.remove("Information zum Semesterapparat.eml")
mail_prev.comboBox.addItems(mail_prevs)
active_apparat_id = self.tableWidget_apparate.item(
self.tableWidget_apparate.currentRow(), 0
).text()
general_data = {
"Appname": self.app_name.text(),
"AppSubject": self.app_fach.currentText(),
"appnr": self.active_apparat,
}
print(active_apparat_id)
mail_prev.appid = active_apparat_id
base_data = self.db.getProfData(id=active_apparat_id)
profname = self.db.getProfNameById(base_data["id"])
profname = profname.split(" ")
profname = f"{profname[1]} {profname[0]}"
pass_data = {
"prof_name": profname,
"mail_name": base_data["prof_mail"],
"general": general_data,
}
mail_prev.set_data(pass_data)
mail_prev.set_mail()
dialog.exec()
import subprocess
import tempfile
from PyQt6 import QtCore, QtGui, QtWidgets
from src.ui.dialogs.mail_preview import Ui_Dialog
class Mail_Dialog(QtWidgets.QDialog, Ui_Dialog):
def __init__(self, parent=None):
super().__init__(parent)
self.setupUi(self)
self.appid = ""
self.mail_data = ""
self.data = None
self.buttonBox.accepted.connect(self.save_mail)
def set_data(self, data: dict):
print(data)
self.prof_name.setText(data["prof_name"])
self.mail_name.setText(data["mail_name"])
# assign data["general"] to self.data
self.data = data["general"]
def set_mail(self):
email_template = self.comboBox.currentText()
with open(f"mail_vorlagen/{email_template}", "r", encoding="utf-8") as f:
mail_template = f.read()
email_header = email_template.split(".eml")[0]
if "{AppNr}" in email_template:
email_header = email_template.split(".eml")[0].format(AppNr=self.appid)
self.mail_header.setText(email_header)
self.mail_data = mail_template.split("<html>")[0]
mail_html = mail_template.split("<html>")[1]
mail_html = "<html>" + mail_html
print(self.data)
Appname = self.data["Appname"]
mail_html = mail_html.format(
Profname=self.prof_name.text().split(" ")[-1], Appname=Appname
)
self.mail_body.setHtml(mail_html)
def save_mail(self):
# create a temporary file
mail_header = self.mail_header.text()
mail_body = self.mail_body.toHtml()
mail = self.mail_data + mail_body
mail = mail.replace("Subject:", f"Subject: {mail_header}")
with tempfile.NamedTemporaryFile(
mode="w", delete=False, suffix=".eml", encoding="utf-8", dir="mails"
) as f:
f.write(mail)
self.mail_path = f.name
print(self.mail_path)
# open the file using thunderbird
subprocess.Popen(["thunderbird", f"{self.mail_path}"])
# delete the file
# os.remove(self.mail_path)
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Dialog = QtWidgets.QDialog()
ui = Mail_Dialog()
ui.setupUi(Dialog)
Dialog.show()
sys.exit(app.exec())

View File

@@ -1,7 +0,0 @@
import pytest
from src.backend.semester import generateSemesterByDate
def test_generateSemesterByDate():
assert generateSemesterByDate() == "WiSe 23/24"

View File

@@ -1,4 +0,0 @@
from src.backend.database import Database
db = Database("semap.db")
# print(db.query_db("SELECT * FROM subjects WHERE id=1"))

View File

@@ -1,18 +0,0 @@
import pytest
from src.logic.dataclass import BookData
from src.logic.webrequest import BibTextTransformer, WebRequest
def test_webdata_bibtexttransform(source_data: str = "RIS"):
request = WebRequest().get_ppn("ST 250 U42 (15) ").get_data()
assert isinstance(request, list) is True
assert len(request) > 0
model: BookData = BibTextTransformer(source_data).get_data(request).return_data()
assert model is not None
assert model.signature == "ST 250 U42 (15)"
assert model.ppn == "1693321114"
assert model.author == "Ullenboom, Christian"
assert model.link == "https://rds.ibs-bw.de/phfreiburg/link?kid=1693321114"
assert model.pages == "1246"
assert model.publisher == "Rheinwerk Computing"