Skip to content

Commit

Permalink
Re-enable oneswipe
Browse files Browse the repository at this point in the history
  • Loading branch information
hackenbergstefan committed Jan 4, 2025
1 parent 582b6b6 commit ed0fbd4
Show file tree
Hide file tree
Showing 14 changed files with 290 additions and 255 deletions.
36 changes: 18 additions & 18 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ on: [push]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.10", "3.11"]
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install --user pdm
pdm sync -G dev
- name: Format
run: |
pdm run ruff format --check .
- name: Lint
run: |
pdm run ruff check .
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.13"
- name: Install dependencies
run: |
pip install --user pdm
pdm sync -G dev
- name: Format
run: |
pdm run ruff format --check .
- name: Lint
run: |
pdm run ruff check .
- name: Djlint
run: |
pdm run djlint coffeebuddy
96 changes: 48 additions & 48 deletions .github/workflows/test_backends.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,51 +7,51 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v1
with:
python-version: 3.8
- name: Install dependencies
run: |
sudo apt-get install libpcsclite-dev
pip install --user pdm
pdm sync --prod
- name: Test backend sqlite
run: |
sed -i 's/^CARD.*/CARD = ""/' config.py
sed -i 's/^FACERECOGNITION.*/FACERECOGNITION = False/' config.py
sed -i 's/^PIR.*/PIR = False/' config.py
sed -i 's/^ILLUMINATION.*/ILLUMINATION = False/' config.py
sed -i 's/^DB_BACKEND.*/DB_BACKEND = "sqlite"/' config.py
pdm run ./bin/run.py &
pid=$!
sleep 1
ps | grep -c $pid || wait $pid
kill -SIGTERM $pid
- name: Test backend postgresql
run: |
sed -i 's/^CARD.*/CARD = ""/' config.py
sed -i 's/^FACERECOGNITION.*/FACERECOGNITION = False/' config.py
sed -i 's/^PIR.*/PIR = False/' config.py
sed -i 's/^ILLUMINATION.*/ILLUMINATION = False/' config.py
sed -i 's/^DB_BACKEND.*/DB_BACKEND = "postgres"/' config.py
pdm run ./bin/run.py &
pid=$!
sleep 1
ps | grep -c $pid || wait $pid
kill -SIGTERM $pid
- name: Test backend testing
run: |
sed -i 's/^CARD.*/CARD = ""/' config.py
sed -i 's/^FACERECOGNITION.*/FACERECOGNITION = False/' config.py
sed -i 's/^PIR.*/PIR = False/' config.py
sed -i 's/^ILLUMINATION.*/ILLUMINATION = False/' config.py
sed -i 's/^DB_BACKEND.*/DB_BACKEND = "sqlite"/' config.py
export FLASK_ENV=prefilled
export FLASK_DEBUG=true
pdm run ./bin/run.py &
pid=$!
sleep 1
ps | grep -c $pid || wait $pid
kill -SIGTERM $pid
- uses: actions/checkout@v2
- name: Set up Python 3.13
uses: actions/setup-python@v5
with:
python-version: 3.13
- name: Install dependencies
run: |
sudo apt-get install libpcsclite-dev
pip install --user pdm
pdm sync --prod
- name: Test backend sqlite
run: |
sed -i 's/^CARD.*/CARD = ""/' config.py
sed -i 's/^FACERECOGNITION.*/FACERECOGNITION = False/' config.py
sed -i 's/^PIR.*/PIR = False/' config.py
sed -i 's/^ILLUMINATION.*/ILLUMINATION = False/' config.py
sed -i 's/^DB_BACKEND.*/DB_BACKEND = "sqlite"/' config.py
pdm run ./bin/run.py &
pid=$!
sleep 1
ps | grep -c $pid || wait $pid
kill -SIGTERM $pid
- name: Test backend postgresql
run: |
sed -i 's/^CARD.*/CARD = ""/' config.py
sed -i 's/^FACERECOGNITION.*/FACERECOGNITION = False/' config.py
sed -i 's/^PIR.*/PIR = False/' config.py
sed -i 's/^ILLUMINATION.*/ILLUMINATION = False/' config.py
sed -i 's/^DB_BACKEND.*/DB_BACKEND = "postgres"/' config.py
pdm run ./bin/run.py &
pid=$!
sleep 1
ps | grep -c $pid || wait $pid
kill -SIGTERM $pid
- name: Test backend testing
run: |
sed -i 's/^CARD.*/CARD = ""/' config.py
sed -i 's/^FACERECOGNITION.*/FACERECOGNITION = False/' config.py
sed -i 's/^PIR.*/PIR = False/' config.py
sed -i 's/^ILLUMINATION.*/ILLUMINATION = False/' config.py
sed -i 's/^DB_BACKEND.*/DB_BACKEND = "sqlite"/' config.py
export FLASK_ENV=prefilled
export FLASK_DEBUG=true
pdm run ./bin/run.py &
pid=$!
sleep 1
ps | grep -c $pid || wait $pid
kill -SIGTERM $pid
56 changes: 28 additions & 28 deletions .github/workflows/test_dockerdb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,31 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Patch docker-compose.yml
run: sed -i 's,.*/mnt/ssd/postgresql.*,#\\0,' database/docker-compose.yml
- name: Setup certificates
run: |
cd database
echo -e "1\nn" | ./gen_certs.sh
echo -e "2\ncoffeebuddydb" | ./gen_certs.sh
echo -e "3\ncoffeebuddy01\nn" | ./gen_certs.sh
- name: Create container
run: |
cd database
docker compose up
- name: Start container again
run: |
cd database
docker compose up -d
sleep 5
PGSSLMODE=require \
PGSSLROOTCERT=certs/ca/root.crt \
PGSSLCERT=certs/client_coffeebuddy01/postgresql.crt \
PGSSLKEY=certs/client_coffeebuddy01/postgresql.key \
psql -U coffeebuddy01 -h localhost -d coffeebuddy -lqt
- name: Stop containers
if: always()
run: |
cd database
docker compose down
- uses: actions/checkout@v2
- name: Patch docker-compose.yml
run: sed -i 's,.*/mnt/ssd/postgresql.*,#\\0,' database/docker-compose.yml
- name: Setup certificates
run: |
cd database
echo -e "1\nn" | ./gen_certs.sh
echo -e "2\ncoffeebuddydb" | ./gen_certs.sh
echo -e "3\ncoffeebuddy01\nn" | ./gen_certs.sh
- name: Create container
run: |
cd database
docker compose up
- name: Start container again
run: |
cd database
docker compose up -d
sleep 5
PGSSLMODE=require \
PGSSLROOTCERT=certs/ca/root.crt \
PGSSLCERT=certs/client_coffeebuddy01/postgresql.crt \
PGSSLKEY=certs/client_coffeebuddy01/postgresql.key \
psql -U coffeebuddy01 -h localhost -d coffeebuddy -lqt
- name: Stop containers
if: always()
run: |
cd database
docker compose down
5 changes: 3 additions & 2 deletions coffeebuddy/extensions/coffeemaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def brew(self, data):
def init():
logging.getLogger(__name__).info("Init")
app = flask.current_app
config = app.config.get("COFFEEMAKER", None) or {}

if (brew_time := app.config.get("COFFEEMAKER_MOCK_BREW_TIME", False)) is not False:
CoffeeMakerMock(brew_time=brew_time)
if "mock" in config:
CoffeeMakerMock(brew_time=config["mock"])
2 changes: 1 addition & 1 deletion coffeebuddy/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import flask
import sqlalchemy
from sqlalchemy import Column, ForeignKey, Integer, Table, select, text
from sqlalchemy.orm import Mapped, backref, mapped_column, relationship
from sqlalchemy.orm import Mapped, mapped_column, relationship

from . import Base

Expand Down
6 changes: 5 additions & 1 deletion coffeebuddy/ui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ def url(site: str, **kwargs):
for key, value in kwargs.items():
if isinstance(value, bytes):
kwargs[key] = value.hex()
return site + "?" + "&".join(f"{key}={value}" for key, value in kwargs.items())
return (
site
+ "?"
+ "&".join(f"{key}={value}" if value else key for key, value in kwargs.items())
)


@flask.current_app.context_processor
Expand Down
4 changes: 2 additions & 2 deletions coffeebuddy/ui/base/templates/selectuser.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ <h3>Most frequent users</h3>
<div class="d-flex flex-row flex-wrap">
{% for user in top_manual_users %}
<div class="item"
onclick="window.location.href = '../coffee.html?tag={{ user.tag.hex() }}&manually'">
onclick="window.location.href = '../coffee.html?tag={{ user.tag.hex() }}&manually&can-oneswipe'">
{{- user.name }} {{ user.prename -}}
</div>
{% endfor %}
Expand All @@ -58,7 +58,7 @@ <h3 class="mt-5">All users</h3>
<div class="d-flex flex-row flex-wrap">
{% for user in userlist %}
<div class="item"
onclick="window.location.href = '../coffee.html?tag={{ user.tag.hex() }}&manually'">
onclick="window.location.href = '../coffee.html?tag={{ user.tag.hex() }}&manually&can-oneswipe'">
{{- user.name }} {{ user.prename -}}
</div>
{% endfor %}
Expand Down
2 changes: 1 addition & 1 deletion coffeebuddy/ui/base/templates/welcome.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
$(() => {
var socket = io.connect(window.location.host);
socket.on('card_connected', (msg) => {
window.location.href = `../coffee.html?tag=${msg['tag']}`;
window.location.href = `../coffee.html?tag=${msg['tag']}&can-oneswipe`;
});
});

Expand Down
35 changes: 29 additions & 6 deletions coffeebuddy/ui/coffee/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,22 @@ def post():
if request.method == "POST":
return post()

has_coffeemaker = flask.current_app.config.get("COFFEEMAKER", None) is not None

if (
not has_coffeemaker
and "can-oneswipe" in flask.request.args
and user.option_oneswipe
):
return flask.redirect(url("oneswipe.html", **flask.request.args))

variants_favorites, variants = CoffeeVariant.all_for_user(user)
return flask.render_template(
"coffee.html",
user=user,
variants_favorites=variants_favorites,
variants=variants,
coffeemaker=flask.current_app.config.get("COFFEEMAKER", False)
or flask.current_app.config.get("COFFEEMAKER_MOCK_BREW_TIME", False)
is not False,
coffeemaker=has_coffeemaker,
price=flask.current_app.config["PRICE"],
)

Expand Down Expand Up @@ -160,12 +167,28 @@ def post():
)


@blueprint.route("/oneswipe.html", methods=["POST"])
@blueprint.route("/oneswipe.html", methods=["GET", "POST"])
@require_tag
def oneswipe(user: User):
db = flask.current_app.db

selected_manually = "manually" in flask.request.args

if "coffee" in flask.request.form:
db.session.add(Drink(user=user, price=flask.current_app.config["PRICE"]))
db.session.add(
Drink(
user=user,
price=flask.current_app.config["PRICE"],
selected_manually=selected_manually,
)
)
db.session.commit()
return ""
elif "undo" in flask.request.form:
return flask.redirect(
url(
"coffee.html",
tag=user.tag,
**{"manually" if selected_manually else None: None},
)
)
return flask.render_template("oneswipe.html", user=user)
Loading

0 comments on commit ed0fbd4

Please sign in to comment.