Przeglądaj źródła

add and remove front

list shows up in a header bar on the home page
cube 5 dni temu
rodzic
commit
5d770587b4

+ 15
- 3
README.md Wyświetl plik

@@ -2,13 +2,19 @@
2 2
 
3 3
 flask app for plurals to publicly share member lists
4 4
 
5
-# dev set up 
5
+# dev set up (windows)
6 6
 
7 7
 - after cloning, run `py -3 -m venv .venv` in the root directory and then `.venv\Scripts\activate`
8 8
 - then `pip install Flask` inside the virtual env
9 9
 - you might also need to init a database, so use `flask --app myriad init-db`
10 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 18
 # prod set up
13 19
 
14 20
 - not ready yet
@@ -18,11 +24,17 @@ flask app for plurals to publicly share member lists
18 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 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 38
 # usage
27 39
 
28 40
 - the software here is free to use, and there's no requirement to link back

+ 8
- 8
myriad/home.py Wyświetl plik

@@ -10,13 +10,10 @@ bp = Blueprint('home', __name__)
10 10
 
11 11
 @bp.route('/')
12 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 18
 @bp.route('/full')
22 19
 def full_list():
@@ -28,7 +25,10 @@ def full_list():
28 25
         icon_id = member[6]
29 26
         if icon_id:
30 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 32
     print(icons)
33 33
 
34 34
     return render_template('full.html', memberlist=members, icons=icons)

+ 49
- 3
myriad/manage.py Wyświetl plik

@@ -15,7 +15,6 @@ def new():
15 15
     if request.method == 'POST':
16 16
         name = request.form['name']
17 17
         bio = request.form['bio']
18
-        #icon = request.form['icon']
19 18
         user_id = g.user[0]
20 19
         db = get_db()
21 20
         error = None
@@ -52,12 +51,41 @@ def edit(mid):
52 51
             db.commit()
53 52
 
54 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 57
             file = request.files["file"]
56 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 60
             db.execute("INSERT INTO icons (member_id, icon_location) VALUES (?, ?)", (mid, filename),)
59 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 89
         member = db.execute("SELECT * FROM member WHERE id=(?)",(mid,)).fetchone()
62 90
         icons = db.execute("SELECT * FROM icons WHERE member_id=(?)",(mid,)).fetchall()
63 91
         return render_template("manage/edit.html", member=member, icons=icons)
@@ -71,4 +99,22 @@ def set_main_icon(mid, icon_id):
71 99
     db.execute("UPDATE member SET main_icon=(?) WHERE id=(?)",(icon_id, mid))
72 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 Wyświetl plik

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

myriad/static/icons/any.jpg → myriad/static/any.jpg Wyświetl plik


+ 3
- 3
myriad/templates/full.html Wyświetl plik

@@ -17,16 +17,16 @@
17 17
 
18 18
     <div class="profile" id="{{ member[0] }}">
19 19
         <div class="heading"><b>{{ member[3] }}</b> {{ member[4] }}</div>
20
-        {% if member[6] != None %}
20
+        {% if icons[member[0]] %}
21 21
         <img src="{{ url_for('static', filename='icons/'+icons[member[0]]) }}" class="icon">
22 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 24
         {% endif %}
25 25
         <div class="bio">
26 26
             {{ member[5] }} 
27 27
         </div>
28 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 30
         <!-- <img src="/geo/dsgame.webp" class="dsgame"> -->
31 31
         <br class="clear" />
32 32
     </div>

+ 5
- 6
myriad/templates/index.html Wyświetl plik

@@ -1,11 +1,10 @@
1 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 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 7
   </div>
8
+
9
+
11 10
 {% endblock %}