瀏覽代碼

blog privacy settings, can delete blog posts

cube 1 天之前
父節點
當前提交
869588ef13
共有 5 個檔案被更改,包括 40 行新增7 行删除
  1. 1
    3
      README.md
  2. 14
    1
      myriad/blog.py
  3. 8
    1
      myriad/templates/blog/blog.html
  4. 6
    1
      myriad/templates/blog/new.html
  5. 11
    1
      myriad/templates/page.html

+ 1
- 3
README.md 查看文件

6
 
6
 
7
 # assorted todo
7
 # assorted todo
8
 
8
 
9
-- ==privacy settings in database to keep selected members private to logged-in users ==
10
-- ==privacy settings for groups? ==
11
-- ==privacy settings for blog posts==
9
+- privacy settings for blog posts
12
 - add delete button to blog posts on main feed
10
 - add delete button to blog posts on main feed
13
 - show blog posts in edit member section with a delete button
11
 - show blog posts in edit member section with a delete button
14
 - page theme edit inside the user (below user theme?) 
12
 - page theme edit inside the user (below user theme?) 

+ 14
- 1
myriad/blog.py 查看文件

35
         title = request.form['title']
35
         title = request.form['title']
36
         content = request.form['content']
36
         content = request.form['content']
37
         mid = request.form["mid"]
37
         mid = request.form["mid"]
38
+        privacy = request.form["privacy"]
38
 
39
 
39
-        db.execute("INSERT INTO blog (member_id, title, content) VALUES (?, ?, ?)",(mid, title, content))
40
+        db.execute("INSERT INTO blog (member_id, title, content, public) VALUES (?, ?, ?, ?)",(mid, title, content, privacy))
40
         db.commit()
41
         db.commit()
41
 
42
 
42
         return redirect(url_for('blog.blog'))
43
         return redirect(url_for('blog.blog'))
44
     
45
     
45
     return render_template('blog/new.html', members=members)
46
     return render_template('blog/new.html', members=members)
46
 
47
 
48
+@bp.route("/delete/<pid>/<location>")
49
+@login_required
50
+def delete(pid, location):
51
+    db = get_db()
52
+    db.execute("DELETE FROM blog WHERE id=(?)",(pid,))
53
+    db.commit()
54
+
55
+    if location == "blog":
56
+        return redirect(url_for("blog.blog"))
57
+    else:
58
+        return redirect(url_for("home.page", mid=location))
59
+

+ 8
- 1
myriad/templates/blog/blog.html 查看文件

8
   
8
   
9
   {% for post in blog %}
9
   {% for post in blog %}
10
     {% set op = member_ids[post[1]] %}
10
     {% set op = member_ids[post[1]] %}
11
+    {% if not g.user and op[23]==0 %}
12
+    {% elif not g.user and post[5]==0 %}
13
+    {% else %}
11
     <div class="post">
14
     <div class="post">
12
       {% if member_icons[op[0]][0] %}
15
       {% if member_icons[op[0]][0] %}
13
         <img src="{{ url_for('static', filename='icons/'+member_icons[op[0]][0]) }}" class="icon">
16
         <img src="{{ url_for('static', filename='icons/'+member_icons[op[0]][0]) }}" class="icon">
15
         <img src="{{ url_for('static', filename='any.jpg') }}" class="icon">
18
         <img src="{{ url_for('static', filename='any.jpg') }}" class="icon">
16
       {% endif %}
19
       {% endif %}
17
         <div class="title">{{post[3]|safe}}</div>
20
         <div class="title">{{post[3]|safe}}</div>
18
-        <div class="timestamp">{{post[2]}} - <a href="{{ url_for('home.page', mid=post[1]) }}">{{op[3]}}</a></div>
21
+        <div class="timestamp">{{post[2]}} - <a href="{{ url_for('home.page', mid=post[1]) }}">{{op[3]}}</a> {% if g.user %}{% if op[23]==0 %}(Private){% else %}(Public)</b>{% endif %}{% endif %}</div>
19
         <div class="content">
22
         <div class="content">
20
             {{post[4]|safe}}
23
             {{post[4]|safe}}
21
         </div>
24
         </div>
22
         <br class="clear" />
25
         <br class="clear" />
26
+        {% if g.user %}
27
+        {% if post[5]==0 %}<b style="color:red;">Private</b>{% else %}<b style="color:green;">Public</b>{% endif %} | <a href="{{url_for('blog.delete', pid=post[0], location='blog')}}" class="danger">Delete post</a>
28
+        {% endif %}
23
     </div>
29
     </div>
30
+    {% endif %}
24
   {% endfor %}
31
   {% endfor %}
25
 
32
 
26
 {% endblock %}
33
 {% endblock %}

+ 6
- 1
myriad/templates/blog/new.html 查看文件

15
       {% for member in members %}
15
       {% for member in members %}
16
       <option value="{{member[0]}}">{{member[1]}}</option>
16
       <option value="{{member[0]}}">{{member[1]}}</option>
17
       {% endfor %}
17
       {% endfor %}
18
-    </select> 
18
+    </select>
19
+    <br>
20
+    <input type="radio" id="public" name="privacy" value=1 checked>
21
+      <label for="public">Public</label><br>
22
+      <input type="radio" id="private" name="privacy" value=0>
23
+      <label for="private">Private</label><br>
19
     <input type="submit" value="Submit">
24
     <input type="submit" value="Submit">
20
   </form>
25
   </form>
21
 
26
 

+ 11
- 1
myriad/templates/page.html 查看文件

3
 
3
 
4
 {% block content %}
4
 {% block content %}
5
 
5
 
6
+    {% if not g.user and member[23]==0 %}
7
+    permission denied
8
+    {% else %}
9
+
6
     {% if icon %}
10
     {% if icon %}
7
     <img class="icon" src="{{ url_for('static', filename='icons/'+icon[0]) }}">
11
     <img class="icon" src="{{ url_for('static', filename='icons/'+icon[0]) }}">
8
     {% else %}
12
     {% else %}
18
     <div class="heading big">{{member[3]}}'s blog</div>
22
     <div class="heading big">{{member[3]}}'s blog</div>
19
         <div id="blog">
23
         <div id="blog">
20
             {% for post in blog %}
24
             {% for post in blog %}
25
+            {% if not g.user and post[5]==0 %}
26
+            {% else %}
21
             <div class="post">
27
             <div class="post">
22
                 <div class="title">{{post[3]|safe}}</div>
28
                 <div class="title">{{post[3]|safe}}</div>
23
-                <div class="timestamp">{{post[2]}}</div>
29
+                <div class="timestamp">{{post[2]}} {% if g.user %}{% if post[5]==0 %}(Private){% else %}(Public){% endif %}{% endif %}</div>
24
                 <div class="content">
30
                 <div class="content">
25
                     {{post[4]|safe}}
31
                     {{post[4]|safe}}
26
                 </div>
32
                 </div>
33
+                {% if g.user %}<a href="{{url_for('blog.delete', pid=post[0], location=member[0])}}" class="danger">Delete post</a>{% endif %}
27
             </div>
34
             </div>
35
+            {% endif %}
28
             {% endfor %}
36
             {% endfor %}
29
         </div>
37
         </div>
30
     {% endif %}
38
     {% endif %}
37
     {% endif %}
45
     {% endif %}
38
 
46
 
39
 
47
 
48
+    {% endif %}
49
+
40
 {% endblock %}
50
 {% endblock %}