From ab19504738392a3e4efe25523245533dbd6573d2 Mon Sep 17 00:00:00 2001 From: retoor Date: Sat, 14 Dec 2024 21:45:36 +0100 Subject: [PATCH] First working version. --- Makefile | 1 + setup.cfg | 6 ++++-- src/form/__main__.py | 13 ++++++------- src/form/app.py | 27 ++++++++++++++------------- src/form/tests.py | 6 +----- 5 files changed, 26 insertions(+), 27 deletions(-) diff --git a/Makefile b/Makefile index 0b724bb..9ba797d 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ PYTHON=./.venv/bin/python PIP=./.venv/bin/pip BIN=./.venv/bin +ENV=./.venv/bin/activate APP=form all: ensure_env format install build test diff --git a/setup.cfg b/setup.cfg index 0ac5f31..905e5d8 100644 --- a/setup.cfg +++ b/setup.cfg @@ -15,10 +15,12 @@ package_dir = python_requires = >=3.7 install_requires = requests - app @ retoor.molodetz.nl/retoor/app + app @ git+https://retoor.molodetz.nl/retoor/app + captcha + [options.packages.find] where = src [options.entry_points] console_scripts = - form = form.__main__:main + form.serve = form.__main__:main diff --git a/src/form/__main__.py b/src/form/__main__.py index 03bd23c..6791a6c 100644 --- a/src/form/__main__.py +++ b/src/form/__main__.py @@ -1,14 +1,13 @@ -from form.app import Application from app.app import argument_parser +from form.app import Application def main(): args = argument_parser.parse_args() - app = Application(db_file="sqlite:///form.db",web_db=args.web_db)) - app.run(host=args.host,port=args.port) - -if __name__ == '__main__': + app = Application(db_path="sqlite:///form.db", db_web=args.db_web) + app.run(host=args.host, port=args.port) + + +if __name__ == "__main__": main() - - diff --git a/src/form/app.py b/src/form/app.py index 2a36e10..1d60c31 100644 --- a/src/form/app.py +++ b/src/form/app.py @@ -1,26 +1,27 @@ from app.app import Application as BaseApplication -import uuid -import asyncio +from aiohttp import web class Application(BaseApplication): def __init__(self, *args, **kwargs): - - self.forms_created - self.forms_validate_success = 0 - self.forms_validate_failure = 0 - self.forms_validate_pending = 0 - super().__init__(*args, **kwargs): + super().__init__(*args, **kwargs) self.router.add_get("/", self.index_handler) + @property + def forms_created(self): + return int(self.sget("forms_created", 0)) - async def index_handler(self): - return web.json_response(dict( - message="Nothing to see here", - error="404" - ),status_code=404) + @forms_created.setter + def forms_created(self, value): + self.sset("forms_created", int(value)) + async def index_handler(self,request): + self.forms_created += 1 + print(self.forms_created) + return web.json_response( + {"message": "Nothing to see here", "error": "404"}, status=404 + ) diff --git a/src/form/tests.py b/src/form/tests.py index cbf81ef..47cb7c9 100644 --- a/src/form/tests.py +++ b/src/form/tests.py @@ -1,4 +1,3 @@ -import asyncio import unittest @@ -11,8 +10,5 @@ class AppTestCase(unittest.IsolatedAsyncioTestCase): self.assertTrue(True) - - -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() -