Explorar el Código

Refactored for new name

DeadTOm hace 1 semana
padre
commit
0d64719069

+ 0 - 1
.gitignore

@@ -1,5 +1,4 @@
 # ---> Python
-checklist.json
 *.kdev4
 __pycache__/
 env/

+ 3 - 3
README.md

@@ -1,5 +1,5 @@
 # ToDoList
-A web based app to add and check items off a list, which outputs a page that can be set up as a browser source in OBS.
+A web based app to add and cross items off a list, which outputs a page that can be set up as a browser source in OBS.
 
 #### Setup
 Create your venv, and activate it:
@@ -38,10 +38,10 @@ Create a browser source, and point it to:
 http://localhost:5022/list
 ```
 
-Be sure to check the box for "Refresh browser when scene becomes active"
+Be sure to cross the box for "Refresh browser when scene becomes active"
 I've included "ListBackground.png" for use as an opaque background for your list in your streaming software, but of course use whatever you like.
 
-#### Manage your check list
+#### Manage your cross list
 <a href=https://git.deadtom.me/deadtom/ToDoList/src/master/screenshots/managelist.png><img src=https://git.deadtom.me/deadtom/ToDoList/raw/master/screenshots/managelist.png width=100></a>
 
 To add items to your list, or cross items off, go to:

+ 0 - 63
checklist/checklist.py

@@ -1,63 +0,0 @@
-from flask import Flask, render_template, Blueprint, request, redirect, url_for, current_app
-from datetime import timezone
-import json
-import os
-
-clbp = Blueprint('checklist', __name__)
-
-
-def save_checklist(list_items):  # Save checklist items
-    new_list = json.dumps(list_items, indent=4)
-    list_file = os.path.join(current_app.instance_path, 'list.py')
-    try:
-        with open(list_file, 'w') as f:
-            f.write(f'LIST = {new_list}')
-        f.close
-        current_app.config.from_pyfile('list.py', silent=True)  # Reread the list into the app
-    except Exception as sclerror:
-        current_app.logger.error(f'Couldn\'t save list.py: {sclerror.args[0]}')
-
-
-@clbp.route('/', methods=['GET', 'POST'])
-def index():
-    checklist_items = current_app.config['LIST']
-    if request.method == 'POST':
-        checklist_items = current_app.config['LIST']
-        item = request.form.get('item')
-        if item:
-            checklist_items.append({'name': item, 'checked': 'no'})
-            save_checklist(checklist_items)  # Save to file after adding
-        return redirect(url_for('checklist.index'))
-    return render_template('index.html', items=checklist_items)
-
-
-@clbp.route('/check/<int:item_id>')
-def check(item_id):
-    checklist_items = current_app.config['LIST']
-    if 0 <= item_id < len(checklist_items):
-        checklist_items[item_id]['checked'] = 'yes'
-        save_checklist(checklist_items)  # Save to file after checking
-    return redirect(url_for('checklist.index'))
-
-
-@clbp.route('/uncheck/<int:item_id>')
-def uncheck(item_id):
-    checklist_items = current_app.config['LIST']
-    if 0 <= item_id < len(checklist_items):
-        checklist_items[item_id]['checked'] = 'no'
-        save_checklist(checklist_items)  # Save to file after checking
-    return redirect(url_for('checklist.index'))
-
-
-@clbp.route('/clear')
-def clear():
-    checklist_items = current_app.config['LIST']
-    checklist_items = []  # Clear the list
-    save_checklist(checklist_items)  # Save the empty list
-    return redirect(url_for('checklist.index'))
-
-
-@clbp.route('/list')
-def list():
-    checklist_items = current_app.config['LIST']
-    return render_template('list.html', items=checklist_items)

+ 1 - 1
pyproject.toml

@@ -3,6 +3,6 @@ requires = ["setuptools>=42", "wheel"]
 build-backend = "setuptools.build_meta"
 
 [project]
-name = "checklist"
+name = "todolist"
 version = "0.1"
 dependencies = ["flask", "gunicorn"]

BIN
screenshots/managelist.png


+ 1 - 1
setup.py

@@ -1,7 +1,7 @@
 from setuptools import find_packages, setup
 
 setup(
-    name='checklist',
+    name='todolist',
     version='0.1',
     packages=find_packages(),
     include_package_data=True,

+ 3 - 3
checklist/__init__.py → todolist/__init__.py

@@ -11,15 +11,15 @@ def create_app(test_config=None):
     except OSError:
         pass
     
-    app.config.from_object('checklist.default_list')  # Read default list
+    app.config.from_object('todolist.default_list')  # Read default list
     app.config.from_pyfile('list.py', silent=True)
 
     gunicorn_logger = logging.getLogger('gunicorn.error')  # Gunicorn logging integration
     app.logger.handlers = gunicorn_logger.handlers
     app.logger.setLevel(gunicorn_logger.level)
 
-    from . import checklist  # Set up blueprints
-    app.register_blueprint(checklist.clbp)
+    from . import todolist  # Set up blueprints
+    app.register_blueprint(todolist.clbp)
 
     return app
 

+ 3 - 3
checklist/default_list.py → todolist/default_list.py

@@ -1,13 +1,13 @@
 LIST = [{
     "name": "Do a thing",
-    "checked": 'yes'
+    "crossed": 'yes'
     },
     {
     "name": "Do another thing",
-    "checked": 'no'
+    "crossed": 'no'
     },
     {
     "name": "And that other thing too",
-    "checked": 'no'
+    "crossed": 'no'
     }
 ]

+ 7 - 7
checklist/templates/index.html → todolist/templates/index.html

@@ -3,7 +3,7 @@
 <head>
     <meta charset="UTF-8">
     <meta name="viewport" content="width=device-width, initial-scale=1.0">
-    <title>Checklist</title>
+    <title>To-do List</title>
     <style>
         body {
             background-color: #1F2933;
@@ -41,7 +41,7 @@
     </script>
 </head>
 <body onload="focusInput()">
-    <h1>Checklist</h1>
+    <h1>To-do List</h1>
     <form method="POST" onsubmit="focusInput()">
         <input type="text" id="itemInput" name="item" placeholder="Add a new item" required>
         <button type="submit" class="button">Add</button>
@@ -49,24 +49,24 @@
     <ul>
         {% if items %}
             {% for item in items %}
-                {% if item.checked == 'no' %}
+                {% if item.crossed == 'no' %}
                     <li style="text-decoration:none;">
                         {{ item.name }}
-                        <a href="{{ url_for('checklist.check', item_id=loop.index0) }}">[Cross Off]</a>
+                        <a href="{{ url_for('todolist.cross', item_id=loop.index0) }}">[Cross Off]</a>
                     </li>
                 {% else %}
                     <li> <span style="text-decoration:line-through;">
                         {{ item.name }}</span>
-                        <a href="{{ url_for('checklist.uncheck', item_id=loop.index0) }}">[Un-Cross]</a>
+                        <a href="{{ url_for('todolist.uncross', item_id=loop.index0) }}">[Un-Cross]</a>
                     </li>
                 {% endif %}
             {% endfor %}
         {% endif %}
     </ul>
-    <form action="{{ url_for('checklist.list') }}" method="get" style="display: inline;">
+    <form action="{{ url_for('todolist.list') }}" method="get" style="display: inline;">
         <button type="submit" class="button">View List</button>
     </form>
-    <form action="{{ url_for('checklist.clear') }}" method="get" style="display: inline;">
+    <form action="{{ url_for('todolist.clear') }}" method="get" style="display: inline;">
         <button type="submit" class="button">Clear List</button>
     </form>
     <br><br>

+ 1 - 1
checklist/templates/list.html → todolist/templates/list.html

@@ -17,7 +17,7 @@
         <h2>Today's to-do List</h2>
         <ul>
             {% for item in items %}
-                <li style="text-decoration: {{ 'line-through' if item.checked == 'yes' else 'none' }}; font-weight: bold; font-size: 18px;">
+                <li style="text-decoration: {{ 'line-through' if item.crossed == 'yes' else 'none' }}; font-weight: bold; font-size: 18px;">
                     {{ item.name }}
                 </li>
             {% endfor %}

+ 63 - 0
todolist/todolist.py

@@ -0,0 +1,63 @@
+from flask import Flask, render_template, Blueprint, request, redirect, url_for, current_app
+from datetime import timezone
+import json
+import os
+
+clbp = Blueprint('todolist', __name__)
+
+
+def save_todolist(list_items):  # Save todolist items
+    new_list = json.dumps(list_items, indent=4)
+    list_file = os.path.join(current_app.instance_path, 'list.py')
+    try:
+        with open(list_file, 'w') as f:
+            f.write(f'LIST = {new_list}')
+        f.close
+        current_app.config.from_pyfile('list.py', silent=True)  # Reread the list into the app
+    except Exception as sclerror:
+        current_app.logger.error(f'Couldn\'t save list.py: {sclerror.args[0]}')
+
+
+@clbp.route('/', methods=['GET', 'POST'])
+def index():
+    todolist_items = current_app.config['LIST']
+    if request.method == 'POST':
+        todolist_items = current_app.config['LIST']
+        item = request.form.get('item')
+        if item:
+            todolist_items.append({'name': item, 'crossed': 'no'})
+            save_todolist(todolist_items)  # Save to file after adding
+        return redirect(url_for('todolist.index'))
+    return render_template('index.html', items=todolist_items)
+
+
+@clbp.route('/cross/<int:item_id>')
+def cross(item_id):
+    todolist_items = current_app.config['LIST']
+    if 0 <= item_id < len(todolist_items):
+        todolist_items[item_id]['crossed'] = 'yes'
+        save_todolist(todolist_items)  # Save to file after crossing
+    return redirect(url_for('todolist.index'))
+
+
+@clbp.route('/uncross/<int:item_id>')
+def uncross(item_id):
+    todolist_items = current_app.config['LIST']
+    if 0 <= item_id < len(todolist_items):
+        todolist_items[item_id]['crossed'] = 'no'
+        save_todolist(todolist_items)  # Save to file after crossing
+    return redirect(url_for('todolist.index'))
+
+
+@clbp.route('/clear')
+def clear():
+    todolist_items = current_app.config['LIST']
+    todolist_items = []  # Clear the list
+    save_todolist(todolist_items)  # Save the empty list
+    return redirect(url_for('todolist.index'))
+
+
+@clbp.route('/list')
+def list():
+    todolist_items = current_app.config['LIST']
+    return render_template('list.html', items=todolist_items)