ソースを参照

add and remove front

list shows up in a header bar on the home page
cube 5 日 前
コミット
5d770587b4
共有7 個のファイルを変更した83 個の追加32 個の削除を含む
  1. 15
    3
      README.md
  2. 8
    8
      myriad/home.py
  3. 49
    3
      myriad/manage.py
  4. 3
    9
      myriad/schema.sql
  5. 0
    0
      myriad/static/any.jpg
  6. 3
    3
      myriad/templates/full.html
  7. 5
    6
      myriad/templates/index.html

+ 15
- 3
README.md ファイルの表示

2
 
2
 
3
 flask app for plurals to publicly share member lists
3
 flask app for plurals to publicly share member lists
4
 
4
 
5
-# dev set up 
5
+# dev set up (windows)
6
 
6
 
7
 - after cloning, run `py -3 -m venv .venv` in the root directory and then `.venv\Scripts\activate`
7
 - after cloning, run `py -3 -m venv .venv` in the root directory and then `.venv\Scripts\activate`
8
 - then `pip install Flask` inside the virtual env
8
 - then `pip install Flask` inside the virtual env
9
 - you might also need to init a database, so use `flask --app myriad init-db`
9
 - you might also need to init a database, so use `flask --app myriad init-db`
10
 - to start the site use `flask --app myriad run --debug`
10
 - to start the site use `flask --app myriad run --debug`
11
 
11
 
12
+do not deploy this way, the packaged flask server is not secure. production instructions will be provided when the project is ready
13
+
14
+- you will need to run `.venv\Scripts\activate` from the folder every time you start working on it
15
+- 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
16
+- start the site with `flask --app myriad run --debug` as usual
17
+
12
 # prod set up
18
 # prod set up
13
 
19
 
14
 - not ready yet
20
 - not ready yet
18
 - create `config.py` in the instance folder and customise the following settings to your needs
24
 - create `config.py` in the instance folder and customise the following settings to your needs
19
 
25
 
20
 ```
26
 ```
21
-REGISTRATION: False # only set to True if in a development situation, or to create your first user
22
-UPLOAD_FOLDER = 'myriad/static/icons'
27
+REGISTRATION = True
23
 ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'gif'}
28
 ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'gif'}
29
+ICON_UPLOAD_FOLDER = 'myriad/static/icons'
30
+BLINKIES_UPLOAD_FOLDER = 'myriad/static/blinkies'
31
+STAMPS_UPLOAD_FOLDER = 'myriad/static/stamps'
24
 ```
32
 ```
25
 
33
 
34
+- 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
35
+- feel free to adjust allowed file extensions however you choose
36
+- upload folders don't need to be changed
37
+
26
 # usage
38
 # usage
27
 
39
 
28
 - the software here is free to use, and there's no requirement to link back
40
 - the software here is free to use, and there's no requirement to link back

+ 8
- 8
myriad/home.py ファイルの表示

10
 
10
 
11
 @bp.route('/')
11
 @bp.route('/')
12
 def index():
12
 def index():
13
-    # db = get_db()
14
-    # posts = db.execute(
15
-    #     'SELECT p.id, title, body, created, author_id, username'
16
-    #     ' FROM post p JOIN user u ON p.author_id = u.id'
17
-    #     ' ORDER BY created DESC'
18
-    # ).fetchall()
19
-    return render_template('index.html')
13
+    db = get_db()
14
+    fronters = db.execute("SELECT * FROM member WHERE front=(?)",(1,)).fetchall()
15
+
16
+    return render_template('index.html', front_list=fronters)
20
 
17
 
21
 @bp.route('/full')
18
 @bp.route('/full')
22
 def full_list():
19
 def full_list():
28
         icon_id = member[6]
25
         icon_id = member[6]
29
         if icon_id:
26
         if icon_id:
30
             icon = db.execute("SELECT icon_location FROM icons WHERE id=(?)",(icon_id,)).fetchone()
27
             icon = db.execute("SELECT icon_location FROM icons WHERE id=(?)",(icon_id,)).fetchone()
31
-            icons[member[0]] = icon[0]
28
+            if icon:
29
+                icons[member[0]] = icon[0]
30
+            else:
31
+                icons[member[0]] = None
32
     print(icons)
32
     print(icons)
33
 
33
 
34
     return render_template('full.html', memberlist=members, icons=icons)
34
     return render_template('full.html', memberlist=members, icons=icons)

+ 49
- 3
myriad/manage.py ファイルの表示

15
     if request.method == 'POST':
15
     if request.method == 'POST':
16
         name = request.form['name']
16
         name = request.form['name']
17
         bio = request.form['bio']
17
         bio = request.form['bio']
18
-        #icon = request.form['icon']
19
         user_id = g.user[0]
18
         user_id = g.user[0]
20
         db = get_db()
19
         db = get_db()
21
         error = None
20
         error = None
52
             db.commit()
51
             db.commit()
53
 
52
 
54
         if "file" in request.files:
53
         if "file" in request.files:
54
+            # here we are just saving the uploaded file to the icons folder. 
55
+            # we're not going hard on security because we expect there to only be 1 admin
56
+            # but the filename will always be changed to a random string of numbers and letters known as uuid
55
             file = request.files["file"]
57
             file = request.files["file"]
56
             filename = str(uuid.uuid4()) + "." + file.filename.split(".")[1]
58
             filename = str(uuid.uuid4()) + "." + file.filename.split(".")[1]
57
-            file.save(os.path.join(current_app.config["UPLOAD_FOLDER"], filename))
59
+            file.save(os.path.join(current_app.config["ICON_UPLOAD_FOLDER"], filename))
58
             db.execute("INSERT INTO icons (member_id, icon_location) VALUES (?, ?)", (mid, filename),)
60
             db.execute("INSERT INTO icons (member_id, icon_location) VALUES (?, ?)", (mid, filename),)
59
             db.commit()
61
             db.commit()
60
 
62
 
63
+            # this specific chunk here is checking whether icons in the myriad/static/icons folder have a link in the database
64
+            # in case the database was rebuilt, or something else happened, it is a waste of storage keeping an unlinked image
65
+            icons = db.execute("SELECT * FROM icons").fetchall()
66
+            icon_storage = os.listdir(current_app.config["ICON_UPLOAD_FOLDER"])
67
+            for icon in icon_storage:
68
+                in_database = False
69
+                for i in icons:
70
+                    print(i[2], icon)
71
+                    if i[2] == icon:
72
+                        in_database = True
73
+                if not in_database:
74
+                    os.remove(os.path.join(current_app.config["ICON_UPLOAD_FOLDER"], icon))
75
+
76
+            # and now for the same in reverse - clean the database of references to images that don't exist
77
+            for i in icons:
78
+                in_storage = False
79
+                print(i[2], i[0])
80
+                if i[2] in icon_storage:
81
+                    in_storage = True
82
+                if not in_storage:
83
+                    db.execute("DELETE FROM icons WHERE id=(?)", (i[0],),)
84
+                    db.commit()
85
+
86
+            # the above cleanup operations should be a button in the manage sidebar but for now they are here.
87
+
88
+
61
         member = db.execute("SELECT * FROM member WHERE id=(?)",(mid,)).fetchone()
89
         member = db.execute("SELECT * FROM member WHERE id=(?)",(mid,)).fetchone()
62
         icons = db.execute("SELECT * FROM icons WHERE member_id=(?)",(mid,)).fetchall()
90
         icons = db.execute("SELECT * FROM icons WHERE member_id=(?)",(mid,)).fetchall()
63
         return render_template("manage/edit.html", member=member, icons=icons)
91
         return render_template("manage/edit.html", member=member, icons=icons)
71
     db.execute("UPDATE member SET main_icon=(?) WHERE id=(?)",(icon_id, mid))
99
     db.execute("UPDATE member SET main_icon=(?) WHERE id=(?)",(icon_id, mid))
72
     db.commit()
100
     db.commit()
73
 
101
 
74
-    return redirect(url_for("manage.edit", mid=mid))
102
+    return redirect(url_for("manage.edit", mid=mid))
103
+
104
+@bp.route("/add_to_front/<mid>")
105
+@login_required
106
+def add_to_front(mid):
107
+    db = get_db()
108
+    db.execute("UPDATE member SET front=(?) WHERE id=(?)",(1, mid))
109
+    db.commit()
110
+
111
+    return redirect(url_for('home.full_list'))
112
+
113
+@bp.route("/remove_front/<mid>")
114
+@login_required
115
+def remove_front(mid):
116
+    db = get_db()
117
+    db.execute("UPDATE member SET front=(?) WHERE id=(?)",(0, mid))
118
+    db.commit()
119
+
120
+    return redirect(url_for('home.full_list'))

+ 3
- 9
myriad/schema.sql ファイルの表示

3
 DROP TABLE IF EXISTS icons;
3
 DROP TABLE IF EXISTS icons;
4
 DROP TABLE IF EXISTS groups;
4
 DROP TABLE IF EXISTS groups;
5
 DROP TABLE IF EXISTS group_members;
5
 DROP TABLE IF EXISTS group_members;
6
-DROP TABLE IF EXISTS user_front;
7
 DROP TABLE IF EXISTS pages;
6
 DROP TABLE IF EXISTS pages;
7
+DROP TABLE IF EXISTS themes;
8
+DROP TABLE IF EXISTS member_themes;
8
 
9
 
9
 CREATE TABLE user (
10
 CREATE TABLE user (
10
   id INTEGER PRIMARY KEY AUTOINCREMENT,
11
   id INTEGER PRIMARY KEY AUTOINCREMENT,
21
   bio TEXT,
22
   bio TEXT,
22
   main_icon INTEGER,
23
   main_icon INTEGER,
23
   homepage BOOLEAN NOT NULL DEFAULT 0,
24
   homepage BOOLEAN NOT NULL DEFAULT 0,
25
+  front BOOLEAN NOT NULL DEFAULT 0,
24
   FOREIGN KEY (user_id) REFERENCES user (id),
26
   FOREIGN KEY (user_id) REFERENCES user (id),
25
   FOREIGN KEY (main_icon) REFERENCES icons (id)
27
   FOREIGN KEY (main_icon) REFERENCES icons (id)
26
 );
28
 );
46
   FOREIGN KEY (member_id) REFERENCES member (id)
48
   FOREIGN KEY (member_id) REFERENCES member (id)
47
 );
49
 );
48
 
50
 
49
-CREATE TABLE user_front (
50
-  id INTEGER PRIMARY KEY AUTOINCREMENT,
51
-  member_id INTEGER NOT NULL,
52
-  user_id INTEGER NOT NULL,
53
-  FOREIGN KEY (member_id) REFERENCES member (id),
54
-  FOREIGN KEY (user_id) REFERENCES user (id)
55
-);
56
-
57
 CREATE TABLE pages (
51
 CREATE TABLE pages (
58
   id INTEGER PRIMARY KEY AUTOINCREMENT,
52
   id INTEGER PRIMARY KEY AUTOINCREMENT,
59
   member_id INTEGER NOT NULL,
53
   member_id INTEGER NOT NULL,

myriad/static/icons/any.jpg → myriad/static/any.jpg ファイルの表示


+ 3
- 3
myriad/templates/full.html ファイルの表示

17
 
17
 
18
     <div class="profile" id="{{ member[0] }}">
18
     <div class="profile" id="{{ member[0] }}">
19
         <div class="heading"><b>{{ member[3] }}</b> {{ member[4] }}</div>
19
         <div class="heading"><b>{{ member[3] }}</b> {{ member[4] }}</div>
20
-        {% if member[6] != None %}
20
+        {% if icons[member[0]] %}
21
         <img src="{{ url_for('static', filename='icons/'+icons[member[0]]) }}" class="icon">
21
         <img src="{{ url_for('static', filename='icons/'+icons[member[0]]) }}" class="icon">
22
         {% else %}
22
         {% else %}
23
-        <img src="{{ url_for('static', filename='icons/any.jpg') }}" class="icon">
23
+        <img src="{{ url_for('static', filename='any.jpg') }}" class="icon">
24
         {% endif %}
24
         {% endif %}
25
         <div class="bio">
25
         <div class="bio">
26
             {{ member[5] }} 
26
             {{ member[5] }} 
27
         </div>
27
         </div>
28
         <br class="clear" />
28
         <br class="clear" />
29
-        {% if g.user %}<div class="heading links"><a href="">Add to Front</a> &#9734 <a href="{{ url_for('manage.edit', mid=member[0]) }}">Edit</a> &#9734 <a href="">Pin to Homepage</a></div>{% endif %}
29
+        {% 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 %} &#9734 <a href="{{ url_for('manage.edit', mid=member[0]) }}">Edit</a> &#9734 <a href="">Pin to Homepage</a></div>{% endif %}
30
         <!-- <img src="/geo/dsgame.webp" class="dsgame"> -->
30
         <!-- <img src="/geo/dsgame.webp" class="dsgame"> -->
31
         <br class="clear" />
31
         <br class="clear" />
32
     </div>
32
     </div>

+ 5
- 6
myriad/templates/index.html ファイルの表示

1
 {% extends 'base.html' %}
1
 {% extends 'base.html' %}
2
-
3
-{% block header %}
4
-  <div class="title">{% block title %}Welcome{% endblock %}</div>
5
-{% endblock %}
2
+{% block title %}Welcome{% endblock %}
6
 
3
 
7
 {% block content %}
4
 {% block content %}
8
-  <div class="maintext">
9
-    homepage :) 
5
+  <div id="frontbanner" class="heading">
6
+    <b>currently fronting: </b> {% for member in front_list %} {{ member[3] }} {% if front_list.index(member) != front_list|length -1 %}&{% endif %} {% endfor %}
10
   </div>
7
   </div>
8
+
9
+
11
 {% endblock %}
10
 {% endblock %}