コード例 #1
0
            try:
                u = User.objects.get (handle = screen_name)
            except User.DoesNotExist:
                u = User (handle = screen_name)
            u.twitter_access_key = tw_access
            u.twitter_secret_key = tw_secret
            u.save ()
            print login_user (u, remember = "yes") 

        return redirect ("/")


class Logout (MethodView):

    def get (self):
        logout_user ()
        return redirect ("/")


class Login (MethodView):

    def get (self):
        return render_template ("login.jade", **locals())


app.add_url_rule ('/auth/twitter', view_func = TwitterAuth.as_view ('twitterauth'))
app.add_url_rule ('/auth/callback', view_func = TwitterCallback.as_view ('twittercallback'))
app.add_url_rule ('/auth/logout', view_func = Logout.as_view ('logout'))
app.add_url_rule ('/auth/login', view_func = Login.as_view ('login'))

コード例 #2
0
ファイル: album.py プロジェクト: pleomax00/flask-mongo-skel
"""
@date Thu Nov  1 16:14:48 IST 2012

Shows user /album/handle page
"""

from fallenthrone import app
from flask import render_template, request
from flask.views import MethodView
from fallenthrone.models import User, CacheData
from flask_login import *

from fallenthrone.lib.tweetparser import TweetParser
import sys

class Album (MethodView):

    def read_images (self, handle):
        tparser = TweetParser (app.config['TWITTER_CONSUMER_KEY'], app.config['TWITTER_CONSUMER_SECRET'], current_user.twitter_access_key, current_user.twitter_secret_key)
        images = tparser.parse (handle)
        return images

    def get (self, handle):
        images = self.read_images (handle)
        #images = CacheData.getset ("images", current_user.handle + ":" + handle, self.read_images, [handle])
        print images
        return render_template ('album.jade', **locals ())

app.add_url_rule ('/album/<handle>', view_func = Album.as_view ('album'))
コード例 #3
0
from flask_login import *

from fallenthrone.lib.tweetparser import TweetParser
import sys

class Index (MethodView):

    def read_friends (self):
        tparser = TweetParser (app.config['TWITTER_CONSUMER_KEY'], app.config['TWITTER_CONSUMER_SECRET'], current_user.twitter_access_key, current_user.twitter_secret_key)
        friends = tparser.following ()
        max_display_in_row = 10
        grouped = []
        temp = []
        for f in friends:
            if len (temp) == max_display_in_row:
                grouped.append (temp)
                temp = []
            temp.append (f)
        grouped.append (temp)
        return grouped

    @login_required
    def get (self):
        """ Serves GET method """
        # Lets read user's tweets
        grouped = CacheData.getset ("friends", current_user.handle, self.read_friends, [])
        return render_template ('index.jade', **locals ())

app.add_url_rule ('/', view_func = Index.as_view ('index'))