Преглед изворни кода

upload icons

also pick an icon to be main icon from edit page
cube пре 5 дана
родитељ
комит
f7cba449ef
6 измењених фајлова са 48 додато и 16 уклоњено
  1. 1
    1
      myriad/__init__.py
  2. 11
    2
      myriad/home.py
  3. 22
    8
      myriad/manage.py
  4. 3
    2
      myriad/static/style.css
  5. 5
    1
      myriad/templates/full.html
  6. 6
    2
      myriad/templates/manage/edit.html

+ 1
- 1
myriad/__init__.py Прегледај датотеку

30
     from . import manage
30
     from . import manage
31
     app.register_blueprint(manage.bp)
31
     app.register_blueprint(manage.bp)
32
 
32
 
33
-    return app
33
+    return app

+ 11
- 2
myriad/home.py Прегледај датотеку

1
 from flask import (
1
 from flask import (
2
-    Blueprint, flash, g, redirect, render_template, request, url_for
2
+    Blueprint, flash, g, redirect, render_template, request, url_for, current_app
3
 )
3
 )
4
 from werkzeug.exceptions import abort
4
 from werkzeug.exceptions import abort
5
 
5
 
22
 def full_list():
22
 def full_list():
23
     db = get_db()
23
     db = get_db()
24
     members = db.execute('SELECT * FROM member ORDER BY member_name').fetchall()
24
     members = db.execute('SELECT * FROM member ORDER BY member_name').fetchall()
25
-    return render_template('full.html', memberlist=members)
25
+
26
+    icons={}
27
+    for member in members:
28
+        icon_id = member[6]
29
+        if icon_id:
30
+            icon = db.execute("SELECT icon_location FROM icons WHERE id=(?)",(icon_id,)).fetchone()
31
+            icons[member[0]] = icon[0]
32
+    print(icons)
33
+
34
+    return render_template('full.html', memberlist=members, icons=icons)

+ 22
- 8
myriad/manage.py Прегледај датотеку

1
 from flask import (
1
 from flask import (
2
-    Blueprint, flash, g, redirect, render_template, request, session, url_for
2
+    Blueprint, flash, g, redirect, render_template, request, session, url_for, current_app
3
 )
3
 )
4
 from werkzeug.utils import secure_filename
4
 from werkzeug.utils import secure_filename
5
-import os
5
+import os, uuid
6
 
6
 
7
 from myriad.auth import login_required
7
 from myriad.auth import login_required
8
 from myriad.db import get_db
8
 from myriad.db import get_db
50
             subtitle = request.form['subtitle']
50
             subtitle = request.form['subtitle']
51
             db.execute("UPDATE member SET member_name=(?), bio=(?), subtitle=(?) WHERE id=(?)",(name, bio, subtitle, mid))
51
             db.execute("UPDATE member SET member_name=(?), bio=(?), subtitle=(?) WHERE id=(?)",(name, bio, subtitle, mid))
52
             db.commit()
52
             db.commit()
53
-        elif "icon" in request.form:
54
-            file = request.form["icon"]
55
-            filename = secure_filename(file.filename)
56
-            file.save("/static/uploads/" + filename)
57
 
53
 
58
-        return redirect(url_for("home.full_list"))
54
+        if "file" in request.files:
55
+            file = request.files["file"]
56
+            filename = str(uuid.uuid4()) + "." + file.filename.split(".")[1]
57
+            file.save(os.path.join(current_app.config["UPLOAD_FOLDER"], filename))
58
+            db.execute("INSERT INTO icons (member_id, icon_location) VALUES (?, ?)", (mid, filename),)
59
+            db.commit()
60
+
61
+        member = db.execute("SELECT * FROM member WHERE id=(?)",(mid,)).fetchone()
62
+        icons = db.execute("SELECT * FROM icons WHERE member_id=(?)",(mid,)).fetchall()
63
+        return render_template("manage/edit.html", member=member, icons=icons)
64
+
65
+    return render_template("manage/edit.html", member=member, icons=icons)
66
+
67
+@bp.route("/set_main_icon/<mid>/<icon_id>")
68
+@login_required
69
+def set_main_icon(mid, icon_id):
70
+    db = get_db()
71
+    db.execute("UPDATE member SET main_icon=(?) WHERE id=(?)",(icon_id, mid))
72
+    db.commit()
59
 
73
 
60
-    return render_template("manage/edit.html", member=member, icons=icons)
74
+    return redirect(url_for("manage.edit", mid=mid))

+ 3
- 2
myriad/static/style.css Прегледај датотеку

99
     display:inline;
99
     display:inline;
100
     float:left;
100
     float:left;
101
     width:120px;
101
     width:120px;
102
-    height:auto;
102
+    height:120px;
103
+    object-fit: cover;
103
     border-radius:10px;
104
     border-radius:10px;
104
     margin:12px;
105
     margin:12px;
105
     border-style:solid;
106
     border-style:solid;
106
     border-width:2px;
107
     border-width:2px;
107
     border-color:#008bcc;
108
     border-color:#008bcc;
108
-    box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.2); 
109
+    box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.2);
109
 }
110
 }
110
 
111
 
111
 .bio{
112
 .bio{

+ 5
- 1
myriad/templates/full.html Прегледај датотеку

10
 
10
 
11
     <div class="profile">
11
     <div class="profile">
12
         <div class="heading"><b>{{ member[3] }}</b> {{ member[4] }}</div>
12
         <div class="heading"><b>{{ member[3] }}</b> {{ member[4] }}</div>
13
+        {% if member[6] != None %}
14
+        <img src="{{ url_for('static', filename='icons/'+icons[member[0]]) }}" class="icon">
15
+        {% else %}
13
         <img src="{{ url_for('static', filename='icons/any.jpg') }}" class="icon">
16
         <img src="{{ url_for('static', filename='icons/any.jpg') }}" class="icon">
17
+        {% endif %}
14
         <div class="bio">
18
         <div class="bio">
15
-            {{ member[5] }}
19
+            {{ member[5] }} 
16
         </div>
20
         </div>
17
         <br class="clear" />
21
         <br class="clear" />
18
         {% 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></div>{% endif %}
22
         {% 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></div>{% endif %}

+ 6
- 2
myriad/templates/manage/edit.html Прегледај датотеку

20
 
20
 
21
   <div class="heading">Manage Icons</div>
21
   <div class="heading">Manage Icons</div>
22
   <form method="post" enctype="multipart/form-data">
22
   <form method="post" enctype="multipart/form-data">
23
-      <input type="file" name="icon">
23
+      <input type="file" name="file">
24
       <input type="submit" value="Upload New Icon">
24
       <input type="submit" value="Upload New Icon">
25
   </form>
25
   </form>
26
 
26
 
27
   {% for icon in icons %}
27
   {% for icon in icons %}
28
 
28
 
29
-  <img class="icon" src="{{ icon[2] }}">
29
+  <img class="icon" src="{{ url_for('static', filename='icons/'+icon[2]) }}">
30
+  <br class="clear" />
31
+  <a href="{{ url_for('manage.set_main_icon', mid=member[0], icon_id=icon[0]) }}">Set Main Icon</a> &#9734 <a href="">Delete Icon</a>
32
+  <br class="clear" />
33
+  <hr>
30
 
34
 
31
   {% endfor %}
35
   {% endfor %}
32
 
36