diff --git a/myriad/__init__.py b/myriad/__init__.py index 7cb0058..09b85ee 100644 --- a/myriad/__init__.py +++ b/myriad/__init__.py @@ -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, diff --git a/myriad/home.py b/myriad/home.py index b24bc31..68c803f 100644 --- a/myriad/home.py +++ b/myriad/home.py @@ -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
Go Home", 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(): diff --git a/myriad/manage.py b/myriad/manage.py index 2854610..ef7777a 100644 --- a/myriad/manage.py +++ b/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) @@ -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/") @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) diff --git a/myriad/schema.sql b/myriad/schema.sql index f5ef3db..729e943 100644 --- a/myriad/schema.sql +++ b/myriad/schema.sql @@ -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, @@ -110,4 +111,11 @@ CREATE TABLE pages ( title TEXT, 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) ); \ No newline at end of file diff --git a/myriad/templates/manage/admin.html b/myriad/templates/manage/admin.html index 9296651..fecb7cf 100644 --- a/myriad/templates/manage/admin.html +++ b/myriad/templates/manage/admin.html @@ -47,24 +47,12 @@
- -
Export
- Export entire system as JSON (without images)
- Export entire system as ZIP (with images) - +
Export & Import
+ Export entire system as ZIP
- -
Import system from JSON
-

You must only run full system imports on a fresh database

-
- - -
- -
- -
Import system from ZIP
-

You must only run full system imports on a fresh database

+

Import system from previous Myriad export

+

This will replace existing data

+

Be sure to upload the .zip folder as it was downloaded without unzipping it

@@ -72,28 +60,5 @@
-
WIP ZONE
-
Site Users
-
These are the usernames that can log in to the site
- {% for user in users %} -

{{ user[1] }}{% if user[0]!=g.user[0] %} | Delete user{% endif %}

- {% endfor %} -

Add New User

- -
Admin Log
-
Actions taken by registered users
- -
Site Theme
-
Choose the overall theme for the site here
- - - -
- {% endblock %} \ No newline at end of file diff --git a/myriad/templates/page.html b/myriad/templates/page.html index 8cff725..ee237ee 100644 --- a/myriad/templates/page.html +++ b/myriad/templates/page.html @@ -58,13 +58,6 @@ {{ section[3]|safe }} {% endfor %} - - {% if member[13] %} {% if blinkies|length > 0 %} {% if member[18] %}
{{ member[18] }}
{% endif %} @@ -101,6 +94,16 @@ {% endif %}
+ {% if member[15] %} + {% if groups|length > 0 %} +
{{ member[20] }}
+ {% for gr in groups %} + {% set group = get_group(gr[1]) %} + >> {{ group[1] }}
+ {% endfor %} + {% endif %} + {% endif %} + {% endif %}