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'),
|
return render_template('edit_profile.html', title=_('Edit Profile'),
|
||||||
form=form)
|
form=form)
|
||||||
|
|
||||||
#
|
@bp.route('/archive/<post_id>/<post_b>/<post_user>/<post_time>')
|
||||||
@bp.route('/archive/<post_b>/<post_user>/<post_time>')
|
|
||||||
@login_required
|
@login_required
|
||||||
def archive(post_b, post_user, post_time):
|
def archive(post_id, post_b, post_user, post_time):
|
||||||
current_user.archive(post_b, post_user, post_time)
|
current_user.archive(post_id, post_b, post_user, post_time)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
flash(_('You have archived %(username)s post!', username=post_user))
|
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'])
|
@bp.route('/follow/<username>', methods=['POST'])
|
||||||
|
|
|
@ -97,7 +97,7 @@ class User(UserMixin, PaginatedAPIMixin, db.Model):
|
||||||
password_hash = db.Column(db.String(128))
|
password_hash = db.Column(db.String(128))
|
||||||
posts = db.relationship('Post', backref='author', lazy='dynamic')
|
posts = db.relationship('Post', backref='author', lazy='dynamic')
|
||||||
# link archive class to user
|
# 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))
|
about_me = db.Column(db.String(140))
|
||||||
last_seen = db.Column(db.DateTime, default=datetime.utcnow)
|
last_seen = db.Column(db.DateTime, default=datetime.utcnow)
|
||||||
token = db.Column(db.String(32), index=True, unique=True)
|
token = db.Column(db.String(32), index=True, unique=True)
|
||||||
|
@ -133,11 +133,18 @@ class User(UserMixin, PaginatedAPIMixin, db.Model):
|
||||||
digest, size)
|
digest, size)
|
||||||
|
|
||||||
# Create new achive entry
|
# Create new achive entry
|
||||||
def archive(self, post_body, post_user, post_time):
|
def archive(self, post_id, post_body, post_user, post_time):
|
||||||
a = Archive(body=post_body, author=post_user, archived_by=self.id)
|
a = Archive(id=post_id, body=post_body, author=post_user, archived_by=self.id)
|
||||||
db.session.add(a)
|
db.session.add(a)
|
||||||
print("Archived!")
|
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):
|
def follow(self, user):
|
||||||
if not self.is_following(user):
|
if not self.is_following(user):
|
||||||
self.followed.append(user)
|
self.followed.append(user)
|
||||||
|
|
|
@ -30,7 +30,11 @@
|
||||||
</span>
|
</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if post.author.username != current_user.username %}
|
{% 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 %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
{% if user != current_user %}
|
{% if user != current_user %}
|
||||||
<p><a href="{{ url_for('main.send_message', recipient=user.username) }}">{{ _('Send private message') }}</a></p>
|
<p><a href="{{ url_for('main.send_message', recipient=user.username) }}">{{ _('Send private message') }}</a></p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
Loading…
Reference in New Issue