コード例 #1
0
 def get_by_id_str(cls, id_str):
     media = None
     if isinstance(id_str, tuple):
         media = db.query(Media).filter_by(id_str=id_str[1]).first()
     elif isinstance(id_str, basestring):
         media = db.query(Media).filter_by(id_str=id_str).first()
     return media
コード例 #2
0
def before_request():
    session.permanent = True
    g.user = None
    #db.commit()

    if 'id_int' in session:
        g.user = db.query(User).get(session['id_int'])
コード例 #3
0
    def register_google(cls, response):
        access_token = response.get(u"access_token", None)
        if not access_token:
            return {u"ok": False, u"msg": u"Google 로그인에 실패했습니다."}

        r = GoogleAPI(access_token=access_token).fetch()

        if r.status != 200:
            return {u"ok": False, u"msg": u"개인 정보를 불러오는 데 실패했습니다."}

        data = r.data
        user_email = data.get("email")
        user_data = db.query(User).filter_by(email=user_email).first()
        if user_data:
            return {u"ok": True, u"user": user_data, u"created": False}

        user_id = user_email.split("@")[0]
        user_pw = md5("%s%s%s" % ("go", user_id, "google")).hexdigest()[:20]
        user_pic = data.get("picture")

        created_user = User(id_str=user_email.split("@")[0], email=user_email, password=user_pw, picture=user_pic)
        db.add(created_user)
        db.commit()

        created_feed = NewsFeed(
            news_type=(3,), data={u"user": {u"picture": user_pic, u"id_int": created_user.id_int, u"id_str": user_id}}
        )

        db.add(created_feed)
        db.commit()

        return {u"ok": True, u"user": created_user, u"created": True}
コード例 #4
0
    def get_newsfeed_old(cls, id_int):
        news_feed = db.query(NewsFeed).order_by(NewsFeed.id_int.desc())
        if id_int > 0:
            news_feed = news_feed.filter(NewsFeed.id_int < id_int)[:10]
        else:
            news_feed = news_feed[:10]

        return news_feed
コード例 #5
0
    def add_media(cls, playlist, media):
        if isinstance(playlist, int):
            playlist = db.query(Playlist).get(playlist)

        if isinstance(media, int):
            media = db.query(Media).get(media)

        if None in [playlist, media]:
            return False

        playlist.media_list.append(media)
        db.add(playlist)
        db.commit()

        NewsFeedController.create(news_type=1 if playlist.default else 2,
                                  media=media,
                                  playlist=playlist)

        return True
コード例 #6
0
    def get_playlist_number(cls, **kwargs):
        """
        Parameters:
        user: owner of playlist
        """

        playlist = db.query(Playlist)
        user = kwargs.get('user', g.user)
        if isinstance(user, User):
            playlist = playlist.filter_by(owner=user.id_int)
        elif isinstance(user, int):
            playlist = playlist.filter_by(owner=user)

        return playlist.count() or 0
コード例 #7
0
    def get_all_playlist(cls, **kwargs):
        """
        Parameters:
        user: specific user (default=user of current session)
        """

        playlist = db.query(Playlist)
        user = kwargs.get("user", g.user)
        if isinstance(user, User):
            playlist = playlist.filter_by(owner=user.id_int)
        elif isinstance(user, int):
            playlist = playlist.filter_by(owner=user)

        playlist = playlist.order_by("created_at")
        return playlist
コード例 #8
0
    def get_user_by_id_int(cls, id_int):
        user = db.query(User).filter_by(id_int=id_int).first()

        if user:
            return user
        return None
コード例 #9
0
 def get_playlist_by_id_int(cls, id_int):
     playlist = db.query(Playlist).filter_by(id_int=id_int).first()
     return playlist