Added post deletion
Users can delete their own posts, and all users except user who have the post archived will also no longer see the post.
This commit is contained in:
parent
09ab33aeed
commit
7699955f87
|
@ -153,6 +153,13 @@ def archive_remove_user(post_user, post_id):
|
|||
flash(_('You have removed %(username)s post from your archive!', username=post_user))
|
||||
return redirect(url_for('main.view_archive', username=current_user.username))
|
||||
|
||||
@bp.route('/delete/<post_id>')
|
||||
@login_required
|
||||
def delete(post_id):
|
||||
current_user.delete_post(post_id)
|
||||
db.session.commit()
|
||||
flash(_('You have delete your post!'))
|
||||
return redirect(url_for('main.index'))
|
||||
|
||||
@bp.route('/follow/<username>', methods=['POST'])
|
||||
@login_required
|
||||
|
|
|
@ -141,6 +141,9 @@ class User(UserMixin, PaginatedAPIMixin, db.Model):
|
|||
db.session.add(a)
|
||||
print("Archived!")
|
||||
|
||||
def delete_post(self, post_id):
|
||||
return self.posts.filter_by(id=post_id).delete()
|
||||
|
||||
def archive_remove(self, post_id):
|
||||
self.archived.filter_by(id=post_id).delete()
|
||||
print("Removed Archive!")
|
||||
|
|
|
@ -36,6 +36,9 @@
|
|||
<a href="{{ url_for('main.archive_remove', post_user=post.author.username, post_id=post.id) }}">Remove from Archive</a>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% if post.author.username == current_user.username %}
|
||||
<a href="{{ url_for('main.delete', post_id=post.id) }}">Delete</a>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
|
Loading…
Reference in New Issue