Skip to content

Commit 96f25c3

Browse files
authored
Merge pull request #22 from fmipython/project_pygrader
Project pygrader
2 parents 63aab2a + b5bbce8 commit 96f25c3

File tree

11 files changed

+374
-0
lines changed

11 files changed

+374
-0
lines changed

.DS_Store

-8 KB
Binary file not shown.

15 - Web programming/real_example/README.md

Whitespace-only changes.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
from dataclasses import dataclass
2+
3+
from flask import Flask, request, jsonify, make_response
4+
from tinydb import TinyDB, where, Query
5+
6+
app = Flask(__name__)
7+
db = TinyDB("db.json")
8+
9+
10+
Reward = Query()
11+
12+
13+
@dataclass
14+
class BonusReward:
15+
name: str
16+
code: str
17+
18+
19+
def to_dict(reward: BonusReward) -> dict[str, str]:
20+
return {"name": reward.name, "code": reward.code}
21+
22+
23+
@app.route("/")
24+
def root():
25+
return jsonify(name="Lyubo")
26+
27+
28+
@app.route("/insert/<name>/<code>", methods=["POST"])
29+
def insert(name, code):
30+
current_reward = BonusReward(name, code)
31+
db.insert(to_dict(current_reward))
32+
33+
return jsonify(result="OK")
34+
35+
36+
@app.route("/reward/<name>")
37+
def get(name):
38+
return jsonify(result="OK", rewards=db.search(Reward.name == name))
39+
40+
41+
@app.route("/remove/<code>", methods=["DELETE"])
42+
def remove(code):
43+
matching = db.search(Reward.code == code)
44+
45+
if len(matching) == 0:
46+
# 404
47+
return make_response(jsonify(result="Not found"), 404)
48+
49+
db.remove(Reward.code == code)
50+
51+
return jsonify(result="OK")
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[project]
2+
name = "real-example"
3+
version = "0.1.0"
4+
description = "Add your description here"
5+
readme = "README.md"
6+
requires-python = ">=3.14"
7+
dependencies = [
8+
"flask>=3.1.2",
9+
"tinydb>=4.8.2",
10+
]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
body {
2+
background-color: black;
3+
color: white;
4+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<html>
2+
<head>
3+
<title>Help</title>
4+
5+
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}"/>
6+
</head>
7+
<body>
8+
This is out Flask app !
9+
<br/>
10+
{% block content %}
11+
{% endblock %}
12+
</body>
13+
</html>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{% extends "base.html" %}
2+
3+
{% block content %}
4+
5+
You tried to access a page that doesn't exist !
6+
7+
{% endblock %}
8+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{% extends "base.html" %}
2+
3+
{% block content %}
4+
5+
This is our content from home
6+
7+
{% endblock %}
8+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{% extends "base.html" %}
2+
3+
{% block content %}
4+
5+
This is our content from second - {{foo}}
6+
7+
{% endblock %}
8+

15 - Web programming/real_example/uv.lock

Lines changed: 137 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)