Ejemplo n.º 1
0
def main_view(request):
    hitpct = Idea.ideas_bunch(Idea.hit_percentage.desc())
    top = Idea.ideas_bunch(Idea.hits.desc())
    bottom = Idea.ideas_bunch(Idea.misses.desc())
    last10 = Idea.ideas_bunch(Idea.idea_id.desc())

    toplists = [
        {
            'title': 'Latest shots',
            'items': last10
        },
        {
            'title': 'Most hits',
            'items': top
        },
        {
            'title': 'Most misses',
            'items': bottom
        },
        {
            'title': 'Best performance',
            'items': hitpct
        },
    ]

    login_form = login_form_view(request)

    return {
        'username': authenticated_userid(request),
        'toolbar': toolbar_view(request),
        'cloud': cloud_view(request),
        'latest': latest_view(request),
        'login_form': login_form,
        'toplists': toplists,
    }
Ejemplo n.º 2
0
    def test_add_idea(self):
        from shootout.models import Idea
        user = self._addUser()
        idea = Idea(
            author=user,
            title=u'Foo',
            text=u'Lorem ipsum dolor sit amet',
        )
        self.session.flush()

        idea = self.session.query(Idea).filter(Idea.title == u'Foo')
        idea = idea.first()

        self.assertEqual(idea.comments, [])
        self.assertEqual(idea.author.user_id, user.user_id)
        self.assertEqual(idea.author.username, u'username')
        self.assertEqual(idea.title, u'Foo')
        self.assertEqual(idea.text, u'Lorem ipsum dolor sit amet')
        self.assertEqual(idea.hits, 0)
        self.assertEqual(idea.misses, 0)
        self.assertEqual(idea.tags, [])
        self.assertEqual(idea.voted_users.all(), [])
        self.assertEqual(idea.hit_percentage, 0)
        self.assertEqual(idea.total_votes, 0)
        self.assertEqual(idea.vote_differential, 0)
Ejemplo n.º 3
0
    def test_add_idea(self):
        from shootout.models import Idea
        user = self._addUser()
        idea = Idea(
            author=user,
            title=u'Foo',
            text=u'Lorem ipsum dolor sit amet',
        )
        self.session.flush()

        idea = self.session.query(Idea).filter(Idea.title == u'Foo')
        idea = idea.first()

        self.assertEqual(idea.comments, [])
        self.assertEqual(idea.author.user_id, user.user_id)
        self.assertEqual(idea.author.username, u'username')
        self.assertEqual(idea.title, u'Foo')
        self.assertEqual(idea.text, u'Lorem ipsum dolor sit amet')
        self.assertEqual(idea.hits, 0)
        self.assertEqual(idea.misses, 0)
        self.assertEqual(idea.tags, [])
        self.assertEqual(idea.voted_users.all(), [])
        self.assertEqual(idea.hit_percentage, 0)
        self.assertEqual(idea.total_votes, 0)
        self.assertEqual(idea.vote_differential, 0)
Ejemplo n.º 4
0
    def test_ideas_bunch(self):
        from shootout.models import Idea

        user = self._addUser()
        idea1 = self._addIdea(user=user)
        idea2 = self._addIdea(user=user, title=u"title3")
        idea3 = self._addIdea(user=user, title=u"title4")
        idea4 = self._addIdea(user=user, title=u"title2")

        self.assertEqual(Idea.ideas_bunch(Idea.idea_id), [idea1, idea2, idea3, idea4])
        self.assertEqual(Idea.ideas_bunch(Idea.idea_id, 2), [idea1, idea2])
        self.assertEqual(Idea.ideas_bunch(Idea.title), [idea1, idea4, idea2, idea3])
Ejemplo n.º 5
0
    def test_ideas_bunch(self):
        from shootout.models import Idea
        user = self._addUser()
        idea1 = self._addIdea(user=user)
        idea2 = self._addIdea(user=user, title=u'title3')
        idea3 = self._addIdea(user=user, title=u'title4')
        idea4 = self._addIdea(user=user, title=u'title2')

        self.assertEqual(Idea.ideas_bunch(Idea.idea_id),
                         [idea1, idea2, idea3, idea4])
        self.assertEqual(Idea.ideas_bunch(Idea.idea_id, 2), [idea1, idea2])
        self.assertEqual(Idea.ideas_bunch(Idea.title),
                         [idea1, idea4, idea2, idea3])
Ejemplo n.º 6
0
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
Ejemplo n.º 7
0
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
Ejemplo n.º 8
0
 def _addIdea(self, target=None, user=None):
     from shootout.models import Idea
     if not user:
         user = self._addUser()
     idea = Idea(target=target, author=user, title=u'title', text=u'text')
     self.session.add(idea)
     self.session.flush()
     return idea
Ejemplo n.º 9
0
    def test_idea_vote(self):
        self.login()
        self.add_idea()
        from shootout.models import Idea

        q = Idea.get_by_tagname("tag1")
        target = q.one().idea_id
        self.testapp.post("/idea_vote", {"target": target}, status=301)
Ejemplo n.º 10
0
 def test_add_idea(self):
     self.login()
     self.add_idea()
     from shootout.models import Idea
     q = Idea.get_by_tagname('tag1')
     results = q.all()
     self.assertEqual(len(results), 1)
     idea = results[0]
     self.assertEqual(idea.title, 'title')
Ejemplo n.º 11
0
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,
    }
Ejemplo n.º 12
0
    def test_add_idea(self):
        self.login()
        self.add_idea()
        from shootout.models import Idea

        q = Idea.get_by_tagname("tag1")
        results = q.all()
        self.assertEqual(len(results), 1)
        idea = results[0]
        self.assertEqual(idea.title, "title")
Ejemplo n.º 13
0
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,
    }
Ejemplo n.º 14
0
 def test_idea_vote(self):
     self.login()
     self.add_idea()
     from shootout.models import Idea
     q = Idea.get_by_tagname('tag1')
     target = q.one().idea_id
     self.testapp.post(
         '/idea_vote',
         {'target': target},
         status=301,
     )
Ejemplo n.º 15
0
def tag_view(request):
    tagname = request.matchdict["tag_name"]
    ideas = Idea.get_by_tagname(tagname)
    login_form = login_form_view(request)
    return {
        "tag": tagname,
        "toolbar": toolbar_view(request),
        "cloud": cloud_view(request),
        "latest": latest_view(request),
        "login_form": login_form,
        "ideas": ideas,
    }
Ejemplo n.º 16
0
def tag_view(request):
    tagname = request.matchdict['tag_name']
    ideas = Idea.get_by_tagname(tagname)
    login_form = login_form_view(request)
    return {
        'tag': tagname,
        'toolbar': toolbar_view(request),
        'cloud': cloud_view(request),
        'latest': latest_view(request),
        'login_form': login_form,
        'ideas': ideas,
    }
Ejemplo n.º 17
0
def tag_view(request):
    tagname = request.matchdict['tag_name']
    ideas = Idea.get_by_tagname(tagname)
    login_form = login_form_view(request)
    return {
        'tag': tagname,
        'toolbar': toolbar_view(request),
        'cloud': cloud_view(request),
        'latest': latest_view(request),
        'login_form': login_form,
        'ideas': ideas,
    }
Ejemplo n.º 18
0
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,
    }
Ejemplo n.º 19
0
def main_view(request):
    hitpct = Idea.ideas_bunch(Idea.hit_percentage.desc())
    top = Idea.ideas_bunch(Idea.hits.desc())
    bottom = Idea.ideas_bunch(Idea.misses.desc())
    last10 = Idea.ideas_bunch(Idea.idea_id.desc())

    toplists = [
        {"title": "Latest shots", "items": last10},
        {"title": "Most hits", "items": top},
        {"title": "Most misses", "items": bottom},
        {"title": "Best performance", "items": hitpct},
    ]

    login_form = login_form_view(request)

    return {
        "username": authenticated_userid(request),
        "toolbar": toolbar_view(request),
        "cloud": cloud_view(request),
        "latest": latest_view(request),
        "login_form": login_form,
        "toplists": toplists,
    }
Ejemplo n.º 20
0
def main_view(request):
    hitpct = Idea.ideas_bunch(Idea.hit_percentage.desc())
    top = Idea.ideas_bunch(Idea.hits.desc())
    bottom = Idea.ideas_bunch(Idea.misses.desc())
    last10 = Idea.ideas_bunch(Idea.idea_id.desc())
    
    toplists = [
        {'title': 'Latest shots', 'items': last10},
        {'title': 'Most hits', 'items': top},
        {'title': 'Most misses', 'items': bottom},
        {'title': 'Best performance', 'items': hitpct},
    ]

    login_form = login_form_view(request)
    
    return {
        'username': authenticated_userid(request),
        'toolbar': toolbar_view(request),
        'cloud': cloud_view(request),
        'latest': latest_view(request),
        'login_form': login_form,
        'toplists': toplists,
    }
Ejemplo n.º 21
0
def idea_view(request):
    idea_id = request.matchdict['idea_id']
    idea = Idea.get_by_id(idea_id)

    viewer_username = authenticated_userid(request)
    voted = idea.user_voted(viewer_username)
    login_form = login_form_view(request)

    return {
        'toolbar': toolbar_view(request),
        'cloud': cloud_view(request),
        'latest': latest_view(request),
        'login_form': login_form,
        'voted': voted,
        'viewer_username': viewer_username,
        'idea': idea,
    }
Ejemplo n.º 22
0
def idea_view(request):
    idea_id = request.matchdict['idea_id']
    idea = Idea.get_by_id(idea_id)

    viewer_username = authenticated_userid(request)
    voted = idea.user_voted(viewer_username)
    login_form = login_form_view(request)

    return {
        'toolbar': toolbar_view(request),
        'cloud': cloud_view(request),
        'latest': latest_view(request),
        'login_form': login_form,
        'voted': voted,
        'viewer_username': viewer_username,
        'idea': idea,
    }
Ejemplo n.º 23
0
def idea_view(request):
    idea_id = request.matchdict["idea_id"]
    idea = Idea.get_by_id(idea_id)

    viewer_username = authenticated_userid(request)
    voted = idea.user_voted(viewer_username)
    login_form = login_form_view(request)

    return {
        "toolbar": toolbar_view(request),
        "cloud": cloud_view(request),
        "latest": latest_view(request),
        "login_form": login_form,
        "voted": voted,
        "viewer_username": viewer_username,
        "idea": idea,
    }
Ejemplo n.º 24
0
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
Ejemplo n.º 25
0
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
Ejemplo n.º 26
0
def latest_view(request):
    latest = Idea.ideas_bunch(Idea.idea_id.desc(), with_joinedload=False)
    return render('templates/latest.pt', {'latest': latest}, request)
Ejemplo n.º 27
0
def latest_view(request):
    latest = Idea.ideas_bunch(Idea.idea_id.desc(), with_joinedload=False)
    return render("templates/latest.pt", {"latest": latest}, request)
Ejemplo n.º 28
0
def latest_view(request):
    latest = Idea.ideas_bunch(Idea.idea_id.desc())
    return render('templates/latest.pt', {'latest': latest}, request)
Ejemplo n.º 29
0
 def test_get_by_id(self):
     from shootout.models import Idea
     idea = self._addIdea()
     queried_idea = Idea.get_by_id(idea.idea_id)
     self.assertEqual(idea, queried_idea)
Ejemplo n.º 30
0
def latest_view(request):
    latest = Idea.ideas_bunch(Idea.idea_id.desc())
    return render('templates/latest.pt', {'latest': latest}, request)
Ejemplo n.º 31
0
 def test_get_by_id(self):
     from shootout.models import Idea
     idea = self._addIdea()
     queried_idea = Idea.get_by_id(idea.idea_id)
     self.assertEqual(idea, queried_idea)