Quellcode durchsuchen

blog privacy settings, can delete blog posts

cube vor 1 Tag
Ursprung
Commit
869588ef13
5 geänderte Dateien mit 40 neuen und 7 gelöschten Zeilen
  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 Datei anzeigen

@@ -6,9 +6,7 @@ logged in users are presumed to all be admins with distinction only between bein
6 6
 
7 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 10
 - add delete button to blog posts on main feed
13 11
 - show blog posts in edit member section with a delete button
14 12
 - page theme edit inside the user (below user theme?) 

+ 14
- 1
myriad/blog.py Datei anzeigen

@@ -35,8 +35,9 @@ def new():
35 35
         title = request.form['title']
36 36
         content = request.form['content']
37 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 41
         db.commit()
41 42
 
42 43
         return redirect(url_for('blog.blog'))
@@ -44,3 +45,15 @@ def new():
44 45
     
45 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 Datei anzeigen

@@ -8,6 +8,9 @@
8 8
   
9 9
   {% for post in blog %}
10 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 14
     <div class="post">
12 15
       {% if member_icons[op[0]][0] %}
13 16
         <img src="{{ url_for('static', filename='icons/'+member_icons[op[0]][0]) }}" class="icon">
@@ -15,12 +18,16 @@
15 18
         <img src="{{ url_for('static', filename='any.jpg') }}" class="icon">
16 19
       {% endif %}
17 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 22
         <div class="content">
20 23
             {{post[4]|safe}}
21 24
         </div>
22 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 29
     </div>
30
+    {% endif %}
24 31
   {% endfor %}
25 32
 
26 33
 {% endblock %}

+ 6
- 1
myriad/templates/blog/new.html Datei anzeigen

@@ -15,7 +15,12 @@
15 15
       {% for member in members %}
16 16
       <option value="{{member[0]}}">{{member[1]}}</option>
17 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 24
     <input type="submit" value="Submit">
20 25
   </form>
21 26
 

+ 11
- 1
myriad/templates/page.html Datei anzeigen

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