Compare commits
2 Commits
1f3081471b
...
71cc1d0357
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
71cc1d0357 | ||
|
|
2fcce4cbbe |
@@ -43,14 +43,17 @@ def create_app():
|
||||
def get_themes():
|
||||
themes = os.listdir(app.config["THEMES_FOLDER"])
|
||||
return themes
|
||||
|
||||
def w_server_time():
|
||||
return server_time()
|
||||
def w_get_datetime_str(dt_obj):
|
||||
return get_datetime_str(dt_obj)
|
||||
|
||||
def get_member(mid):
|
||||
db = get_db()
|
||||
member = db.execute("SELECT * FROM member WHERE id=(?)",(mid,)).fetchone()
|
||||
return member
|
||||
|
||||
def get_member_icon(mid):
|
||||
db = get_db()
|
||||
member = get_member(mid)
|
||||
@@ -61,26 +64,26 @@ def create_app():
|
||||
return 'any.jpg'
|
||||
return icon_name[2]
|
||||
|
||||
def get_member_icons(members):
|
||||
def get_member_icons(mid):
|
||||
db = get_db()
|
||||
icons={}
|
||||
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
|
||||
icons = db.execute("SELECT * FROM icons WHERE member_id=(?)",(mid,)).fetchall()
|
||||
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():
|
||||
return app.config["SYSTEM_NAME"]
|
||||
def get_pages_name():
|
||||
return app.config["PAGES_NAME"]
|
||||
|
||||
def check_favicon():
|
||||
if os.path.isfile(os.path.join(app.config["STATIC_FOLDER"], "favicon.ico")):
|
||||
return True
|
||||
return False
|
||||
|
||||
def get_pins_public():
|
||||
db = get_db()
|
||||
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_icon=get_member_icon,
|
||||
get_member_icons=get_member_icons,
|
||||
get_group=get_group,
|
||||
remove_html=remove_html,
|
||||
get_pages=get_pages,
|
||||
get_system_name=get_system_name,
|
||||
|
||||
@@ -53,6 +53,7 @@ def page(mid):
|
||||
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()
|
||||
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:
|
||||
return "Not Found <br> <a href='/'>Go Home</a>", 404
|
||||
|
||||
@@ -60,7 +61,7 @@ def page(mid):
|
||||
if len(blog_public) > 0:
|
||||
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")
|
||||
def groups():
|
||||
|
||||
164
myriad/manage.py
164
myriad/manage.py
@@ -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)
|
||||
@@ -601,6 +669,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
|
||||
def export_fields(mid):
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ DROP TABLE IF EXISTS stamps;
|
||||
DROP TABLE IF EXISTS front_log;
|
||||
DROP TABLE IF EXISTS sections;
|
||||
DROP TABLE IF EXISTS pages;
|
||||
DROP TABLE IF EXISTS custom_urls;
|
||||
|
||||
CREATE TABLE user (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
@@ -111,3 +112,10 @@ CREATE TABLE pages (
|
||||
content TEXT,
|
||||
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)
|
||||
);
|
||||
@@ -47,24 +47,12 @@
|
||||
|
||||
<hr>
|
||||
|
||||
|
||||
<div class="heading">Export</div>
|
||||
<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)
|
||||
|
||||
<div class="heading">Export & Import</div>
|
||||
<a href="{{ url_for('manage.export_system_full') }}">Export entire system as ZIP</a>
|
||||
<hr>
|
||||
|
||||
<div class="heading">Import system from JSON</div>
|
||||
<p>You must only run full system imports on a fresh database</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>
|
||||
<p><b>Import system from previous Myriad export</b></p>
|
||||
<p class="danger">This will replace existing data</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="zip">
|
||||
<input type="file" name="zip">
|
||||
<input type="submit" value="Upload ZIP">
|
||||
@@ -72,28 +60,5 @@
|
||||
|
||||
<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>
|
||||
{% endblock %}
|
||||
@@ -58,13 +58,6 @@
|
||||
{{ section[3]|safe }}
|
||||
{% endfor %}
|
||||
|
||||
<!-- {% if groups|length > 0 %}
|
||||
<div class="heading big">{{ member[20] }}</div>
|
||||
{% for group in groups %}
|
||||
|
||||
{% endfor %}
|
||||
{% endif %} -->
|
||||
|
||||
{% if member[13] %}
|
||||
{% if blinkies|length > 0 %}
|
||||
{% if member[18] %}<div class="heading big">{{ member[18] }}</div>{% endif %}
|
||||
@@ -101,6 +94,16 @@
|
||||
{% endif %}
|
||||
<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 %}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user