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

@@ -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 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.auth import login_required
@@ -338,8 +338,43 @@ def import_groups(groups):
else:
privacy = 0
db.execute("INSERT INTO groups (id, group_name, group_description, public) VALUES (?, ?, ?, ?)", (gid, name, description, privacy))
db.commit()
try:
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):
db = get_db()
@@ -413,9 +448,37 @@ def import_member(member):
stamps_title = member["stamps-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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
(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()
try:
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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""",
(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_json = json.loads(system_content.decode())
groups = system_json["groups"]
import_groups(groups)
groups_i = system_json["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"]:
import_member(m)
@@ -600,6 +668,64 @@ def generate_json_groups():
groups.append(g)
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>")
@login_required
@@ -707,7 +833,6 @@ def export_member(mid):
def export_system():
db = get_db()
members = db.execute("SELECT * FROM member").fetchall()
groups_r = db.execute("SELECT * FROM groups").fetchall()
data = {}
data["members"] = []
@@ -718,6 +843,15 @@ def export_system():
groups = generate_json_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"
file_full_path = current_app.config["TMP_FOLDER"] + "/" + filename
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()
blinkies = db.execute("SELECT blinkie_location FROM blinkies").fetchall()
stamps = db.execute("SELECT stamp_location FROM stamps").fetchall()
misc = os.listdir(current_app.config["MISC_UPLOAD_FOLDER"])
data = {}
data["members"] = []
@@ -743,6 +878,15 @@ def export_system_full():
groups = generate_json_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"
file_full_path = current_app.config["TMP_FOLDER"] + "/" + filename
with open(file_full_path, 'w') as f:
@@ -761,6 +905,8 @@ def export_system_full():
for stamp in stamps:
sname = stamp[0]
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)