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


Python User.is_admin方法代码示例

本文整理汇总了Python中user.User.is_admin方法的典型用法代码示例。如果您正苦于以下问题:Python User.is_admin方法的具体用法?Python User.is_admin怎么用?Python User.is_admin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在user.User的用法示例。


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

示例1: addTrack

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import is_admin [as 别名]
def addTrack():
    l = Location.from_id(request.form["location_id"])
    uid = User.current_id()
    if User.is_admin() and request.form["special"] == "true":
        special = 1
        uid = 29 #MAGIC NUMBER!!! This is the ID of the MSS user on the server
    else:
        special = 0
    ret = l.add_track(request.form["provider_id"], uid, special)
    return ret
开发者ID:chrisclark,项目名称:msfm,代码行数:12,代码来源:music.py

示例2: vote

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import is_admin [as 别名]
 def vote(self, pli_id, direc):
     if not "voted_arr" in session: session["voted_arr"] = []
     voted = session["voted_arr"]
     if User.is_admin() or not pli_id in voted:
         v = Vote(playlist_item_id=pli_id, user_id=User.current_id(), direction=direc)
         v.save()
         voted.append(pli_id)
         session["voted_arr"] = voted  
         self.update_subscribers()
         return common.buildDialogResponse("Thanks for the input!", 200)
     else:
         return common.buildDialogResponse("Nice try sucka! You already voted", 409)
开发者ID:chrisclark,项目名称:msfm,代码行数:14,代码来源:location.py

示例3: add_track

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import is_admin [as 别名]
    def add_track(self, prov_id, user_id, special):
        
        #make sure it's in the DB
        t = MusicLibrary.get_track(provider_id=prov_id)
        
        if not User.is_admin() and self._numTracksFromUser(user_id) > 1:
            return common.buildDialogResponse("You can only have 2 songs on the playlist at once :(", 409)

        if self.playlist().contains_track(t.id):
            return common.buildDialogResponse("Someone already added that one (but you can go vote it up).", 409)
        
        PlaylistItem(track_id=t.id, location_id=self.id, user_id=user_id, date_added=str(datetime.now()), special=special).save()
        self.update_subscribers()
        return common.buildDialogResponse("Song added!", 200)
开发者ID:chrisclark,项目名称:msfm,代码行数:16,代码来源:location.py

示例4: leaderboard

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import is_admin [as 别名]
 def leaderboard(self, hrs=0):
     conn = db_session.connection()
     #TODO: Better sql here. This is pretty weak sauce
     #this is a special case to handle the "all time" leaderboard (hrs=0)
     if hrs == 0: query = "select u.id as user_id, u.first_name, u.last_name, u.photo_url, u.facebook_id, sum(direction) as score from votes v inner join playlist_items pi on v.playlist_item_id = pi.id inner join users u on pi.user_id = u.id where pi.location_id = %s group by pi.user_id order by score desc limit 10;" % (self.id)
     else: query = "select u.id as user_id, u.first_name, u.last_name, u.photo_url, u.facebook_id, sum(direction) as score from votes v inner join playlist_items pi on v.playlist_item_id = pi.id inner join users u on pi.user_id = u.id where pi.location_id = %s and v.timestamp > DATE_SUB(NOW(), INTERVAL %s HOUR) group by pi.user_id order by score desc limit 10;" % (self.id, str(hrs))  
     leaders = conn.execute(query)
     ret = []
     for row in leaders:
         newrow = dict() #necessary because the SQLALCHEMY row doesn't support value updates
         for k in row.keys():
             if isinstance(row[k], decimal.Decimal): newrow[k] = int(row[k])
             elif k == "last_name" and not User.is_admin(): newrow[k] = row[k][0] #only get first letter of last name if its not an admin 
             else: newrow[k] = row[k]
         ret.append(newrow)
     return ret
开发者ID:chrisclark,项目名称:msfm,代码行数:18,代码来源:location.py

示例5: to_json

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import is_admin [as 别名]
    def to_json(self):
        serialize_me = []
        
        cur_playing_pli = None
        
        scores = self._get_scores()
        
        for i in self.queue:
            t = i[0]
            pli = i[1]
            u = i[2]
            
            if pli.id not in scores: scores[pli.id] = 0
            
            dic = common.strip_private(t.__dict__)
        
            dic["currently_playing"] = (pli.id == self.currently_playing_pli_id)
            dic["score"] = scores[pli.id]
            dic["playlist_item_id"] = pli.id
            dic["time_sort"] = time.mktime(pli.date_added.timetuple())
            dic["special"] = pli.special
            
            dic["first_name"] = u.first_name
            if User.is_admin():
                dic["last_name"] = u.last_name
            else:
                dic["last_name"] = u.last_name[0]
            dic["photo_url"] = u.photo_url
            dic["facebook_id"] = u.facebook_id
            
            #this let's us skip an entire sort later on
            if dic["currently_playing"]:
                cur_playing_pli = dic
            else:            
                serialize_me.append(dic)
        
        serialize_me.sort(key=itemgetter("time_sort"))
        serialize_me.sort(key=itemgetter("score"), reverse=True)
        serialize_me.sort(key=itemgetter("special"), reverse=True)
        
        if cur_playing_pli:
            serialize_me.insert(0, cur_playing_pli)

        return json.dumps(serialize_me)
开发者ID:chrisclark,项目名称:msfm,代码行数:46,代码来源:playlist.py

示例6: show_delete_article

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import is_admin [as 别名]
def show_delete_article():
  logged_user = request.get_cookie('account', secret='SECRETKEY')
  if User.is_admin(logged_user):
    return template("view/delete_article.tpl", messages=False)
  else:
    return template("view/main.tpl", messages=User.permission_msgs['admin'], user=logged_user)
开发者ID:tomcat1911,项目名称:dmd,代码行数:8,代码来源:start.py

示例7: decorated_function

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import is_admin [as 别名]
 def decorated_function(*args, **kwargs):
     if not User.is_admin():
         return common.buildDialogResponse("Admins only", 401)
     return f(*args, **kwargs)
开发者ID:chrisclark,项目名称:msfm,代码行数:6,代码来源:music.py


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