Remove Archived posts
Added ability to remove a archived post if it is already archived by the current user.
This commit is contained in:
parent
d3bfb13dbf
commit
caf54c8b75
|
@ -108,14 +108,21 @@ def edit_profile():
|
|||
return render_template('edit_profile.html', title=_('Edit Profile'),
|
||||
form=form)
|
||||
|
||||
#
|
||||
@bp.route('/archive/<post_b>/<post_user>/<post_time>')
|
||||
@bp.route('/archive/<post_id>/<post_b>/<post_user>/<post_time>')
|
||||
@login_required
|
||||
def archive(post_b, post_user, post_time):
|
||||
current_user.archive(post_b, post_user, post_time)
|
||||
def archive(post_id, post_b, post_user, post_time):
|
||||
current_user.archive(post_id, post_b, post_user, post_time)
|
||||
db.session.commit()
|
||||
flash(_('You have archived %(username)s post!', username=post_user))
|
||||
return redirect(url_for('main.index'))
|
||||
return redirect(url_for('main.explore'))
|
||||
|
||||
@bp.route('/archive/<post_user>/<post_id>')
|
||||
@login_required
|
||||
def archive_remove(post_user, post_id):
|
||||
current_user.archive_remove(post_id)
|
||||
db.session.commit()
|
||||
flash(_('You have removed %(username)s post from your archive!', username=post_user))
|
||||
return redirect(url_for('main.explore'))
|
||||
|
||||
|
||||
@bp.route('/follow/<username>', methods=['POST'])
|
||||
|
|
|
@ -97,7 +97,7 @@ class User(UserMixin, PaginatedAPIMixin, db.Model):
|
|||
password_hash = db.Column(db.String(128))
|
||||
posts = db.relationship('Post', backref='author', lazy='dynamic')
|
||||
# link archive class to user
|
||||
archive = db.relationship('Archive', backref='archivee', lazy='dynamic')
|
||||
archived = db.relationship('Archive', backref='archivee', lazy='dynamic')
|
||||
about_me = db.Column(db.String(140))
|
||||
last_seen = db.Column(db.DateTime, default=datetime.utcnow)
|
||||
token = db.Column(db.String(32), index=True, unique=True)
|
||||
|
@ -133,10 +133,17 @@ class User(UserMixin, PaginatedAPIMixin, db.Model):
|
|||
digest, size)
|
||||
|
||||
# Create new achive entry
|
||||
def archive(self, post_body, post_user, post_time):
|
||||
a = Archive(body=post_body, author=post_user, archived_by=self.id)
|
||||
def archive(self, post_id, post_body, post_user, post_time):
|
||||
a = Archive(id=post_id, body=post_body, author=post_user, archived_by=self.id)
|
||||
db.session.add(a)
|
||||
print("Archived!")
|
||||
|
||||
def archive_remove(self, post_id):
|
||||
self.archived.filter_by(id=post_id).delete()
|
||||
print("Removed Archive!")
|
||||
|
||||
def has_archived_post(self, post_id):
|
||||
return Archive.query.filter_by(id=post_id).count() > 0
|
||||
|
||||
def follow(self, user):
|
||||
if not self.is_following(user):
|
||||
|
|
|
@ -30,7 +30,11 @@
|
|||
</span>
|
||||
{% endif %}
|
||||
{% if post.author.username != current_user.username %}
|
||||
<a href="{{ url_for('main.archive', post_b=post.body, post_user=post.author.username, post_time=post.timestamp) }}">Archive</a>
|
||||
{% if not current_user.has_archived_post(post.id) %}
|
||||
<a href="{{ url_for('main.archive', post_id=post.id, post_b=post.body, post_user=post.author.username, post_time=post.timestamp) }}">Archive</a>
|
||||
{% else %}
|
||||
<a href="{{ url_for('main.archive_remove', post_user=post.author.username, post_id=post.id) }}">Remove from Archive</a>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
{% if user != current_user %}
|
||||
<p><a href="{{ url_for('main.send_message', recipient=user.username) }}">{{ _('Send private message') }}</a></p>
|
||||
{% endif %}
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
|
Loading…
Reference in New Issue