def clear(route_id): from app.helpers.route import RouteHelper assert isinstance(route_id, ObjectId) route = RouteHelper.get(route_id) assert route assert not route.finished for attach_id in route.attached: AttachmentHelper.delete(attach_id) while len(route.attached) > 0: route.attached.pop() route.save()
def delete_attach(route_id, attach_id): try: route_id = ObjectId(route_id) attach_id = ObjectId(attach_id) assert RouteHelper.get(route_id) assert AttachmentHelper.get(attach_id) assert not RouteHelper.get(route_id).finished except : flash('invalid route_id or attach_id') return redirect(url_for('home.home')) route = RouteHelper.get(route_id) if route.author != current_user.id: flash('you are not author of the route') return redirect(url_for('home.home')) AttachmentHelper.delete(attach_id) flash(u'删除成功') return redirect(url_for('route.add_attach_page', route_id=route.id))
def delete_route(route_id): assert isinstance(route_id, ObjectId) route = RouteHelper.get(route_id) assert route for attach_id in route.attached: AttachmentHelper.delete(attach_id) f_cate = Category.objects(id=route.father).first() f_cate.routes.remove(route.id) f_cate.save() enters = EnteredRoute.objects(route=route.id) for entered_route in enters: user = UserHelper.get(entered_route.user) user.entered_routes.remove(route.id) user.save() enters.delete() RateInfo.objects(route=route.id).delete() route.delete()