def remove_connection(request): auth_user = User.bid(request.authenticated_userid) assert auth_user, 'No user' conn_id = request.matchdict.get('conn_id') conn = DBSession.query(Connection).filter(Connection.id == conn_id, Connection.by_user_id == auth_user.id).first() assert conn, 'You are not authorized to perform this action' DBSession.delete(conn) DBSession.flush() return ''
def vote_to_answer(request): aid = request.POST.get('aid', -1) answer = DBSession.query(Answers).filter(Answers.id == aid).first() vote = DBSession.query(AnswerVotes).filter(AnswerVotes.answer_id == aid).filter( AnswerVotes.user_id == request.user.id).first() if vote is not None: DBSession.delete(vote) else: vote = AnswerVotes(answer=answer, user=request.user) DBSession.add(vote) vote_count = DBSession.query(func.count(AnswerVotes.id)).filter(AnswerVotes.answer_id == aid).scalar() return {'votes': vote_count}
def addto_track(request): qid = request.POST.get('qid', -1) question = DBSession.query(Questions).filter(Questions.id == qid).first() bookmark_ = (request.POST.get('type') == 'bookmark') existed = DBSession.query(Trackers).filter(Trackers.questions_id == qid).filter( Trackers.tracker_id == request.user.id, Trackers.is_bookmark == bookmark_).first() if existed: DBSession.delete(existed) return {'type': 'removed'} else: tracker = Trackers(tracker=request.user, question=question, is_bookmark=bookmark_) DBSession.add(tracker) return {'type': 'added'}
def delete_company(request): cid = int(request.matchdict.get('id', 0)) should_delete_users = request.matchdict.get('delete_users', '') == 'true' company = DBSession.query(BaseCompany).filter(BaseCompany.id == cid).first() resp = 'Deleted %s' % company.name if should_delete_users: resp += ' and users: ' deleted_usernames = [] for employee in company.employees: if should_delete_users: deleted_usernames.append(employee.nicename) DBSession.delete(employee) else: employee.company = None if should_delete_users: resp += ','.join(deleted_usernames) DBSession.delete(company) request.session.flash(resp) return HTTPFound('/')
def delete_unwanted_action(request): id = request.matchdict.get('id') unwanted_conn = DBSession.query(UnWanted).filter(UnWanted.id == int(id)).first() DBSession.delete(unwanted_conn) return HTTPFound(request.referer)
def tagmanager_delete(request): tag_id = request.matchdict.get('tag_id') tag = DBSession.query(Tag).filter(Tag.id == int(tag_id)).first() DBSession.delete(tag) return HTTPFound(request.referer)
def delete_profile(request): uid = int(request.matchdict.get('id', 0)) user = User.bid(uid) DBSession.delete(user) return HTTPFound('/')