def idea_vote(request): post_data = request.POST target = post_data.get('target') session = DBSession() idea = Idea.get_by_id(target) voter_username = authenticated_userid(request) voter = User.get_by_username(voter_username) if post_data.get('form.vote_hit'): vote = 'hit' idea.hits += 1 idea.author.hits += 1 voter.delivered_hits += 1 elif post_data.get('form.vote_miss'): vote = 'miss' idea.misses += 1 idea.author.misses += 1 voter.delivered_misses += 1 idea.voted_users.append(voter) session.flush() redirect_url = route_url('idea', request, idea_id=idea.idea_id) response = HTTPMovedPermanently(location=redirect_url) return response
def user_view(request): username = request.matchdict['username'] user = User.get_by_username(username) login_form = login_form_view(request) return { 'user': user, 'toolbar': toolbar_view(request), 'cloud': cloud_view(request), 'latest': latest_view(request), 'login_form': login_form, }
def user_view(request): username = request.matchdict['username'] user = User.get_by_username(username) login_form = login_form_view(request) return { 'user': user, 'toolbar': toolbar_view(request), 'cloud': cloud_view(request), 'latest': latest_view(request), 'login_form' :login_form, }
def user_view(request): username = request.matchdict["username"] user = User.get_by_username(username) login_form = login_form_view(request) return { "user": user, "toolbar": toolbar_view(request), "cloud": cloud_view(request), "latest": latest_view(request), "login_form": login_form, }
def idea_add(request): target = request.GET.get('target') session = DBSession() if target: target = Idea.get_by_id(target) if not target: return HTTPNotFound() kind = 'comment' else: kind = 'idea' form = Form(request, schema=AddIdeaSchema) if 'form.submitted' in request.POST and form.validate(): author_username = authenticated_userid(request) author = User.get_by_username(author_username) idea = Idea( target=target, author=author, title=form.data['title'], text=form.data['text'] ) tags = Tag.create_tags(form.data['tags']) if tags: idea.tags = tags session.add(idea) redirect_url = route_url('idea', request, idea_id=idea.idea_id) return HTTPFound(location=redirect_url) login_form = login_form_view(request) return { 'form': FormRenderer(form), 'toolbar': toolbar_view(request), 'cloud': cloud_view(request), 'latest': latest_view(request), 'login_form': login_form, 'target': target, 'kind': kind, }
def idea_add(request): target = request.GET.get('target') session = DBSession() if target: target = Idea.get_by_id(target, with_joinedload=False) if not target: return HTTPNotFound() kind = 'comment' else: kind = 'idea' form = Form(request, schema=AddIdeaSchema) if 'form.submitted' in request.POST and form.validate(): author_username = authenticated_userid(request) author = User.get_by_username(author_username) idea = Idea(target=target, author=author, title=form.data['title'], text=form.data['text']) tags = Tag.create_tags(form.data['tags']) if tags: idea.tags = tags session.add(idea) redirect_url = route_url('idea', request, idea_id=idea.idea_id) return HTTPFound(location=redirect_url) login_form = login_form_view(request) return { 'form': FormRenderer(form), 'toolbar': toolbar_view(request), 'cloud': cloud_view(request), 'latest': latest_view(request), 'login_form': login_form, 'target': target, 'kind': kind, }
def idea_add(request): target = request.params.get("target") session = DBSession() if target: target = Idea.get_by_id(target, with_joinedload=False) if not target: return HTTPNotFound() kind = "comment" else: kind = "idea" form = Form(request, schema=AddIdeaSchema) if "form.submitted" in request.POST and form.validate(): author_username = authenticated_userid(request) author = User.get_by_username(author_username) idea = Idea(target=target, author=author, title=form.data["title"], text=form.data["text"]) tags = Tag.create_tags(form.data["tags"]) if tags: idea.tags = tags session.add(idea) redirect_url = request.route_url("idea", idea_id=idea.idea_id) return HTTPFound(location=redirect_url) login_form = login_form_view(request) return { "form": FormRenderer(form), "toolbar": toolbar_view(request), "cloud": cloud_view(request), "latest": latest_view(request), "login_form": login_form, "target": target, "kind": kind, }
def idea_vote(request): post_data = request.POST target = post_data.get('target') session = DBSession() idea = Idea.get_by_id(target, with_joinedload=False) voter_username = authenticated_userid(request) voter = User.get_by_username(voter_username) redirect_url = route_url('idea', request, idea_id=idea.idea_id) response = HTTPMovedPermanently(location=redirect_url) if voter.user_id == idea.author_id: request.session.flash(u'You cannot vote on your own ideas.') return response if post_data.get('form.vote_hit'): idea.vote(voter, True) elif post_data.get('form.vote_miss'): idea.vote(voter, False) session.flush() return response
def idea_vote(request): post_data = request.POST target = post_data.get("target") session = DBSession() idea = Idea.get_by_id(target, with_joinedload=False) voter_username = authenticated_userid(request) voter = User.get_by_username(voter_username) redirect_url = request.route_url("idea", idea_id=idea.idea_id) response = HTTPMovedPermanently(location=redirect_url) if voter.user_id == idea.author_id: request.session.flash(u"You cannot vote on your own ideas.") return response if post_data.get("form.vote_hit"): idea.vote(voter, True) elif post_data.get("form.vote_miss"): idea.vote(voter, False) session.flush() return response
def test_getting_by_username(self): from shootout.models import User user = self._addUser() self.assertEqual(user, User.get_by_username(u'username'))