예제 #1
0
파일: search.py 프로젝트: kultus/raggregate
def search(request):
    r = request
    ses = r.session
    try:
        sc = request.registry.solr_conn
    except AttributeError:
        r.session['message'] = 'I could not find the search engine.'
        return {'code': 'ENOSOLR', 'success': False}
    search_term = r.params['term']
    q = sc.query()
    for term in search_term.split():
        q = q.query(term)
    res = q.execute()
    stories = []
    vds = []
    vote_dict = {}
    for r in res:
        stories.append(submission.get_story_by_id(r['id']))
        if 'users.id' in ses:
            vds.append(users.get_user_votes_on_submission(ses['users.id'], r['id']))
    for vd in vds:
        if type(vd) == dict:
            vote_dict.update(vd)
    #queries.update_story_vote_tally(stories)
    return {'res': res, 'stories': stories, 'vote_dict': vote_dict}
예제 #2
0
def _assign_epistle_parent(e):
    #@TODO: REALLY need to put parent_info somewhere smarter, and/or not make this happen so much
    if e.parent:
        if e.parent_type == 'story':
            e.parent_info = submission.get_story_by_id(e.parent)
        elif e.parent_type == 'comment':
            e.parent_info = queries.get_comment_by_id(e.parent)
        elif e.parent_type == 'epistle' or e.parent_type == 'reply':
            e.parent_info = queries.get_epistle_by_id(e.parent)
    return e
예제 #3
0
def count_story_votes(submission_id):
    from raggregate.new_queries import submission
    dv_num = dbsession.query(Vote).filter(Vote.points < 0).filter(Vote.submission_id == submission_id).count()
    story = submission.get_story_by_id(submission_id)
    story.downvote_tally = dv_num
    story.downvote_tally_timestamp = now_in_utc()

    uv_num = dbsession.query(Vote).filter(Vote.points > 0).filter(Vote.submission_id == submission_id).count()
    story.upvote_tally = uv_num
    story.upvote_tally_timestamp = now_in_utc()

    story.total_vote_tally = uv_num + dv_num
    story.total_vote_timestamp = now_in_utc()

    dbsession.add(story)
    dbsession.flush()

    return [dv_num, uv_num]
예제 #4
0
def calc_hot_window_score(submission_id, hot_point_window = timedelta(hours = 6)):
    """
    Retrieve vote/score information for a given submission over hot_point_window time.
    Count votes received in the last hot_point_window time. If this is higher than normal,
    the story will be considered hot.

    @param submission_id: the submission to calculate
    @param hot_point_window: timedelta object representing acceptable vote timeframe from now
    """
    try:
        story_votes = dbsession.query(Vote.submission_id, func.sum(Vote.points).label('points')).filter(Vote.added_on < now_in_utc() and Vote.added_on > (now_in_utc() - hot_point_window)).filter(Vote.submission_id == submission_id).group_by(Vote.submission_id).one()
    except sqlalchemy.orm.exc.NoResultFound:
        # no votes on this story yet
        return 0
    from raggregate.new_queries import submission
    story = submission.get_story_by_id(submission_id)
    story.hot_window_score = story_votes.points
    story.hot_window_score_timestamp = now_in_utc()
    dbsession.add(story)
    return story_votes.points
예제 #5
0
파일: tests.py 프로젝트: kultus/raggregate
    def test_create_submission(self):
        #@TODO: another function that should be split out of the view for easy repitition.
        # if the view code changes substantially, this test will not keep up
        user = users.create_user(username = '******', password = '******')
        url = 'http://google.com'
        title = 'test'
        description = 'test'

        if url != '' and url is not None:
            url = queries.strip_all_html(url)
            if not re.match(r'http[s]*:\/\/', url):
                url = 'http://' + url
        else:
            # set to None so that NULL goes into the database
            url = None

        sub = Submission(title, description, url, user.id)
        self.dbsession.add(sub)
        self.dbsession.flush()
        s = submission.get_story_by_id(sub.id)
        self.assertEqual(s.id, sub.id)