add and remove front
list shows up in a header bar on the home page
This commit is contained in:
@@ -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)
|
||||
@@ -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'))
|
||||
|
||||
@@ -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,
|
||||
|
||||
|
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 25 KiB |
@@ -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> ☆ <a href="{{ url_for('manage.edit', mid=member[0]) }}">Edit</a> ☆ <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 %} ☆ <a href="{{ url_for('manage.edit', mid=member[0]) }}">Edit</a> ☆ <a href="">Pin to Homepage</a></div>{% endif %}
|
||||
<!-- <img src="/geo/dsgame.webp" class="dsgame"> -->
|
||||
<br class="clear" />
|
||||
</div>
|
||||
|
||||
@@ -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 %}
|
||||
Reference in New Issue
Block a user