def read(self, id): c.auth_for_update = self.authz.am_authorized(c, Action.CHANGE_STATE, System()) c.auth_for_delete = self.authz.am_authorized(c, Action.PURGE, System()) c.idea = Idea.by_name(id) if not c.idea: abort(404) return render('idea/read.html')
def delete_idea(idea_name): idea = Idea.by_name(idea_name) if not idea_name: abort(404) idea_tags = Session.query(IdeaTag) \ .filter(IdeaTag.idea_id==idea.id) \ .all() for idea_tag in idea_tags: idea_tag.delete() idea.delete() Session.commit()
def edit(self, id, data={}, errors={}, error_summary={}): c.auth_for_update = self.authorizer.am_authorized(c, Action.CHANGE_STATE, System()) if not c.auth_for_update: abort(401, _('Unauthorized to edit application')) c.idea = Idea.by_name(id) if c.idea is None: abort(404) data = c.idea.as_dict() data['tags'] = [t.tag.name for t in c.idea.tags] if request.method == 'POST' and not errors: try: data_dict = dict(request.params) idea = edit_idea(c.idea, data_dict) h.redirect_to(action='read', id=idea.name) except ValidationError, e: errors = e.error_dict error_summary = e.error_summary return self.edit(data_dict, errors, error_summary)
def delete_idea(idea_name): idea = Idea.by_name(idea_name) if not idea_name: abort(404) idea.delete() Session.commit()