Added the ability to edit posts, with edited marker on profiles
This commit is contained in:
parent
de15a84c54
commit
ba9367b35d
4 changed files with 47 additions and 3 deletions
17
Tweeder.py
17
Tweeder.py
|
@ -215,6 +215,7 @@ def like_post(post_id):
|
|||
elif request.method == "GET":
|
||||
pass
|
||||
|
||||
|
||||
@app.route("/unlike/<post_id>", methods=["GET", "POST"])
|
||||
def unlike_post(post_id):
|
||||
if 'username' not in session.keys(): return redirect(url_for('login'))
|
||||
|
@ -245,5 +246,21 @@ def mentions():
|
|||
posts=timeline.get_mentions(logged_in))
|
||||
|
||||
|
||||
@app.route("/editpost/<post_id>", methods=["GET", "POST"])
|
||||
def editpost(post_id):
|
||||
if 'username' not in session.keys(): return redirect(url_for('login'))
|
||||
logged_in = session['username']
|
||||
post_obj = timeline.post_details(post_id)
|
||||
print(post_obj)
|
||||
if request.method == "GET":
|
||||
if post_obj['poster'].lower() != logged_in:
|
||||
return abort(403)
|
||||
else:
|
||||
return render_template('editpost.html', post_obj=post_obj)
|
||||
elif request.method == "POST":
|
||||
timeline.edit_status(post_obj['_id'], request.form['status'])
|
||||
return redirect('/view/'+str(post_id))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(host="127.0.0.1", debug=True)
|
||||
|
|
|
@ -30,12 +30,21 @@ def post_status(username, content, private=False, replyTo=False, location=False)
|
|||
'mentions': accounts_mentioned,
|
||||
'location': False or location,
|
||||
'private': False or private,
|
||||
'edited': False
|
||||
|
||||
}
|
||||
|
||||
timeline_db.insert_one(status)
|
||||
|
||||
|
||||
def edit_status(post_id, new_content):
|
||||
timeline_db.update_one({"_id": ObjectId(post_id)},
|
||||
{"$set":
|
||||
{"content": new_content.replace('\n', ' ').replace('\r', ''),
|
||||
"edited": True}
|
||||
})
|
||||
|
||||
|
||||
def user_posts_by_username(username):
|
||||
return timeline_db.find({'posterid': accounts_db.find_one({"username": username})['_id']}).sort('timePosted', pymongo.DESCENDING)
|
||||
|
||||
|
|
14
templates/editpost.html
Normal file
14
templates/editpost.html
Normal file
|
@ -0,0 +1,14 @@
|
|||
{% extends 'layout.html' %}
|
||||
{% block content %}
|
||||
<div class="container">
|
||||
<div class="card">
|
||||
<div class="card-header">Editing post</div>
|
||||
<div class="card-body">
|
||||
<form method="POST" action="/editpost/{{ post_obj._id }}" class="input-group">
|
||||
<input type="text" name="status" style="margin-right: 16px;" class="form-control" value="{{ post_obj.content }}" autofocus />
|
||||
<input type="submit" class="btn btn-primary" value="Do Post" />
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
|
@ -4,7 +4,7 @@
|
|||
<div class="container">
|
||||
<div class="jumbotron">
|
||||
{% if user.profile.profile_pic %}
|
||||
<img src="/files/{{ user.profile.profile_pic }}" class="rounded float-left" style="margin-right: 24px; max-height: 100px;"/>
|
||||
<img src="/files/{{ user.profile.profile_pic }}" class="rounded float-left mr-4" style="max-height: 100px;"/>
|
||||
{% endif %}
|
||||
<h1>{% if user.verified %} <i class="fas fa-shield-check" alt="Verified"></i> {% endif %}{{ user.displayname }} <small class="text-muted">on Tweeder</small></h1>
|
||||
<h2>
|
||||
|
@ -21,6 +21,7 @@
|
|||
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-4 col-xl-4 mb-3">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<img src="/files/{{ user.profile.profile_pic }}" class="rounded mt-0 mr-1 img-fluid d-inline" style="max-height: 1.7rem;"/>
|
||||
<h4 style="display: inline">{{ user.displayname }}' Profile</h4>
|
||||
{% if following %}<form action="/unfollow/{{ user.displayname }}" method="POST" style="display: inline; float: right;"><input type="submit" value="Unfollow" class="btn btn-outline-danger btn-sm"/></form> {% else %}<form action="/follow/{{ user.displayname }}" method="POST" style="display:inline; float: right;"><input type="submit" value="Follow" class="btn btn-outline-primary btn-sm"/></form>{% endif %}
|
||||
</div>
|
||||
|
@ -38,7 +39,7 @@
|
|||
{% for post in posts if not post.hidden %}
|
||||
<div class="card" style="word-wrap: break-word; margin-bottom: 16px; width: 100%;">
|
||||
<div class="card-header">
|
||||
<b>{{ post.poster }}</b> at {{ post.timePosted.strftime('%Y-%m-%d %-H:%M') }}
|
||||
<b>{{ post.poster }}</b> at {{ post.timePosted.strftime('%Y-%m-%d %-H:%M') }} {% if post.edited %}<i>(Edited)</i>{% endif %}
|
||||
<span style="float: right">
|
||||
{% if logged_in|lower in post.likes %}
|
||||
<form style="display: inline;" method="POST" action="/unlike/{{ post._id }}"><button type="submit" class="btn btn-danger btn-sm"><i class="fas fa-heart"></i> {{ post.likes|count }}</button></form>
|
||||
|
@ -46,7 +47,10 @@
|
|||
<form style="display: inline;" method="POST" action="/like/{{ post._id }}"><button type="submit" class="btn btn-outline-danger btn-sm"><i class="fas fa-heart"></i> {{ post.likes|count }}</button></form>
|
||||
{% endif %}
|
||||
<a href="/reply/{{ post._id }}" class="btn btn-primary btn-sm"><i class="far fa-reply"></i></a>
|
||||
{% if logged_in == post.poster %}
|
||||
{% if logged_in|lower == post.poster|lower %}
|
||||
<a href="/editpost/{{ post._id }}" class="btn btn-primary btn-sm"><i class="far fa-edit"></i></a>
|
||||
{% endif %}
|
||||
{% if logged_in|lower == post.poster|lower %}
|
||||
<a href="/delete/{{ post._id }}" class="btn btn-danger btn-sm"><i class="far fa-trash-alt"></i></a>
|
||||
{% endif %}
|
||||
</span>
|
||||
|
|
Loading…
Add table
Reference in a new issue