add and remove front
list shows up in a header bar on the home page
This commit is contained in:
18
README.md
18
README.md
@@ -2,13 +2,19 @@
|
|||||||
|
|
||||||
flask app for plurals to publicly share member lists
|
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`
|
- 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
|
- then `pip install Flask` inside the virtual env
|
||||||
- you might also need to init a database, so use `flask --app myriad init-db`
|
- 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`
|
- 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
|
# prod set up
|
||||||
|
|
||||||
- not ready yet
|
- 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
|
- 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
|
REGISTRATION = True
|
||||||
UPLOAD_FOLDER = 'myriad/static/icons'
|
|
||||||
ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'gif'}
|
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
|
# usage
|
||||||
|
|
||||||
- the software here is free to use, and there's no requirement to link back
|
- the software here is free to use, and there's no requirement to link back
|
||||||
|
|||||||
@@ -10,13 +10,10 @@ bp = Blueprint('home', __name__)
|
|||||||
|
|
||||||
@bp.route('/')
|
@bp.route('/')
|
||||||
def index():
|
def index():
|
||||||
# db = get_db()
|
db = get_db()
|
||||||
# posts = db.execute(
|
fronters = db.execute("SELECT * FROM member WHERE front=(?)",(1,)).fetchall()
|
||||||
# 'SELECT p.id, title, body, created, author_id, username'
|
|
||||||
# ' FROM post p JOIN user u ON p.author_id = u.id'
|
return render_template('index.html', front_list=fronters)
|
||||||
# ' ORDER BY created DESC'
|
|
||||||
# ).fetchall()
|
|
||||||
return render_template('index.html')
|
|
||||||
|
|
||||||
@bp.route('/full')
|
@bp.route('/full')
|
||||||
def full_list():
|
def full_list():
|
||||||
@@ -28,7 +25,10 @@ def full_list():
|
|||||||
icon_id = member[6]
|
icon_id = member[6]
|
||||||
if icon_id:
|
if icon_id:
|
||||||
icon = db.execute("SELECT icon_location FROM icons WHERE id=(?)",(icon_id,)).fetchone()
|
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)
|
print(icons)
|
||||||
|
|
||||||
return render_template('full.html', memberlist=members, icons=icons)
|
return render_template('full.html', memberlist=members, icons=icons)
|
||||||
@@ -15,7 +15,6 @@ def new():
|
|||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
name = request.form['name']
|
name = request.form['name']
|
||||||
bio = request.form['bio']
|
bio = request.form['bio']
|
||||||
#icon = request.form['icon']
|
|
||||||
user_id = g.user[0]
|
user_id = g.user[0]
|
||||||
db = get_db()
|
db = get_db()
|
||||||
error = None
|
error = None
|
||||||
@@ -52,12 +51,41 @@ def edit(mid):
|
|||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
if "file" in request.files:
|
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"]
|
file = request.files["file"]
|
||||||
filename = str(uuid.uuid4()) + "." + file.filename.split(".")[1]
|
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.execute("INSERT INTO icons (member_id, icon_location) VALUES (?, ?)", (mid, filename),)
|
||||||
db.commit()
|
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()
|
member = db.execute("SELECT * FROM member WHERE id=(?)",(mid,)).fetchone()
|
||||||
icons = db.execute("SELECT * FROM icons WHERE member_id=(?)",(mid,)).fetchall()
|
icons = db.execute("SELECT * FROM icons WHERE member_id=(?)",(mid,)).fetchall()
|
||||||
return render_template("manage/edit.html", member=member, icons=icons)
|
return render_template("manage/edit.html", member=member, icons=icons)
|
||||||
@@ -72,3 +100,21 @@ def set_main_icon(mid, icon_id):
|
|||||||
db.commit()
|
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 icons;
|
||||||
DROP TABLE IF EXISTS groups;
|
DROP TABLE IF EXISTS groups;
|
||||||
DROP TABLE IF EXISTS group_members;
|
DROP TABLE IF EXISTS group_members;
|
||||||
DROP TABLE IF EXISTS user_front;
|
|
||||||
DROP TABLE IF EXISTS pages;
|
DROP TABLE IF EXISTS pages;
|
||||||
|
DROP TABLE IF EXISTS themes;
|
||||||
|
DROP TABLE IF EXISTS member_themes;
|
||||||
|
|
||||||
CREATE TABLE user (
|
CREATE TABLE user (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
@@ -21,6 +22,7 @@ CREATE TABLE member (
|
|||||||
bio TEXT,
|
bio TEXT,
|
||||||
main_icon INTEGER,
|
main_icon INTEGER,
|
||||||
homepage BOOLEAN NOT NULL DEFAULT 0,
|
homepage BOOLEAN NOT NULL DEFAULT 0,
|
||||||
|
front BOOLEAN NOT NULL DEFAULT 0,
|
||||||
FOREIGN KEY (user_id) REFERENCES user (id),
|
FOREIGN KEY (user_id) REFERENCES user (id),
|
||||||
FOREIGN KEY (main_icon) REFERENCES icons (id)
|
FOREIGN KEY (main_icon) REFERENCES icons (id)
|
||||||
);
|
);
|
||||||
@@ -46,14 +48,6 @@ CREATE TABLE group_members (
|
|||||||
FOREIGN KEY (member_id) REFERENCES member (id)
|
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 (
|
CREATE TABLE pages (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
member_id INTEGER NOT NULL,
|
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="profile" id="{{ member[0] }}">
|
||||||
<div class="heading"><b>{{ member[3] }}</b> {{ member[4] }}</div>
|
<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">
|
<img src="{{ url_for('static', filename='icons/'+icons[member[0]]) }}" class="icon">
|
||||||
{% else %}
|
{% else %}
|
||||||
<img src="{{ url_for('static', filename='icons/any.jpg') }}" class="icon">
|
<img src="{{ url_for('static', filename='any.jpg') }}" class="icon">
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="bio">
|
<div class="bio">
|
||||||
{{ member[5] }}
|
{{ member[5] }}
|
||||||
</div>
|
</div>
|
||||||
<br class="clear" />
|
<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"> -->
|
<!-- <img src="/geo/dsgame.webp" class="dsgame"> -->
|
||||||
<br class="clear" />
|
<br class="clear" />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
{% extends 'base.html' %}
|
{% extends 'base.html' %}
|
||||||
|
{% block title %}Welcome{% endblock %}
|
||||||
{% block header %}
|
|
||||||
<div class="title">{% block title %}Welcome{% endblock %}</div>
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="maintext">
|
<div id="frontbanner" class="heading">
|
||||||
homepage :)
|
<b>currently fronting: </b> {% for member in front_list %} {{ member[3] }} {% if front_list.index(member) != front_list|length -1 %}&{% endif %} {% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
Reference in New Issue
Block a user