Delete Article Button in Tutorial Multi-User Applications with Anvil

What I’m trying to do:
I passed tutorials Storing News in a Database and then Multi-User Applications with Anvil

What I’ve tried and what’s not working:
When I click Delete Article button pop up appears
but
when i click NO, the article gets deleted anyway!
I’ve checked my code - its all copied from tutorials
Can you help me?

Clone link:
share a copy of your app
https://anvil.works/build#clone:RMGPNMWU6K7B6NEN=HECU2NXWCYCWNKWCYOHG6XS5

Hi guys
I have a problem with tutorial with Delete article button.
When i click Delete article button Alert pop up appears BUT when i click NO, the article gets deleted anyway!
I’ve double checked my code
Homepage:
def delete_article(self, article, **event_args):
# Delete the article
anvil.server.call(‘delete_article’, article)
self.refresh_articles()
ArticleView
def delete_article_button_click(self, **event_args):
“”“This method is called when the button is clicked”""
confirm(“Are you sure you want to delete {}?”.format(self.item[‘title’]))
self.parent.raise_event(‘x-delete-article’, article=self.item)
ArticleServerModule
@anvil.server.callable
def delete_article(article):
if verify_user_permission(article):
# Delete the article
article.delete()
else:
# Raise an exception if the article doesn’t exist in the Data Table
# or the user doesn’t own the article being deleted
raise Exception(“Article does not exist or does not belong to this user”)

Your answer is further up that thread. You call confirm, but do not use it in an if statement, so your event is raised no matter what.

2 Likes

@k_l_b_1963 Please only post your question in one place. Or, at least please link back to related discussions so people trying to help don’t end up duplicating the work of others.

2 Likes

Thanks a lot for you help!

Ok, now I better understood how the system works :grinning:

1 Like

Another quick forum tip: You can mark his response as the Solution to your question by clicking that button beneath his post.

Welcome!