diff --git a/README.md b/README.md index d5db10d..457e1dc 100644 --- a/README.md +++ b/README.md @@ -2,13 +2,19 @@ flask app for plurals to publicly share member lists -# dev set up +# dev set up (windows) - after cloning, run `py -3 -m venv .venv` in the root directory and then `.venv\Scripts\activate` - then `pip install Flask` inside the virtual env - you might also need to init a database, so use `flask --app myriad init-db` - to start the site use `flask --app myriad run --debug` +do not deploy this way, the packaged flask server is not secure. production instructions will be provided when the project is ready + +- you will need to run `.venv\Scripts\activate` from the folder every time you start working on it +- re-building the entire database with `flask --app myriad init-db` (losing all the data inside) will be necessary as development continues. DO NOT STORE ANYTHING IMPORTANT DURING DEVELOPMENT +- start the site with `flask --app myriad run --debug` as usual + # prod set up - not ready yet @@ -18,11 +24,17 @@ flask app for plurals to publicly share member lists - create `config.py` in the instance folder and customise the following settings to your needs ``` -REGISTRATION: False # only set to True if in a development situation, or to create your first user -UPLOAD_FOLDER = 'myriad/static/icons' +REGISTRATION = True ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'gif'} +ICON_UPLOAD_FOLDER = 'myriad/static/icons' +BLINKIES_UPLOAD_FOLDER = 'myriad/static/blinkies' +STAMPS_UPLOAD_FOLDER = 'myriad/static/stamps' ``` +- registration should only be set to True in a development situation (in production set it to False one you have set up your administration account). this would mean that anyone can make an account and edit your system +- feel free to adjust allowed file extensions however you choose +- upload folders don't need to be changed + # usage - the software here is free to use, and there's no requirement to link back diff --git a/myriad/home.py b/myriad/home.py index 7cc4382..6471064 100644 --- a/myriad/home.py +++ b/myriad/home.py @@ -10,13 +10,10 @@ bp = Blueprint('home', __name__) @bp.route('/') def index(): - # db = get_db() - # posts = db.execute( - # 'SELECT p.id, title, body, created, author_id, username' - # ' FROM post p JOIN user u ON p.author_id = u.id' - # ' ORDER BY created DESC' - # ).fetchall() - return render_template('index.html') + db = get_db() + fronters = db.execute("SELECT * FROM member WHERE front=(?)",(1,)).fetchall() + + return render_template('index.html', front_list=fronters) @bp.route('/full') def full_list(): @@ -28,7 +25,10 @@ def full_list(): icon_id = member[6] if icon_id: icon = db.execute("SELECT icon_location FROM icons WHERE id=(?)",(icon_id,)).fetchone() - icons[member[0]] = icon[0] + if icon: + icons[member[0]] = icon[0] + else: + icons[member[0]] = None print(icons) return render_template('full.html', memberlist=members, icons=icons) \ No newline at end of file diff --git a/myriad/manage.py b/myriad/manage.py index d4d79d6..b76ab0c 100644 --- a/myriad/manage.py +++ b/myriad/manage.py @@ -15,7 +15,6 @@ def new(): if request.method == 'POST': name = request.form['name'] bio = request.form['bio'] - #icon = request.form['icon'] user_id = g.user[0] db = get_db() error = None @@ -52,12 +51,41 @@ def edit(mid): db.commit() if "file" in request.files: + # here we are just saving the uploaded file to the icons folder. + # we're not going hard on security because we expect there to only be 1 admin + # but the filename will always be changed to a random string of numbers and letters known as uuid file = request.files["file"] filename = str(uuid.uuid4()) + "." + file.filename.split(".")[1] - file.save(os.path.join(current_app.config["UPLOAD_FOLDER"], filename)) + file.save(os.path.join(current_app.config["ICON_UPLOAD_FOLDER"], filename)) db.execute("INSERT INTO icons (member_id, icon_location) VALUES (?, ?)", (mid, filename),) db.commit() + # this specific chunk here is checking whether icons in the myriad/static/icons folder have a link in the database + # in case the database was rebuilt, or something else happened, it is a waste of storage keeping an unlinked image + icons = db.execute("SELECT * FROM icons").fetchall() + icon_storage = os.listdir(current_app.config["ICON_UPLOAD_FOLDER"]) + for icon in icon_storage: + in_database = False + for i in icons: + print(i[2], icon) + if i[2] == icon: + in_database = True + if not in_database: + os.remove(os.path.join(current_app.config["ICON_UPLOAD_FOLDER"], icon)) + + # and now for the same in reverse - clean the database of references to images that don't exist + for i in icons: + in_storage = False + print(i[2], i[0]) + if i[2] in icon_storage: + in_storage = True + if not in_storage: + db.execute("DELETE FROM icons WHERE id=(?)", (i[0],),) + db.commit() + + # the above cleanup operations should be a button in the manage sidebar but for now they are here. + + member = db.execute("SELECT * FROM member WHERE id=(?)",(mid,)).fetchone() icons = db.execute("SELECT * FROM icons WHERE member_id=(?)",(mid,)).fetchall() return render_template("manage/edit.html", member=member, icons=icons) @@ -71,4 +99,22 @@ def set_main_icon(mid, icon_id): db.execute("UPDATE member SET main_icon=(?) WHERE id=(?)",(icon_id, mid)) db.commit() - return redirect(url_for("manage.edit", mid=mid)) \ No newline at end of file + return redirect(url_for("manage.edit", mid=mid)) + +@bp.route("/add_to_front/") +@login_required +def add_to_front(mid): + db = get_db() + db.execute("UPDATE member SET front=(?) WHERE id=(?)",(1, mid)) + db.commit() + + return redirect(url_for('home.full_list')) + +@bp.route("/remove_front/") +@login_required +def remove_front(mid): + db = get_db() + db.execute("UPDATE member SET front=(?) WHERE id=(?)",(0, mid)) + db.commit() + + return redirect(url_for('home.full_list')) diff --git a/myriad/schema.sql b/myriad/schema.sql index a426cd2..da6af3b 100644 --- a/myriad/schema.sql +++ b/myriad/schema.sql @@ -3,8 +3,9 @@ DROP TABLE IF EXISTS member; DROP TABLE IF EXISTS icons; DROP TABLE IF EXISTS groups; DROP TABLE IF EXISTS group_members; -DROP TABLE IF EXISTS user_front; DROP TABLE IF EXISTS pages; +DROP TABLE IF EXISTS themes; +DROP TABLE IF EXISTS member_themes; CREATE TABLE user ( id INTEGER PRIMARY KEY AUTOINCREMENT, @@ -21,6 +22,7 @@ CREATE TABLE member ( bio TEXT, main_icon INTEGER, homepage BOOLEAN NOT NULL DEFAULT 0, + front BOOLEAN NOT NULL DEFAULT 0, FOREIGN KEY (user_id) REFERENCES user (id), FOREIGN KEY (main_icon) REFERENCES icons (id) ); @@ -46,14 +48,6 @@ CREATE TABLE group_members ( FOREIGN KEY (member_id) REFERENCES member (id) ); -CREATE TABLE user_front ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - member_id INTEGER NOT NULL, - user_id INTEGER NOT NULL, - FOREIGN KEY (member_id) REFERENCES member (id), - FOREIGN KEY (user_id) REFERENCES user (id) -); - CREATE TABLE pages ( id INTEGER PRIMARY KEY AUTOINCREMENT, member_id INTEGER NOT NULL, diff --git a/myriad/static/icons/any.jpg b/myriad/static/any.jpg similarity index 100% rename from myriad/static/icons/any.jpg rename to myriad/static/any.jpg diff --git a/myriad/templates/full.html b/myriad/templates/full.html index c08bf50..0e1578f 100644 --- a/myriad/templates/full.html +++ b/myriad/templates/full.html @@ -17,16 +17,16 @@
{{ member[3] }} {{ member[4] }}
- {% if member[6] != None %} + {% if icons[member[0]] %} {% else %} - + {% endif %}
{{ member[5] }}

- {% if g.user %}{% endif %} + {% if g.user %}{% endif %}
diff --git a/myriad/templates/index.html b/myriad/templates/index.html index dfaede2..119fe2d 100644 --- a/myriad/templates/index.html +++ b/myriad/templates/index.html @@ -1,11 +1,10 @@ {% extends 'base.html' %} - -{% block header %} -
{% block title %}Welcome{% endblock %}
-{% endblock %} +{% block title %}Welcome{% endblock %} {% block content %} -
- homepage :) +
+ currently fronting: {% for member in front_list %} {{ member[3] }} {% if front_list.index(member) != front_list|length -1 %}&{% endif %} {% endfor %}
+ + {% endblock %} \ No newline at end of file