def delete_folder(id=None): deletefolderform = DeleteAssetFolderForm(prefix="deletefolderform") folder = AssetFolder.query.get(id) if not folder.owner == current_user.profile: logger.debug("Not deleting folder for other person") abort(403) if folder.parent is None: logger.debug("Can't delete top folder") abort(403) if deletefolderform.validate_on_submit(): logger.debug("Delete an empty folder") parent_id = folder.parent.id if str(folder.id) != deletefolderform.id.data: logger.debug(f"Wrong ids specified {folder.id} " f"and {deletefolderform.id.data}") abort(403) if folder.files: logger.debug("Folder contains files") abort(403) session.delete(folder) session.commit() return redirect(url_for('userassets.index', folder_id=parent_id)) return redirect(url_for('userassets.index', folder_id=id))
def api_invite_delete(id): invite = Invite.query.get(id) if current_user.profile.id != invite.owner_id: abort(403) session.delete(invite) session.commit() return jsonify({'html': 'Deleted'})
def delete_course(category_id, course_id): try: course = session.query(Course).filter_by( id=course_id, category_id=category_id).one() except: return error_message(404, "Cannot delete: Course not found.") session.delete(course) session.commit() return data_message(200, None, "Course was successfully deleted.")
def delete_category(category_id): try: category = session.query(Category).filter_by(id=category_id).one() except: return error_message(404, "Cannot delete: Category not found.") session.query(Course).filter_by(category_id=category_id).delete() session.delete(category) session.commit() return data_message(200, None, "Category and sub-courses was successfully deleted.")
def delete(fileid, filename): logger.debug("Delete asset") asset = Asset.query.get(fileid) form = DeleteAssetForm(prefix="deleteasset") if form.validate_on_submit(): if asset.owner != current_user.profile: abort(403) flash("You just deleted an asset") session.delete(asset) session.commit() return redirect(url_for('userassets.index', folder_id=asset.folder_id))
def delete(id: int): """Delete a character.""" character = get_character(id, check_author=True) if current_user.profile.id != character.user_id: abort(404) form = DeleteForm() if form.validate_on_submit(): session.delete(character) session.commit() return redirect(url_for('character.index')) form.character_id.data = character.id return render_template('character/delete_character.html.jinja', form=form, character=character)
def remove_npc(id: int, characterid: int): npc = NPC.query.get(characterid) form = RemoveCharacterForm() if form.validate_on_submit(): if npc.campaign.id == id: session.delete(npc) session.commit() return redirect(url_for('campaign.view', id=id)) form.id.data = npc.campaign.id form.character.data = npc.character.id return render_template('campaign/removecharacter.html.jinja', character=npc.character, campaign=npc.campaign, form=form)
def manage_npc(id: int, npcid: int): npc = NPC.query.get(npcid) transferform = NPCTransferForm(prefix="npctransfer", npc_id=npcid) if npc is None: return abort(404) if npc.campaign_id != id: return abort(404) if current_user.profile != npc.campaign.user: return abort(404) if transferform.submit.data: if transferform.validate_on_submit(): player = UserProfile.query.get(transferform.player.data) campaign = npc.campaign # Create a copy of the character new_character = Character(title=npc.character.title, body=npc.character.body, user_id=player.id) session.add(new_character) # Add the character to the campaign campaign.characters.append(new_character) # Remove the NPC session.delete(npc) # Commit changes session.commit() return redirect(url_for('campaign.view', id=campaign.id)) transferform.player.choices = [(p.id, p.user.username) for p in npc.campaign.players] return render_template('campaign/managenpc.html.jinja', npc=npc, transferform=transferform)
def invite_delete(id): invite = Invite.query.get(id) if current_user.profile.id != invite.owner_id: logger.debug("Wrong user") abort(403) form = DeleteInviteForm() if form.validate_on_submit(): logger.debug("Delete form validated") session.delete(invite) session.commit() return redirect('/') objclass = get_class_by_tablename(invite.table) obj = None if objclass is not None: obj = objclass.query.get(invite.object_id) form.id.data = invite.id return render_template('main/invite_delete.html.jinja', obj=obj, invite=invite, form=form)