当前位置: 首页>>代码示例>>Python>>正文


Python model.get_current_youtify_user_model函数代码示例

本文整理汇总了Python中model.get_current_youtify_user_model函数的典型用法代码示例。如果您正苦于以下问题:Python get_current_youtify_user_model函数的具体用法?Python get_current_youtify_user_model怎么用?Python get_current_youtify_user_model使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了get_current_youtify_user_model函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: post

    def post(self):
        """Update playlist"""
        youtify_user_model = get_current_youtify_user_model()
        if youtify_user_model == None:
            self.error(403)
            return

        playlist_id = self.request.path.split("/")[-1]
        playlist_model = Playlist.get_by_id(int(playlist_id))
        json = self.request.get("json", None)
        device = self.request.get("device")

        if json is None:
            self.error(400)
            return

        if playlist_model.owner.key() == youtify_user_model.key():
            if youtify_user_model.device != device:
                self.error(409)
                self.response.out.write("wrong_device")
                return
            else:
                old_playlist = simplejson.loads(json)
                playlist_model.private = old_playlist.get("isPrivate", False)
                playlist_model.tracks_json = simplejson.dumps(old_playlist["videos"])
                playlist_model.owner = youtify_user_model
                playlist_model.title = old_playlist["title"]
                playlist_model.remote_id = old_playlist["remoteId"]
                playlist_model.json = None
                playlist_model.save()

                self.response.out.write(str(playlist_model.key().id()))
        else:
            self.error(403)
开发者ID:noisebleed,项目名称:youtify,代码行数:34,代码来源:playlists.py

示例2: get

 def get(self):
     redirect_uri = self.request.get("redirect_uri", "/")
     user = get_current_youtify_user_model()
     user.flattr_access_token = None
     user.flattr_user_name = None
     user.save()
     self.redirect(redirect_uri)
开发者ID:rbplani,项目名称:youtify,代码行数:7,代码来源:flattr.py

示例3: get

 def get(self, path):
     """List content in path"""
     filetypes = ['.mp3', '.mp4', '.ogg', '.wav']
     user = get_current_youtify_user_model()
     if user is None:
         self.error(403)
         self.response.out.write('User not logged in')
         return
     access_token = OAuthToken.from_string(user.dropbox_access_token)
     session = dropbox.session.DropboxSession(config.DROPBOX_APP_KEY, config.DROPBOX_APP_SECRET, config.DROPBOX_ACCESS_TYPE)
     session.token = access_token
     client = dropbox.client.DropboxClient(session)
     
     path = '/' + path
     dirs = []
     mediafiles = []
     
     try:
         metadata = client.metadata(path)
         if 'contents' in metadata:
             for item in metadata['contents']:
                 if item['is_dir']:
                     dirs.append(item['path'])
                 else:
                     for filetype in filetypes:
                         if item['path'].lower().endswith(filetype):
                             # all currently supported filetypes are 4 chars long
                             title = ' - '.join(item['path'].split('/'))[3:-4]
                             track = { 'videoId': item['path'], 'title': title, 'type': 'dropbox' }
                             mediafiles.append(track)
                             break
     except:
         pass
     self.response.headers['Content-Type'] = 'application/json'
     self.response.out.write(simplejson.dumps({'dirs': dirs, 'media': mediafiles}))
开发者ID:Narii1416,项目名称:youtify,代码行数:35,代码来源:dropbox-handler.py

示例4: post

    def post(self, type, external_user_id):
        """Subscribes to an external user"""
        youtify_user_model = get_current_youtify_user_model()
        if youtify_user_model == None:
            self.error(403)
            return
        
        external_user_model = ExternalUser.all().filter('type =', type).filter('external_user_id =', external_user_id).get()
        if external_user_model is None:
            external_user_model = ExternalUser(type=type, external_user_id=external_user_id) 

            # @XXX should not trust client with this information, fetch from server instead
            external_user_model.username = self.request.get('username')
            external_user_model.avatar_url = self.request.get('avatar_url')
            external_user_model.get_last_updated = True

            external_user_model.save()
        
        if external_user_model.key() in youtify_user_model.external_user_subscriptions:
            self.error(400)
            self.response.out.write('You already subscribe to this external user')
            return
            
        youtify_user_model.external_user_subscriptions.append(external_user_model.key())
        youtify_user_model.save()
        
        external_user_model.subscribers.append(youtify_user_model.key())
        external_user_model.nr_of_subscribers = len(external_user_model.subscribers)
        external_user_model.get_last_updated = True
        external_user_model.save()

        create_external_subscribe_activity(youtify_user_model, external_user_model)
        
        self.response.headers['Content-Type'] = 'text/plain'
        self.response.out.write('ok')
开发者ID:Narii1416,项目名称:youtify,代码行数:35,代码来源:external_users.py

示例5: post

 def post(self):
     user = get_current_youtify_user_model()
     user.send_new_follower_email = self.request.get('send_new_follower_email') == 'true'
     user.send_new_subscriber_email = self.request.get('send_new_subscriber_email') == 'true'
     user.save()
     settings = get_settings_struct_for_youtify_user_model(user)
     self.response.out.write(simplejson.dumps(settings))
开发者ID:Erkan-Yilmaz,项目名称:youtify,代码行数:7,代码来源:me.py

示例6: post

    def post(self, type, external_user_id):
        """Marks the external user as viewed"""
        youtify_user_model = get_current_youtify_user_model()
        if youtify_user_model == None:
            self.response.out.write("user not logged in")
            logging.info("user not logged in")
            self.error(403)
            return

        external_user_model = (
            ExternalUser.all().filter("type =", type).filter("external_user_id =", external_user_id).get()
        )
        if external_user_model == None:
            logging.info("external user " + external_user_id + " not found")
            self.response.out.write("external user " + external_user_id + " not found")
            self.error(404)
            return
        external_user_timestamp = (
            ExternalUserTimestamp.all()
            .filter("external_user =", external_user_model)
            .filter("user =", youtify_user_model)
            .get()
        )

        if external_user_timestamp == None:
            external_user_timestamp = ExternalUserTimestamp(
                external_user=external_user_model.key(), user=youtify_user_model.key()
            )

        external_user_timestamp.last_viewed = datetime.now()
        external_user_timestamp.save()

        self.response.out.write("ok")
开发者ID:hanlindev,项目名称:youtify,代码行数:33,代码来源:external_users.py

示例7: delete

    def delete(self, type, external_user_id):
        """Unsubscribes from an external user"""
        youtify_user_model = get_current_youtify_user_model()
        if youtify_user_model == None:
            self.error(403)
            return

        external_user_model = (
            ExternalUser.all().filter("type =", type).filter("external_user_id =", external_user_id).get()
        )

        youtify_user_model.external_user_subscriptions.remove(external_user_model.key())
        youtify_user_model.save()

        external_user_model.subscribers.remove(youtify_user_model.key())
        external_user_model.nr_of_subscribers = len(external_user_model.subscribers)

        if external_user_model.nr_of_subscribers > 0:
            external_user_model.get_last_updated = True
        else:
            external_user_model.get_last_updated = False
        external_user_model.save()

        self.response.headers["Content-Type"] = "text/plain"
        self.response.out.write("ok")
开发者ID:hanlindev,项目名称:youtify,代码行数:25,代码来源:external_users.py

示例8: post

    def post(self, uid):
        other_user = YoutifyUser.get_by_id(int(uid))
        me = get_current_youtify_user_model()

        if other_user is None:
            self.error(400)
            self.response.out.write('Other user not found')
            return

        if me.key().id() == other_user.key().id():
            self.error(400)
            self.response.out.write('You can not follow yourself')
            return

        if FollowRelation.all().filter('user1 =', me).filter('user2 =', other_user).get():
            self.error(400)
            self.response.out.write('You already follow that user')
            return

        me.nr_of_followings += 1
        other_user.nr_of_followers += 1

        me.save()
        other_user.save()

        m = FollowRelation(user1=me.key().id(), user2=other_user.key().id())
        m.put()

        create_follow_activity(me, other_user)
        send_new_follower_email(me, other_user)

        self.response.headers['Content-Type'] = 'text/plain'
        self.response.out.write('ok')
开发者ID:hanlindev,项目名称:youtify,代码行数:33,代码来源:me.py

示例9: post

    def post(self):
        """Add a track to the favorite list"""
        youtify_user_model = get_current_youtify_user_model()
        if youtify_user_model == None:
            self.error(403)
            return
        
        playlist_id = self.request.path.split('/')[-1]
        playlist_model = Playlist.get_by_id(int(playlist_id))
        json = self.request.get('json', None)
        device = self.request.get('device')

        if json is None:
            self.error(400)
            return

        if playlist_model.owner.key() == youtify_user_model.key():
            if youtify_user_model.device != device:
                self.error(409)
                self.response.out.write('wrong_device')
                return
            else:
                old_playlist = simplejson.loads(json)
                playlist_model.private = old_playlist.get('isPrivate', False)
                playlist_model.tracks_json = simplejson.dumps(old_playlist['videos'])
                playlist_model.owner = youtify_user_model
                playlist_model.title = old_playlist['title']
                playlist_model.remote_id = old_playlist['remoteId']
                playlist_model.json = None
                playlist_model.save()
                
                self.response.out.write(str(playlist_model.key().id()))
        else:
            self.error(403)
开发者ID:Narii1416,项目名称:youtify,代码行数:34,代码来源:favorites.py

示例10: post

    def post(self):
        """Follows a playlist"""
        youtify_user_model = get_current_youtify_user_model()
        if youtify_user_model == None:
            self.error(403)
            return
        
        playlist_id = self.request.path.split('/')[-1]
        playlist_model = Playlist.get_by_id(int(playlist_id))
        if playlist_model is None:
            self.error(404)
            return

        if playlist_model.owner.key().id() == youtify_user_model.key().id():
            self.error(400)
            self.response.out.write('You can not subscribe to your own playlists')
            return
        
        youtify_user_model.playlist_subscriptions.append(playlist_model.key())
        youtify_user_model.save()
        
        playlist_model.followers.append(youtify_user_model.key())
        playlist_model.save()

        create_subscribe_activity(youtify_user_model, playlist_model)
        send_new_subscriber_email(youtify_user_model, playlist_model)
        
        self.response.headers['Content-Type'] = 'text/plain'
        self.response.out.write('ok')
开发者ID:Erkan-Yilmaz,项目名称:youtify,代码行数:29,代码来源:playlists.py

示例11: post

    def post(self):
        url_to_submit = self.request.get("url")
        video_title = self.request.get("videoTitle")
        url = "https://api.flattr.com/rest/v2/flattr"
        user = get_current_youtify_user_model()

        headers = {"Authorization": "Bearer %s" % user.flattr_access_token, "Content-Type": "application/json"}

        data = simplejson.dumps({"url": url_to_submit})

        response = urlfetch.fetch(
            url=url, payload=data, method=urlfetch.POST, headers=headers, validate_certificate=VALIDATE_CERTIFICATE
        )
        json = simplejson.loads(response.content)

        if json.get("message") == "ok" and "thing" in json:
            thing_id = str(json["thing"].get("id"))
            create_flattr_activity(user, thing_id, video_title)
            user.nr_of_flattrs += 1
            user.save()
        elif json.get("error") == "flattr_once":
            pass
        else:
            logging.error("Error creating flattr click. Response: %s" % response.content)

        self.response.headers["Content-Type"] = "application/json"
        self.response.out.write(response.content)
开发者ID:rbplani,项目名称:youtify,代码行数:27,代码来源:flattr.py

示例12: post

    def post(self):
        url_to_submit = self.request.get('url')
        video_title = self.request.get('videoTitle')
        url = 'https://api.flattr.com/rest/v2/flattr'
        user = get_current_youtify_user_model()

        headers = {
            'Authorization': 'Bearer %s' % user.flattr_access_token,
            'Content-Type': 'application/json',
        }

        data = simplejson.dumps({
            'url': url_to_submit,
        })

        response = urlfetch.fetch(url=url, payload=data, method=urlfetch.POST, headers=headers, validate_certificate=VALIDATE_CERTIFICATE)
        json = simplejson.loads(response.content)

        if json.get('message') == 'ok' and 'thing' in json:
            thing_id = str(json['thing'].get('id'))
            create_flattr_activity(user, thing_id, video_title)
            user.nr_of_flattrs += 1
            user.save()
        else:
            logging.error('Error creating flattr click. Response: %s' % response.content)

        self.response.headers['Content-Type'] = 'application/json'
        self.response.out.write(response.content)
开发者ID:glesperance,项目名称:youtify,代码行数:28,代码来源:flattr.py

示例13: get

 def get(self):
     """Set a new device token for the user"""
     user = get_current_youtify_user_model()
     user.device = generate_device_token()
     user.save()
     json = {"device": user.device}
     self.response.headers["Content-Type"] = "application/json"
     self.response.out.write(simplejson.dumps(json))
开发者ID:glesperance,项目名称:youtify,代码行数:8,代码来源:me.py

示例14: post

    def post(self):
        username = self.request.get("username")

        user = get_current_youtify_user_model()
        user.youtube_username = username
        user.save()

        self.response.headers["Content-Type"] = "text/plain"
        self.response.out.write("ok")
开发者ID:glesperance,项目名称:youtify,代码行数:9,代码来源:me.py

示例15: get

 def get(self):
     """Get the users playlists, including private ones"""
     user = get_current_youtify_user_model()
     if user:
         json = get_playlist_overview_structs(user, True)
     else:
         json = []
     self.response.headers['Content-Type'] = 'application/json'
     self.response.out.write(simplejson.dumps(json))
开发者ID:hanlindev,项目名称:youtify,代码行数:9,代码来源:me.py


注:本文中的model.get_current_youtify_user_model函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。