コード例 #1
0
ファイル: test_epistle.py プロジェクト: sjuxax/raggregate
 def test_get_new_message_num(self):
     recipient = users.create_user(username="******", password="******")
     epistle = self.create_epistle(recipient=recipient)
     result = epistle_queries.get_new_message_num(recipient.id)
     assert result == 1
コード例 #2
0
def user_session_handler(event):
    s = event['request'].session
    r = event['request']
    e = event
    if 'message' in s:
        e['message'] = s['message']
    else:
        e['message'] = None

    e['template_filters'] = template_filters

    # this could be accessed by the request object, request.static_url()
    # should fixup the first here at least to be normal
    e['static_base'] = static_url("{0}/".format(r.registry.settings['template_static_asset']), r)
    e['static_url'] = static_url

    e['site_name'] = r.registry.settings['site.site_name']

    # export date fuzzing function to templates
    e['fuzzify_date'] = users.fuzzify_date

    e['new_message_num'] = None
    e['karma'] = None
    e['u'] = None
    e['logged_in_admin'] = None
    e['logged_in'] = False

    s['logged_in_admin'] = False

    e['followed_users'] = []

    if 'recent_comments.num' in r.registry.settings:
        e['recent_comments'] = submission.get_recent_comments(r.registry.settings['recent_comments.num'])
    else:
        # use ten as default if server parameter is missing
        e['recent_comments'] = submission.get_recent_comments(10)

    if 'sort' in r.params:
        e['sort'] = r.params['sort']
    else:
        e['sort'] = 'new'

    if 'logged_in' in s:
        #@TODO: implement caching/rate limiting so we don't perform this on every single request anymore
        num = epistle_queries.get_new_message_num(s['users.id'])
        if num == 0:
            s['new_message_num'] = None
            e['new_message_num'] = None
        else:
            s['new_message_num'] = num
            e['new_message_num'] = num
        #@TODO: another calculation that would benefit from caching
        #if 'karma' in s:
        #    e['karma'] = s['karma']
        #    print 'AAAAAAAAAA' + str(s['karma'])
        #else:
        #not caching right now, commenting conditional
        karma = users.get_user_by_id(s['users.id']).update_karma()
        s['karma'] = karma
        e['karma'] = karma

        if 'followed_users' in s and len(s['followed_users']) > 0:
            e['followed_users'] = s['followed_users']
        else:
            s['followed_users'] = users.get_followed_users(s['users.id'])
            e['followed_users'] = s['followed_users']

        u = users.get_user_by_id(s['users.id'])
        e['logged_in_admin'] = u.is_user_admin()
        s['logged_in_admin'] = e['logged_in_admin']
        e['u'] = u
        e['logged_in'] = True
    elif 'logged_in' not in s and r.registry.settings['user.generate_anon_accounts'] == 'true':
        # do not create a new user if we are on the login page
        # this simplifies anon -> permanent transfer
        if r.url.find('login') != -1:
            return
        # create a temporary user if this is a new session
        # all activity will be associated with this user until conversion to real account is performed
        u = User("{0}".format(uuid.UUID(bytes=os.urandom(16))), str(os.urandom(8)), real_name = "Unregistered User", temporary = True)
        dbsession.add(u)
        dbsession.flush()
        s['users.id'] = str(u.id)
        s['users.display_name'] = u.display_name()
        s['logged_in'] = True
        e['logged_in'] = True
コード例 #3
0
ファイル: test_epistle.py プロジェクト: azmikamis/raggregate
 def test_get_new_message_num(self):
     recipient = users.create_user(username = '******', password = '******')
     epistle = self.create_epistle(recipient = recipient)
     result = epistle_queries.get_new_message_num(recipient.id)
     assert result == 1