فهرست منبع

Reorganized structure

allens 1 هفته پیش
والد
کامیت
b94308c665
10فایلهای تغییر یافته به همراه112 افزوده شده و 79 حذف شده
  1. 1 1
      .gitignore
  2. 5 5
      License
  3. 0 62
      app.py
  4. 28 0
      checklist/__init__.py
  5. 52 0
      checklist/checklist.py
  6. 13 0
      checklist/default_list.py
  7. 1 2
      checklist/templates/index.html
  8. 0 0
      checklist/templates/list.html
  9. 12 0
      setup.py
  10. 0 9
      wsgi.py

+ 1 - 1
.gitignore

@@ -2,6 +2,6 @@
 checklist.json
 *.kdev4
 __pycache__/
-.venv/
+env/
 .kdev4/
 *.egg-info/

+ 5 - 5
License

@@ -1,8 +1,8 @@
-MIT License
-Copyright (c) 2025 DeadTOm
+Checklist © 2025 by DeadTOm is licensed under Creative Commons Attribution-ShareAlike 4.0 International
 
-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:
+This license requires that reusers give credit to the creator. It allows reusers to distribute, remix, adapt, and build upon the material in any medium or format, even for commercial purposes. If others remix, adapt, or build upon the material, they must license the modified material under identical terms.
 
-The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+BY: Credit must be given to you, the creator.
+SA: Adaptations must be shared under the same terms.
 
-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.
+See the License Deed -> https://creativecommons.org/licenses/by-sa/4.0/

+ 0 - 62
app.py

@@ -1,62 +0,0 @@
-from flask import Flask, render_template, request, redirect, url_for
-import json
-import os
-
-app = Flask(__name__)
-
-# File to store checklist items
-CHECKLIST_FILE = 'checklist.json'
-
-
-# Load checklist items
-def load_checklist():
-    if os.path.exists(CHECKLIST_FILE):
-        with open(CHECKLIST_FILE, 'r') as file:
-            return json.load(file)
-    return []
-
-
-# Save checklist items
-def save_checklist(items):
-    with open(CHECKLIST_FILE, 'w') as file:
-        json.dump(items, file)
-
-
-# List of checklist items
-checklist_items = load_checklist()
-
-
-@app.route('/', methods=['GET', 'POST'])
-def index():
-    if request.method == 'POST':
-        item = request.form.get('item')
-        if item:
-            checklist_items.append({'name': item, 'checked': False})
-            save_checklist(checklist_items)  # Save to file after adding
-        return redirect(url_for('index'))
-    return render_template('index.html', items=checklist_items)
-
-
-@app.route('/check/<int:item_id>')
-def check(item_id):
-    if 0 <= item_id < len(checklist_items):
-        checklist_items[item_id]['checked'] = not checklist_items[item_id]['checked']
-        save_checklist(checklist_items)  # Save to file after checking
-    return redirect(url_for('index'))
-
-
-@app.route('/clear')
-def clear():
-    global checklist_items
-    checklist_items = []  # Clear the list
-    save_checklist(checklist_items)  # Save the empty list
-    return redirect(url_for('index'))
-
-
-@app.route('/list')
-def list():
-    return render_template('list.html', items=checklist_items)
-
-
-if __name__ == '__main__':
-    app.run(debug=True)

+ 28 - 0
checklist/__init__.py

@@ -0,0 +1,28 @@
+import os
+import logging
+from flask import Flask
+
+
+def create_app(test_config=None):
+    app = Flask(__name__, instance_relative_config=True)
+
+    try:
+        os.makedirs(app.instance_path)
+    except OSError:
+        pass
+    
+    app.config.from_object('checklist.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)
+
+    return app
+
+
+if __name__ == '__main__':
+    create_app()

+ 52 - 0
checklist/checklist.py

@@ -0,0 +1,52 @@
+from flask import Flask, render_template, Blueprint, request, redirect, url_for
+from datetime import timezone
+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.list['LIST']
+    if request.method == 'POST':
+        item = request.form.get('item')
+        if item:
+            checklist_items.append({'name': item, 'checked': False})
+            save_checklist(checklist_items)  # Save to file after adding
+        return redirect(url_for('index'))
+    return render_template('index.html', items=checklist_items)
+
+
+@clbp.route('/check/<int:item_id>')
+def check(item_id):
+    checklist_items = current_app.list['LIST']
+    if 0 <= item_id < len(checklist_items):
+        checklist_items[item_id]['checked'] = not checklist_items[item_id]['checked']
+        save_checklist(checklist_items)  # Save to file after checking
+    return redirect(url_for('index'))
+
+
+@clbp.route('/clear')
+def clear():
+    checklist_items = current_app.list['LIST']
+    checklist_items = []  # Clear the list
+    save_checklist(checklist_items)  # Save the empty list
+    return redirect(url_for('index'))
+
+
+@clbp.route('/list')
+def list():
+    checklist_items = current_app.list['LIST']
+    return render_template('list.html', items=checklist_items)

+ 13 - 0
checklist/default_list.py

@@ -0,0 +1,13 @@
+LIST = [{
+    "name": "Do a thing",
+    "checked": true
+    },
+    {
+    "name": "Do another thing",
+    "checked": false
+    },
+    {
+    "name": "And that other thing too",
+    "checked": false
+    }
+]

+ 1 - 2
templates/index.html → checklist/templates/index.html

@@ -35,8 +35,7 @@
         }
     </style>
     <script>
-        // Function to focus on the input field
-        function focusInput() {
+        function focusInput() {  // Function to focus on the input field
             document.getElementById('itemInput').focus();
         }
     </script>

+ 0 - 0
templates/list.html → checklist/templates/list.html


+ 12 - 0
setup.py

@@ -0,0 +1,12 @@
+from setuptools import find_packages, setup
+
+setup(
+    name='checklist',
+    version='0.1',
+    packages=find_packages(),
+    include_package_data=True,
+    install_requires=[
+        'flask',
+        'gunicorn'
+    ],
+)

+ 0 - 9
wsgi.py

@@ -1,9 +0,0 @@
-import sys
-import os
-import logging
-
-current_dir = os.path.dirname(os.path.abspath(__file__))
-pathtoapp = os.path.join(current_dir, 'Checklist')  # Adjust this if your app is in a different folder
-sys.path.insert(0, pathtoapp)
-
-from app import app as application