Ejemplo n.º 1
0
def thread_details(thread_id):
    if not thread_id.isdigit():
        try:
            thread_id = base62_decode(thread_id)
        except:
            return redirect('/')

    form = NewPostForm(get_form_from_session())

    thread = Thread.get(thread_id)

    channel_list = {
        'posts': posts.get_channel_key(posts.get_key(thread_id=thread_id)),
        'participants':
        users.get_channel_key(users.get_key(thread_id=thread_id)),
        'active_thread_list': threads.get_channel_key(threads.get_key()),
    }

    if thread['link'] in schedule:
        pycon_session = schedule[thread['link']]
    else:
        pycon_session = False

    if 'auth' in session:
        my_threads = Thread.list_by_author(
            author_id=session['auth']['user_id'])[:5]
        channel_list['my_thread_list'] = threads.get_channel_key(
            threads.get_key(author_id=thread_id))
    else:
        my_threads = []

    post_list = Post.list_by_thread(thread_id)[::-1]
    if 'auth' in session:
        current_user = User.get_by_id(session['auth']['user_id'])
    else:
        current_user = None

    return render_template(
        'threads/details.html', **{
            'thread': thread,
            'form': form,
            'pycon_session': pycon_session,
            'participant_list': User.list_by_thread(thread_id) or [],
            'my_thread_list': my_threads,
            'active_thread_list': Thread.list(limit=10),
            'post_list': post_list,
            'channel_list': channel_list,
            'realtime_host': app.config.get('REALTIME_HOST'),
            'current_user': current_user,
            'do_troll': app.config.get('DING_ENABLED', False)
        })
Ejemplo n.º 2
0
def thread_details(thread_id):
    if not thread_id.isdigit():
        try:
            thread_id = base62_decode(thread_id)
        except:
            return redirect('/')

    form = NewPostForm(get_form_from_session())

    thread = Thread.get(thread_id)

    channel_list = {
        'posts': posts.get_channel_key(posts.get_key(thread_id=thread_id)),
        'participants': users.get_channel_key(users.get_key(thread_id=thread_id)),
        'active_thread_list': threads.get_channel_key(threads.get_key()),
    }

    if thread['link'] in schedule:
        pycon_session = schedule[thread['link']]
    else:
        pycon_session = False

    if 'auth' in session:
        my_threads = Thread.list_by_author(author_id=session['auth']['user_id'])[:5]
        channel_list['my_thread_list'] = threads.get_channel_key(threads.get_key(author_id=thread_id))
    else:
        my_threads = []

    post_list = Post.list_by_thread(thread_id)[::-1]
    if 'auth' in session:
        current_user = User.get_by_id(session['auth']['user_id'])
    else:
        current_user = None

    return render_template('threads/details.html', **{
        'thread': thread,
        'form': form,
        'pycon_session': pycon_session,
        'participant_list': User.list_by_thread(thread_id) or [],
        'my_thread_list': my_threads,
        'active_thread_list': Thread.list(limit=10),
        'post_list': post_list,
        'channel_list': channel_list,
        'realtime_host': app.config.get('REALTIME_HOST'),
        'current_user': current_user,
        'do_troll': app.config.get('DING_ENABLED', False)
    })
Ejemplo n.º 3
0
def oauth_callback():
    from channels.models import User

    code = request.args.get('code')
    error = request.args.get('error')
    if error or not code:
        # TODO: show error
        return redirect('/?oauth_error=' + error)

    req = urllib2.Request('https://disqus.com/api/oauth/2.0/access_token/', urllib.urlencode({
        'grant_type': 'authorization_code',
        'client_id': disqusapi.public_key,
        'client_secret': disqusapi.secret_key,
        'redirect_uri': url_for('oauth_callback', _external=True),
        'code': code,
    }))

    try:
        resp = urllib2.urlopen(req).read()
    except Exception:
        return redirect('/oauth/error/')

    data = simplejson.loads(resp)

    session['auth'] = data
    session.permanent = True

    user = api_call(disqusapi.users.details, user=data['user_id'])
    User.save(user)

    if 'postauth' in session:
        url = session['postauth']['url']
        del session['postauth']
    else:
        url = '/'
    return redirect(url)