diff --git a/.library/lib/site-packages/export-0.2.0.dist-info/INSTALLER b/.library/lib/site-packages/export-0.2.0.dist-info/INSTALLER new file mode 100644 index 0000000..a1b589e --- /dev/null +++ b/.library/lib/site-packages/export-0.2.0.dist-info/INSTALLER @@ -0,0 +1 @@ +pip diff --git a/.library/lib/site-packages/export-0.2.0.dist-info/LICENSE b/.library/lib/site-packages/export-0.2.0.dist-info/LICENSE new file mode 100644 index 0000000..457bf0d --- /dev/null +++ b/.library/lib/site-packages/export-0.2.0.dist-info/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 Tom Bulled + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/.library/lib/site-packages/export-0.2.0.dist-info/METADATA b/.library/lib/site-packages/export-0.2.0.dist-info/METADATA new file mode 100644 index 0000000..9bdbb3d --- /dev/null +++ b/.library/lib/site-packages/export-0.2.0.dist-info/METADATA @@ -0,0 +1,83 @@ +Metadata-Version: 2.1 +Name: export +Version: 0.2.0 +Summary: Control module exports +Home-page: https://github.com/tombulled/export +License: MIT +Keywords: python,export,public,private +Author: Tom Bulled +Author-email: 26026015+tombulled@users.noreply.github.com +Requires-Python: >=3.8,<4.0 +Classifier: License :: OSI Approved :: MIT License +Classifier: Programming Language :: Python :: 3 +Classifier: Programming Language :: Python :: 3.10 +Classifier: Programming Language :: Python :: 3.8 +Classifier: Programming Language :: Python :: 3.9 +Project-URL: Documentation, https://github.com/tombulled/export +Project-URL: Repository, https://github.com/tombulled/export +Description-Content-Type: text/markdown + +# export +Control module exports + +## About +This library dynamically generates an `__all__` attribute for modules + +## Usage + +### Private by Default +*Does* export objects marked **public**, *doesn't* export everything else + +```python +# lib.py + +import export + +export.init(default=export.PRIVATE) + +@export.public +def foo(): + pass + +def bar(): + pass + +def baz(): + pass +``` + +```python +>>> import lib +>>> +>>> lib.__all__ +['foo'] +``` + +### Public by Default +*Doesn't* export objects marked **private**, *does* export everything else + +```python +# lib.py + +import export + +export.init(default=export.PUBLIC) + +def foo(): + pass + +@export.private +def bar(): + pass + +@export.private +def baz(): + pass +``` + +```python +>>> import lib +>>> +>>> lib.__all__ +['export', 'foo'] +``` diff --git a/.library/lib/site-packages/export-0.2.0.dist-info/RECORD b/.library/lib/site-packages/export-0.2.0.dist-info/RECORD new file mode 100644 index 0000000..9d212c8 --- /dev/null +++ b/.library/lib/site-packages/export-0.2.0.dist-info/RECORD @@ -0,0 +1,14 @@ +export-0.2.0.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4 +export-0.2.0.dist-info/LICENSE,sha256=GnW03-0adM_f-nbemR0-poxBk-zJQWQB3t8yAMMFMhY,1067 +export-0.2.0.dist-info/METADATA,sha256=DtgARxtzqpdsOa2n2X7MCqeAm5oWFqFY44UuL0UR50U,1472 +export-0.2.0.dist-info/RECORD,, +export-0.2.0.dist-info/REQUESTED,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0 +export-0.2.0.dist-info/WHEEL,sha256=y3eDiaFVSNTPbgzfNn0nYn5tEn1cX6WrdetDlQM4xWw,83 +export/__init__.py,sha256=Q_CTsi3EXrwEvUx1vaRfOdyCClh212K0UH3CF8MJsxw,148 +export/__pycache__/__init__.cpython-310.pyc,, +export/__pycache__/api.cpython-310.pyc,, +export/__pycache__/enums.cpython-310.pyc,, +export/__pycache__/models.cpython-310.pyc,, +export/api.py,sha256=11G7-4dXNQMlUcyG91Ct3MVKeB3Q9JIhZYLNDR3yOyg,1208 +export/enums.py,sha256=P2ywq5fVliFyv4XdW-LGi8GDrYoGSQG3baaA0hUhnVY,176 +export/models.py,sha256=q292OojIkSLSBKjo-5WUQWbnAONe_X5nk7vbenuknDA,280 diff --git a/.library/lib/site-packages/export-0.2.0.dist-info/REQUESTED b/.library/lib/site-packages/export-0.2.0.dist-info/REQUESTED new file mode 100644 index 0000000..e69de29 diff --git a/.library/lib/site-packages/export-0.2.0.dist-info/WHEEL b/.library/lib/site-packages/export-0.2.0.dist-info/WHEEL new file mode 100644 index 0000000..3764652 --- /dev/null +++ b/.library/lib/site-packages/export-0.2.0.dist-info/WHEEL @@ -0,0 +1,4 @@ +Wheel-Version: 1.0 +Generator: poetry 1.0.7 +Root-Is-Purelib: true +Tag: py3-none-any diff --git a/.library/lib/site-packages/export/__init__.py b/.library/lib/site-packages/export/__init__.py new file mode 100644 index 0000000..a238f4b --- /dev/null +++ b/.library/lib/site-packages/export/__init__.py @@ -0,0 +1,5 @@ +from .api import init, public, private +from . import enums + +PUBLIC: enums.Access = enums.Access.PUBLIC +PRIVATE: enums.Access = enums.Access.PRIVATE diff --git a/.library/lib/site-packages/export/__pycache__/__init__.cpython-310.pyc b/.library/lib/site-packages/export/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000..1c624b5 Binary files /dev/null and b/.library/lib/site-packages/export/__pycache__/__init__.cpython-310.pyc differ diff --git a/.library/lib/site-packages/export/__pycache__/api.cpython-310.pyc b/.library/lib/site-packages/export/__pycache__/api.cpython-310.pyc new file mode 100644 index 0000000..6461bfd Binary files /dev/null and b/.library/lib/site-packages/export/__pycache__/api.cpython-310.pyc differ diff --git a/.library/lib/site-packages/export/__pycache__/enums.cpython-310.pyc b/.library/lib/site-packages/export/__pycache__/enums.cpython-310.pyc new file mode 100644 index 0000000..ea3690b Binary files /dev/null and b/.library/lib/site-packages/export/__pycache__/enums.cpython-310.pyc differ diff --git a/.library/lib/site-packages/export/__pycache__/models.cpython-310.pyc b/.library/lib/site-packages/export/__pycache__/models.cpython-310.pyc new file mode 100644 index 0000000..2111231 Binary files /dev/null and b/.library/lib/site-packages/export/__pycache__/models.cpython-310.pyc differ diff --git a/.library/lib/site-packages/export/api.py b/.library/lib/site-packages/export/api.py new file mode 100644 index 0000000..1961bd3 --- /dev/null +++ b/.library/lib/site-packages/export/api.py @@ -0,0 +1,46 @@ +import inspect +import sys +import types +import typing + +from . import enums, models + + +def init(*, default: enums.Access = enums.Access.PRIVATE) -> None: + module: types.ModuleType = inspect.getmodule(inspect.stack()[1][0]) + + class Module(types.ModuleType): + _scope: models.Scope = models.Scope(default=default) + + @property + def __all__(self) -> typing.List[str]: + attributes: typing.Set[str] = { + key for key in dir(self) if not key.startswith("_") + } + + if self._scope.default == enums.Access.PUBLIC: + return sorted(attributes - self._scope.private) + + return sorted(self._scope.public) + + module.__class__ = Module + + +def public(obj: typing.T) -> typing.T: + return _export(obj, access=enums.Access.PUBLIC) + + +def private(obj: typing.T) -> typing.T: + return _export(obj, access=enums.Access.PRIVATE) + + +def _export(obj: typing.T, access: enums.Access) -> typing.T: + module: types.ModuleType = sys.modules[obj.__module__] + + collection: typing.Set[str] = ( + module._scope.public if access is enums.Access.PUBLIC else module._scope.private + ) + + collection.add(obj.__name__) + + return obj diff --git a/.library/lib/site-packages/export/enums.py b/.library/lib/site-packages/export/enums.py new file mode 100644 index 0000000..1d76ada --- /dev/null +++ b/.library/lib/site-packages/export/enums.py @@ -0,0 +1,9 @@ +import enum + + +class Access(enum.Enum): + PUBLIC = enum.auto() + PRIVATE = enum.auto() + + def __repr__(self) -> str: + return f"<{type(self).__name__}.{self.name}>" diff --git a/.library/lib/site-packages/export/models.py b/.library/lib/site-packages/export/models.py new file mode 100644 index 0000000..74b6501 --- /dev/null +++ b/.library/lib/site-packages/export/models.py @@ -0,0 +1,11 @@ +import dataclasses +import typing + +from . import enums + + +@dataclasses.dataclass +class Scope: + default: enums.Access = enums.Access.PRIVATE + public: typing.Set[str] = dataclasses.field(default_factory=set) + private: typing.Set[str] = dataclasses.field(default_factory=set) diff --git a/__pycache__/app.cpython-310.pyc b/__pycache__/app.cpython-310.pyc new file mode 100644 index 0000000..4fed411 Binary files /dev/null and b/__pycache__/app.cpython-310.pyc differ diff --git a/library.py b/app.py similarity index 65% rename from library.py rename to app.py index 71fee29..11cd6e1 100644 --- a/library.py +++ b/app.py @@ -1,6 +1,7 @@ # THE LIBRARY # -from itertools import groupby # to handle complex iterations + +from itertools import groupby # to handle complex iterations import os import sqlite3 @@ -16,7 +17,6 @@ def get_db_connection(): # Added row_factory attribute to the sqlite connection, in this way you can have name-based access to columns; this means that the database connection will return rows that behave like regular Python dictionaries. - # ----- FLASK ----- # class PrefixMiddleware(object): @@ -41,19 +41,23 @@ app = Flask(__name__) app.wsgi_app = PrefixMiddleware(app.wsgi_app, prefix='/soupboat/library') -@app.route("/", methods=['GET', 'POST']) +@app.route("/") def home(): conn = get_db_connection() todos = conn.execute('SELECT c.content, cat.title FROM cards c JOIN categories cat \ - ON c.category_id = cat.id ORDER BY c.created').fetchall() - + ON c.category_id = cat.id ORDER BY cat.title').fetchall() + categories = {} # for each category and group of cards for each cat in groupby() grouper object for k, g in groupby(todos, key=lambda t: t['title']): categories[k] = list(g) - - + print(categories[k]) + for cat, cards in categories.items(): # ♥ .items is a build in attribute of the dictionary(?) + print(cat) + for card in cards: + print(' ', card['content']) + # if request.method == 'POST': # title = request.form.get('title') # author = request.form.get('author') @@ -64,26 +68,25 @@ def home(): return render_template('home.html', categories=categories) +# @app.route("/add", methods=['GET', 'POST']) +# def create(): +# # the goal here is to choose from a list of parameters what you want to add +# # 1- ogni blocco del form dovrebbe essere una tabella a parte +# if request.method == 'POST': +# title = request.form.get('title') +# author = request.form.get('author') +# description = request.form.get('description') +# add_book(author, title, description) +# # if author: +# # return url_for('add_new_author') +# return redirect(url_for('home')) +# return render_template('add_new.html') -@app.route("/add", methods=['GET', 'POST']) -def create(): - # the goal here is to choose from a list of parameters what you want to add - # 1- ogni blocco del form dovrebbe essere una tabella a parte - if request.method == 'POST': - title = request.form.get('title') - author = request.form.get('author') - description = request.form.get('description') - add_book(author, title, description) -# if author: -# return url_for('add_new_author') - - return redirect(url_for('home')) - return render_template('add_new.html') -app.run(port=3148) +# app.run(port=3148) # TODO: # - list the cards -# - put its category inside \ No newline at end of file +# - put its category inside diff --git a/init_db.py b/init_db.py index 035c09d..137a5a6 100644 --- a/init_db.py +++ b/init_db.py @@ -8,8 +8,16 @@ with open('schema.sql') as f: cur = connection.cursor() +cur.execute("INSERT INTO categories (title) VALUES (?)", ('Reading',)) +cur.execute("INSERT INTO categories (title) VALUES (?)", ('Note',)) +cur.execute("INSERT INTO categories (title) VALUES (?)", ('Question',)) + +cur.execute("INSERT INTO cards (category_id, content) VALUES (?,?)", + (1, 'Oltre Eboli')) +cur.execute("INSERT INTO cards (category_id, content) VALUES (?,?)", + (1, 'This is not an Atlas')) # close conenction connection.commit() -connection.close() \ No newline at end of file +connection.close() diff --git a/library.db b/library.db index 0b48572..9f911a2 100644 Binary files a/library.db and b/library.db differ diff --git a/templates/base.html b/templates/base.html index 3d8c5b8..86bb645 100644 --- a/templates/base.html +++ b/templates/base.html @@ -2,12 +2,12 @@ - library - - + {% block title %} {% endblock %} + + - + {% block content %} {% endblock %} diff --git a/templates/home.html b/templates/home.html index 0deac9a..a25baa7 100644 --- a/templates/home.html +++ b/templates/home.html @@ -2,20 +2,20 @@ {% block content %}

{% block title %} Welcome to FlaskTodo {% endblock %}

- {% for category, cards in categories.cards() %} + {% for category, cards in categories.items() %}

{{ category }}

{% endfor %} {% endblock %} - + #}-->