we think we have export and import of pages and sections. there is definitely groups on member pages

This commit is contained in:
cube
2026-05-28 01:49:45 +01:00
parent 09f2786754
commit 2fcce4cbbe
6 changed files with 194 additions and 67 deletions

View File

@@ -43,14 +43,17 @@ def create_app():
def get_themes(): def get_themes():
themes = os.listdir(app.config["THEMES_FOLDER"]) themes = os.listdir(app.config["THEMES_FOLDER"])
return themes return themes
def w_server_time(): def w_server_time():
return server_time() return server_time()
def w_get_datetime_str(dt_obj): def w_get_datetime_str(dt_obj):
return get_datetime_str(dt_obj) return get_datetime_str(dt_obj)
def get_member(mid): def get_member(mid):
db = get_db() db = get_db()
member = db.execute("SELECT * FROM member WHERE id=(?)",(mid,)).fetchone() member = db.execute("SELECT * FROM member WHERE id=(?)",(mid,)).fetchone()
return member return member
def get_member_icon(mid): def get_member_icon(mid):
db = get_db() db = get_db()
member = get_member(mid) member = get_member(mid)
@@ -61,26 +64,26 @@ def create_app():
return 'any.jpg' return 'any.jpg'
return icon_name[2] return icon_name[2]
def get_member_icons(members): def get_member_icons(mid):
db = get_db() db = get_db()
icons={} icons = db.execute("SELECT * FROM icons WHERE member_id=(?)",(mid,)).fetchall()
for member in members:
icon_id = member[6]
if icon_id:
icon = db.execute("SELECT icon_location FROM icons WHERE id=(?)",(icon_id,)).fetchone()
if icon:
icons[member[0]] = icon[0]
else:
icons[member[0]] = None
return icons return icons
def get_group(gid):
db = get_db()
group = db.execute("SELECT * FROM groups WHERE id=(?)",(gid,)).fetchone()
return group
def get_system_name(): def get_system_name():
return app.config["SYSTEM_NAME"] return app.config["SYSTEM_NAME"]
def get_pages_name(): def get_pages_name():
return app.config["PAGES_NAME"] return app.config["PAGES_NAME"]
def check_favicon(): def check_favicon():
if os.path.isfile(os.path.join(app.config["STATIC_FOLDER"], "favicon.ico")): if os.path.isfile(os.path.join(app.config["STATIC_FOLDER"], "favicon.ico")):
return True return True
return False return False
def get_pins_public(): def get_pins_public():
db = get_db() db = get_db()
pins = db.execute("SELECT * FROM member WHERE homepage=(?) AND public=(?) ORDER BY member_name",(1, 1)).fetchall() pins = db.execute("SELECT * FROM member WHERE homepage=(?) AND public=(?) ORDER BY member_name",(1, 1)).fetchall()
@@ -96,6 +99,7 @@ def create_app():
get_member=get_member, get_member=get_member,
get_member_icon=get_member_icon, get_member_icon=get_member_icon,
get_member_icons=get_member_icons, get_member_icons=get_member_icons,
get_group=get_group,
remove_html=remove_html, remove_html=remove_html,
get_pages=get_pages, get_pages=get_pages,
get_system_name=get_system_name, get_system_name=get_system_name,

View File

@@ -53,6 +53,7 @@ def page(mid):
stamps = db.execute("SELECT stamp_location FROM stamps WHERE member_id=(?)",(mid,)).fetchall() stamps = db.execute("SELECT stamp_location FROM stamps WHERE member_id=(?)",(mid,)).fetchall()
blog_public = db.execute("SELECT * FROM blog WHERE member_id=(?) AND public=(?)",(mid,1)).fetchall() blog_public = db.execute("SELECT * FROM blog WHERE member_id=(?) AND public=(?)",(mid,1)).fetchall()
sections = db.execute("SELECT * FROM sections WHERE member_id=(?) ORDER BY position ASC",(mid,)).fetchall() sections = db.execute("SELECT * FROM sections WHERE member_id=(?) ORDER BY position ASC",(mid,)).fetchall()
groups = db.execute("SELECT * FROM group_members WHERE member_id=(?)",(mid,)).fetchall()
except TypeError: except TypeError:
return "Not Found <br> <a href='/'>Go Home</a>", 404 return "Not Found <br> <a href='/'>Go Home</a>", 404
@@ -60,7 +61,7 @@ def page(mid):
if len(blog_public) > 0: if len(blog_public) > 0:
blog_public_show = True blog_public_show = True
return render_template('page.html', member=member, blog=blog, icon=icon, all_icons=all_icons, blinkies=blinkies, stamps=stamps, blog_public_show=blog_public_show, sections=sections) return render_template('page.html', member=member, blog=blog, icon=icon, all_icons=all_icons, blinkies=blinkies, stamps=stamps, blog_public_show=blog_public_show, sections=sections, groups=groups)
@bp.route("/groups") @bp.route("/groups")
def groups(): def groups():

View File

@@ -1,7 +1,7 @@
from flask import Blueprint, flash, g, redirect, render_template, request, session, url_for, current_app, send_file, send_from_directory from flask import Blueprint, flash, g, redirect, render_template, request, session, url_for, current_app, send_file, send_from_directory
from werkzeug.utils import secure_filename from werkzeug.utils import secure_filename
import os, uuid, json, zipfile, datetime import os, uuid, json, zipfile, datetime, sqlite3
from myriad.utilities import server_time, get_datetime_obj, server_time_obj from myriad.utilities import server_time, get_datetime_obj, server_time_obj
from myriad.auth import login_required from myriad.auth import login_required
@@ -338,8 +338,43 @@ def import_groups(groups):
else: else:
privacy = 0 privacy = 0
db.execute("INSERT INTO groups (id, group_name, group_description, public) VALUES (?, ?, ?, ?)", (gid, name, description, privacy)) try:
db.commit() db.execute("INSERT INTO groups (id, group_name, group_description, public) VALUES (?, ?, ?, ?)",
(gid, name, description, privacy))
db.commit()
except sqlite3.IntegrityError:
pass
def import_sections(sections):
db = get_db()
for section in sections:
sid = section["id"]
mid = section["member_id"]
title = section["title"]
content = section["content"]
position = section["position"]
try:
db.execute("INSERT INTO sections (id, member_id, title, content, position) VALUES (?, ?, ?, ?, ?)",
(sid, mid, title, content, position))
db.commit()
except sqlite3.IntegrityError:
pass
def import_pages(pages):
db = get_db()
for page in pages:
pid = page["id"]
title = page["title"]
content = page["content"]
position = page["position"]
try:
db.execute("INSERT INTO pages (id, title, content, position) VALUES (?, ?, ?, ?)",
(pid, title, content, position))
db.commit()
except sqlite3.IntegrityError:
pass
def import_member(member): def import_member(member):
db = get_db() db = get_db()
@@ -413,9 +448,37 @@ def import_member(member):
stamps_title = member["stamps-title"] stamps_title = member["stamps-title"]
groups_title = member["groups-title"] groups_title = member["groups-title"]
db.execute("INSERT INTO member (id,created,user_id, member_name,subtitle, bio,public,theme,homepage,main_icon,show_blog,show_icons,show_blinkies,show_stamps,show_groups,blog_title,icons_title,blinkies_title,stamps_title,groups_title) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", try:
(mid, date_created_obj, user_id, name, subtitle, description,privacy, theme, homepage, main_icon_id, show_blog, show_icons, show_blinkies, show_stamps, show_groups, blog_title, icons_title, blinkies_title, stamps_title, groups_title)) db.execute("""
db.commit() INSERT INTO member
(id,created,user_id, member_name,subtitle,
bio,public,theme,homepage,main_icon,show_blog,
show_icons,show_blinkies,show_stamps,show_groups,
blog_title,icons_title,blinkies_title,stamps_title,groups_title)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""",
(mid,
date_created_obj,
user_id,
name,
subtitle,
description,
privacy,
theme,
homepage,
main_icon_id,
show_blog,
show_icons,
show_blinkies,
show_stamps,
show_groups,
blog_title,
icons_title,
blinkies_title,
stamps_title,
groups_title))
db.commit()
except sqlite3.IntegrityError:
pass
@@ -451,8 +514,13 @@ def admin():
system_content = zipf.read(f) system_content = zipf.read(f)
system_json = json.loads(system_content.decode()) system_json = json.loads(system_content.decode())
groups = system_json["groups"] groups_i = system_json["groups"]
import_groups(groups) sections = system_json["sections"]
pages_i = system_json["pages"]
import_groups(groups_i)
import_sections(sections)
import_pages(pages_i)
for m in system_json["members"]: for m in system_json["members"]:
import_member(m) import_member(m)
@@ -600,6 +668,64 @@ def generate_json_groups():
groups.append(g) groups.append(g)
return groups return groups
def generate_json_frontlog():
db = get_db()
front_log_r = db.execute("SELECT * FROM front_log ORDER BY start_time DESC").fetchall()
front_log = []
for front in front_log_r:
start_d_c = get_datetime_str(front[2])
if front[3]:
end_d_c = get_datetime_str(front[3])
else:
end_d_c = "(no end time)"
f = {
"id":front[0],
"member_id":front[1],
"start_time":start_d_c,
"end_time":end_d_c
}
front_log.append(f)
return front_log
def generate_json_sections():
db = get_db()
sections_r = db.execute("SELECT * FROM sections").fetchall()
sections = []
for section in sections_r:
s = {
"id":section[0],
"member_id":section[1],
"title":section[2],
"content":section[3],
"position":section[4]
}
sections.append(s)
return sections
def generate_json_pages():
db=get_db()
pages_r = db.execute("SELECT * FROM pages").fetchall()
pages=[]
for page in pages_r:
p = {
"id":page[0],
"title":page[1],
"content":page[2],
"position":page[3]
}
pages.append(p)
return pages
@bp.route("/export_fields/<mid>") @bp.route("/export_fields/<mid>")
@login_required @login_required
@@ -707,7 +833,6 @@ def export_member(mid):
def export_system(): def export_system():
db = get_db() db = get_db()
members = db.execute("SELECT * FROM member").fetchall() members = db.execute("SELECT * FROM member").fetchall()
groups_r = db.execute("SELECT * FROM groups").fetchall()
data = {} data = {}
data["members"] = [] data["members"] = []
@@ -718,6 +843,15 @@ def export_system():
groups = generate_json_groups() groups = generate_json_groups()
data["groups"] = groups data["groups"] = groups
front_log = generate_json_frontlog()
data["front_log"] = front_log
sections = generate_json_sections()
data["sections"] = sections
pages = generate_json_pages()
data["pages"] = pages
filename = "myriad_system_textonly.json" filename = "myriad_system_textonly.json"
file_full_path = current_app.config["TMP_FOLDER"] + "/" + filename file_full_path = current_app.config["TMP_FOLDER"] + "/" + filename
with open(file_full_path, 'w') as f: with open(file_full_path, 'w') as f:
@@ -733,6 +867,7 @@ def export_system_full():
icons = db.execute("SELECT icon_location FROM icons").fetchall() icons = db.execute("SELECT icon_location FROM icons").fetchall()
blinkies = db.execute("SELECT blinkie_location FROM blinkies").fetchall() blinkies = db.execute("SELECT blinkie_location FROM blinkies").fetchall()
stamps = db.execute("SELECT stamp_location FROM stamps").fetchall() stamps = db.execute("SELECT stamp_location FROM stamps").fetchall()
misc = os.listdir(current_app.config["MISC_UPLOAD_FOLDER"])
data = {} data = {}
data["members"] = [] data["members"] = []
@@ -743,6 +878,15 @@ def export_system_full():
groups = generate_json_groups() groups = generate_json_groups()
data["groups"] = groups data["groups"] = groups
front_log = generate_json_frontlog()
data["front_log"] = front_log
sections = generate_json_sections()
data["sections"] = sections
pages = generate_json_pages()
data["pages"] = pages
filename = "myriad_system.json" filename = "myriad_system.json"
file_full_path = current_app.config["TMP_FOLDER"] + "/" + filename file_full_path = current_app.config["TMP_FOLDER"] + "/" + filename
with open(file_full_path, 'w') as f: with open(file_full_path, 'w') as f:
@@ -761,6 +905,8 @@ def export_system_full():
for stamp in stamps: for stamp in stamps:
sname = stamp[0] sname = stamp[0]
zipf.write(current_app.config["STAMPS_UPLOAD_FOLDER"] + "/" + sname) zipf.write(current_app.config["STAMPS_UPLOAD_FOLDER"] + "/" + sname)
#for misc_file in misc:
#zipf.write(current_app.config["MISC_UPLOAD_FOLDER"] + "/" + misc_file)
return send_file("static/tmp/"+zip_name, as_attachment=True) return send_file("static/tmp/"+zip_name, as_attachment=True)

View File

@@ -9,6 +9,7 @@ DROP TABLE IF EXISTS stamps;
DROP TABLE IF EXISTS front_log; DROP TABLE IF EXISTS front_log;
DROP TABLE IF EXISTS sections; DROP TABLE IF EXISTS sections;
DROP TABLE IF EXISTS pages; DROP TABLE IF EXISTS pages;
DROP TABLE IF EXISTS custom_urls;
CREATE TABLE user ( CREATE TABLE user (
id INTEGER PRIMARY KEY AUTOINCREMENT, id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -110,4 +111,11 @@ CREATE TABLE pages (
title TEXT, title TEXT,
content TEXT, content TEXT,
position INTEGER position INTEGER
);
CREATE TABLE custom_urls (
id INTEGER PRIMARY KEY AUTOINCREMENT,
member_id INTEGER NOT NULL,
custom_url TEXT,
FOREIGN KEY (member_id) REFERENCES member (id)
); );

View File

@@ -47,24 +47,12 @@
<hr> <hr>
<div class="heading">Export & Import</div>
<div class="heading">Export</div> <a href="{{ url_for('manage.export_system_full') }}">Export entire system as ZIP</a>
<a href="{{ url_for('manage.export_system') }}">Export entire system as JSON</a> (without images)<br>
<a href="{{ url_for('manage.export_system_full') }}">Export entire system as ZIP</a> (with images)
<hr> <hr>
<p><b>Import system from previous Myriad export</b></p>
<div class="heading">Import system from JSON</div> <p class="danger">This will replace existing data</p>
<p>You must only run full system imports on a fresh database</p> <p>Be sure to upload the .zip folder as it was downloaded without unzipping it</p>
<form method="post" enctype="multipart/form-data" id="json">
<input type="file" name="json">
<input type="submit" value="Upload JSON">
</form>
<hr>
<div class="heading">Import system from ZIP</div>
<p>You must only run full system imports on a fresh database</p>
<form method="post" enctype="multipart/form-data" id="zip"> <form method="post" enctype="multipart/form-data" id="zip">
<input type="file" name="zip"> <input type="file" name="zip">
<input type="submit" value="Upload ZIP"> <input type="submit" value="Upload ZIP">
@@ -72,28 +60,5 @@
<hr> <hr>
<div class="heading big pink">WIP ZONE</div>
<div class="heading">Site Users</div>
<div class="maintext">These are the usernames that can log in to the site</div>
{% for user in users %}
<p><b>{{ user[1] }}</b>{% if user[0]!=g.user[0] %} | <a>Delete user</a>{% endif %}</p>
{% endfor %}
<p><a>Add New User</a></p>
<div class="heading">Admin Log</div>
<div class="maintext">Actions taken by registered users</div>
<div class="heading">Site Theme</div>
<div class="maintext">Choose the overall theme for the site here</div>
<form>
<select name="theme" id="theme">
{% for theme in get_themes() %}
{% set theme_name = theme.split(".")[0] %}
<option value="{{theme_name}}">{{theme_name}}</option>
{% endfor %}
</select>
<input type="submit" value="Submit">
</form>
</div> </div>
{% endblock %} {% endblock %}

View File

@@ -58,13 +58,6 @@
{{ section[3]|safe }} {{ section[3]|safe }}
{% endfor %} {% endfor %}
<!-- {% if groups|length > 0 %}
<div class="heading big">{{ member[20] }}</div>
{% for group in groups %}
{% endfor %}
{% endif %} -->
{% if member[13] %} {% if member[13] %}
{% if blinkies|length > 0 %} {% if blinkies|length > 0 %}
{% if member[18] %}<div class="heading big">{{ member[18] }}</div>{% endif %} {% if member[18] %}<div class="heading big">{{ member[18] }}</div>{% endif %}
@@ -101,6 +94,16 @@
{% endif %} {% endif %}
<br class="clear" /> <br class="clear" />
{% if member[15] %}
{% if groups|length > 0 %}
<div class="heading big">{{ member[20] }}</div>
{% for gr in groups %}
{% set group = get_group(gr[1]) %}
>> <a href="{{ url_for('home.group_page', gid=group[0]) }}">{{ group[1] }}</a><br>
{% endfor %}
{% endif %}
{% endif %}
{% endif %} {% endif %}