add and remove front

list shows up in a header bar on the home page
This commit is contained in:
cube
2026-03-17 13:26:49 +00:00
parent b6732c2ebd
commit 5d770587b4
7 changed files with 83 additions and 32 deletions

View File

@@ -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

View File

@@ -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)

View File

@@ -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))
return redirect(url_for("manage.edit", mid=mid))
@bp.route("/add_to_front/<mid>")
@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/<mid>")
@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'))

View File

@@ -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,

View File

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 25 KiB

View File

@@ -17,16 +17,16 @@
<div class="profile" id="{{ member[0] }}">
<div class="heading"><b>{{ member[3] }}</b> {{ member[4] }}</div>
{% if member[6] != None %}
{% if icons[member[0]] %}
<img src="{{ url_for('static', filename='icons/'+icons[member[0]]) }}" class="icon">
{% else %}
<img src="{{ url_for('static', filename='icons/any.jpg') }}" class="icon">
<img src="{{ url_for('static', filename='any.jpg') }}" class="icon">
{% endif %}
<div class="bio">
{{ member[5] }}
</div>
<br class="clear" />
{% if g.user %}<div class="heading links"><a href="">Add to Front</a> &#9734 <a href="{{ url_for('manage.edit', mid=member[0]) }}">Edit</a> &#9734 <a href="">Pin to Homepage</a></div>{% endif %}
{% if g.user %}<div class="heading links">{% if member[8]==0 %}<a href="{{ url_for('manage.add_to_front', mid=member[0]) }}">Add to Front</a>{% else %}<a href="{{ url_for('manage.remove_front', mid=member[0]) }}">Remove from Front</a>{% endif %} &#9734 <a href="{{ url_for('manage.edit', mid=member[0]) }}">Edit</a> &#9734 <a href="">Pin to Homepage</a></div>{% endif %}
<!-- <img src="/geo/dsgame.webp" class="dsgame"> -->
<br class="clear" />
</div>

View File

@@ -1,11 +1,10 @@
{% extends 'base.html' %}
{% block header %}
<div class="title">{% block title %}Welcome{% endblock %}</div>
{% endblock %}
{% block title %}Welcome{% endblock %}
{% block content %}
<div class="maintext">
homepage :)
<div id="frontbanner" class="heading">
<b>currently fronting: </b> {% for member in front_list %} {{ member[3] }} {% if front_list.index(member) != front_list|length -1 %}&{% endif %} {% endfor %}
</div>
{% endblock %}