def get_wall_posts(wall_id, number=0): number = int(number) if number == 0: return Post.query.filter(Post.wall_id == wall_id).order_by(db.desc(Post.edited_time)).limit(5) else: return Post.query.filter(Post.wall_id == wall_id).order_by(db.desc(Post.edited_time)).slice(number, number+5)
def contests(page=0): if type(page)==int: page=0 if page<1 else page-1 data=Contest.query.order_by(db.desc(Contest.id)).limit(10).offset(page*10).all() objects_list=[] for row in data: d=collections.OrderedDict() d['id']=row.id d['title']=row.title d['description']=row.description d['start_time']=row.start_time d['end_time']=row.end_time d['problems']=row.problems d['private']=row.private d['contestants']=row.contestants d['ranklist']=row.ranklist objects_list.append(d) return render_template("contests.html", contests=objects_list, total_page = int(math.ceil(Contest.query.count()/10.0)), current_page = page + 1, ctime=datetime.now(), site_name = app.config['SCPC_TS_SITE_NAME'] ) return redirect(url_for('index'))
def get_wall_posts(wall_id,start_id = 0, post_count = 5): start_id = int(start_id) if start_id == 0: return Post.query.filter(Post.wall_id == wall_id).order_by(db.desc(Post.edited_time)).limit(post_count) else: return Post.query.filter(Post.wall_id == wall_id, Post.id < start_id).order_by(db.desc(Post.edited_time)).limit(post_count)
def index(): """ 网站首页 :return: """ context = { 'questions': Question.query.order_by( db.desc('create_time')).all() # 按照时间降序排序 最新的信息在排在前面 } return render_template('home/index.html', **context)
def get_rank_team_list(league): team_rank_list=[] cnt=1 for team in Team.query.filter_by(league=league).order_by(db.desc(Team.point),db.desc(Team.goal_difference),db.desc(Team.goals_for),db.asc(Team.goals_against)).slice(0,20): #User.query.order_by(User.popularity.desc(),User.date_created.desc()).limit(10).all() rank_dic={} t=Team.query.get(team.pk) rank_dic['rank']=cnt rank_dic['name']=t.name rank_dic['win']=t.win rank_dic['draw']=t.draw rank_dic['lose']=t.lose rank_dic['point']=t.point rank_dic['goals_for']=t.goals_for rank_dic['goal_difference']=t.goal_difference rank_dic['goals_against']=t.goals_against team_rank_list.append(rank_dic) cnt+=1 return team_rank_list
def get_top_choice(self, word_data): choice = db.session.query(Choice).filter_by( word_id=word_data['wordId'], tweetry_id=word_data['tweetryId']).order_by( db.desc('votes')).first() if choice: top_choice = {'word': choice.text, 'votes': choice.votes} return top_choice else: return 'Failed'
def get_best_11_player(team_pk): match_pk=Match.query.filter(Match.win_team_pk!=None).order_by(db.desc(Match.date)).with_entities(Match.pk).first() best_11=[] if match_pk[0]!=None: match_team_pk=Match_team.query.filter(Match_team.match_pk==match_pk[0],Match_team.team_pk==team_pk).with_entities(Match_team.pk).first() if match_team_pk: player_pk_list=Match_player.query.filter(Match_player.match_team_pk==match_team_pk[0]).with_entities(Match_player.player_pk).all() for player_pk in player_pk_list: best_11.append(Player.query.filter(Player.pk==player_pk[0]).with_entities(Player.pk,Player.player_name,Player.position,Player.wildcard).all()) return best_11 else: return best_11 else: return best_11
def index(): news_list = News.query.order_by(db.desc(News.id)).limit(8).all() lenx=6 data = Submission.query.order_by(db.desc(Submission.id)).offset(0).limit(lenx).all() status = [] for row in data: d = collections.OrderedDict() d['id'] = row.id d['problem_id']=row.problem.id d['problem_title'] = row.problem.title d['username'] = row.user.username d['result'] = row.result d['memory_used'] = row.memory_used d['time_used'] = row.time_used d['compiler'] = row.compiler d['code'] = len(row.code) d['submit_time'] = row.submit_time status.append(d) return render_template("index.html", news_list = news_list, site_name = app.config['SCPC_TS_SITE_NAME'], status=status )
def search(): """ 搜索 :return: """ q = request.args.get('q') if q is not None: # 标题或内容包含有都返回 questions = Question.query.filter( or_(Question.title.contains(q), Question.content.contains(q))).order_by( db.desc('create_time')).all() return render_template('home/index.html', questions=questions) else: pass
def get_player_list_by_league(league): #리그속한 선수들 득점순 불러오기 team_pk_list=[] rank_list=[] cnt=1 # for team in get_team_list_by_league(league): for team in Team.query.filter_by(league=league).with_entities(Team.pk).all(): team_pk_list.append(team[0]) players=Player.query.filter(Player.team_pk.in_(team_pk_list)).order_by(db.desc(Player.goal)).with_entities(Player.player_name,Player.goal).slice(0,10) for player in players: p_dic={} p_dic['rank']=cnt p_dic['name']=player[0] p_dic['goal']=player[1] rank_list.append(p_dic) cnt+=1 return rank_list
def get_top_choice_list(self, word_data): choices = db.session.query(Choice).filter_by( word_id=word_data['wordId'], tweetry_id=word_data['tweetryId']).order_by( db.desc('votes')).limit(10).all() top_choices = {} for choice in choices: top_choices[choice.text] = { 'word': choice.text, 'votes': choice.votes } return top_choices
def messages(): """ 信息列表 :return: """ message_list = Message.query.order_by(db.desc('create_time')).all() message_list = [ { 'id': m.id, 'content': m.content, 'user_name': m.user.name, 'tags': [t.name for t in m.tags], 'create_time': m.create_time.strftime('%Y-%m-%d %X') } for m in message_list] return jsonify(code=200, msg='获取全部信息列表成功!', messages=message_list, total=len(message_list))
def get_top_choice_for_words(self, words_data): top_choice_list = [] for word in words_data: top_choice = db.session.query(Choice).filter_by( word_id=word['wordId'], tweetry_id=word['tweetryId']).order_by( db.desc('votes')).first() if top_choice: top_choice_list.append({ 'topChoice': top_choice.text, 'wordId': top_choice.word_id, 'votes': top_choice.votes }) return top_choice_list
def find(name, limit=10, page=1): """Нахождение чатов по названию или по идентификатору,\ если ``name`` является числом :param name: Имя чата :param limit: Количество чатов на странице :param page: Номер страницы :return: Все чаты, в названии которых содержится имя чата """ if name.isdigit(): chat_id = int(name) return [Chat.query.get(chat_id)] offset = (page - 1) * limit query = Chat.query.order_by(db.desc(Chat.create_time)) if name != '': query = query.filter(Chat.name.like('%' + name + '%')) if limit > 0: offset = (page - 1) * limit query = query.offset(offset).limit(limit) return query.all()
def messages_history(): """ 用户个人历史信息列表 :return: """ user_id = session.get('user_id') if user_id: message_list = Message.query.filter_by(user_id=user_id).order_by( db.desc('create_time')).all() message_list = [{ 'id': m.id, 'content': m.content, 'user_name': m.user.name, 'tags': [t.name for t in m.tags], 'create_time': m.create_time.strftime('%Y-%m-%d %X') } for m in message_list] return jsonify(code=200, msg='获取个人历史留言成功!', messages=message_list, total=len(message_list)) else: return jsonify(code=400, msg='请先登录!')
def get_player_rank_in_team(team_pk,keyword): if keyword==1: goal=Player.query.filter(and_(Player.team_pk==team_pk, Player.goal!=0)).order_by(db.desc(Player.goal)).with_entities(Player.goal).first() if goal!=None: return Player.query.filter(Player.team_pk==team_pk, Player.goal==goal.goal).order_by(db.desc(Player.goal)).with_entities(Player.player_name,Player.goal).slice(0,2) else: return [] if keyword==2: assist=Player.query.filter(and_(Player.team_pk==team_pk, Player.assist!=0)).order_by(db.desc(Player.assist)).with_entities(Player.assist).first() if assist!=None: return Player.query.filter(and_(Player.team_pk==team_pk, Player.assist==assist.assist)).order_by(db.desc(Player.assist)).with_entities(Player.player_name,Player.assist).slice(0,2) else: return [] if keyword==3: match_count= Player.query.filter(and_(Player.team_pk==team_pk, Player.match_count!=0)).order_by(db.desc(Player.match_count)).with_entities(Player.match_count).first() if match_count!=None: return Player.query.filter(and_(Player.team_pk==team_pk, Player.match_count==match_count.match_count)).order_by(db.desc(Player.match_count)).with_entities(Player.player_name,Player.match_count).slice(0,2) else: return [] if keyword==4: yellow=Player.query.filter(and_(Player.team_pk==team_pk, Player.yellow_card_count!=0)).order_by(db.desc(Player.yellow_card_count)).with_entities(Player.yellow_card_count).first() if yellow!=None: return Player.query.filter(and_(Player.team_pk==team_pk, Player.yellow_card_count==yellow.yellow_card_count)).order_by(db.desc(Player.yellow_card_count)).with_entities(Player.player_name,Player.yellow_card_count).slice(0,2) else: return [] if keyword==5: red=Player.query.filter(and_(Player.team_pk==team_pk, Player.red_card_count!=0)).order_by(db.desc(Player.red_card_count)).with_entities(Player.red_card_count).first() if red!=None: return Player.query.filter(and_(Player.team_pk==team_pk, Player.red_card_count==red.red_card_count)).order_by(db.desc(Player.red_card_count)).with_entities(Player.player_name,Player.red_card_count).slice(0,2) else: return [] if keyword==6: limit= Player.query.filter(and_(Player.team_pk==team_pk, Player.accumulate_limit_of_participation!=0)).order_by(db.desc(Player.accumulate_limit_of_participation)).with_entities(Player.accumulate_limit_of_participation).first() if limit!=None: return Player.query.filter(and_(Player.team_pk==team_pk, Player.accumulate_limit_of_participation==limit.accumulate_limit_of_participation)).order_by(db.desc(Player.accumulate_limit_of_participation)).with_entities(Player.player_name,Player.accumulate_limit_of_participation).slice(0,2) else: return []
def forum(page): if type(page) == int: page = 0 if page<1 else page-1 data = Forum.query.filter(Forum.father_node==0,Forum.problem==None).order_by(db.desc(Forum.id)).offset(page*10).limit(10).all() objects_list = [] for row in data: d = collections.OrderedDict() d['id'] = row.id d['title'] = row.title d['content'] = row.content d['last_update_time'] = row.last_update_time d['user'] = row.user.username d['user_email_hash'] = row.user.email.split('|')[1] d['last_reply'] = row.last_reply objects_list.append(d) total_page = int(math.ceil(Forum.query.filter(Forum.father_node==0,Forum.problem==None).count()/10.0)) if total_page == 0: total_page = 1 return render_template('forum.html', posts = objects_list, total_page = total_page, current_page = page + 1, site_name = app.config['SCPC_TS_SITE_NAME'] ) return redirect(url_for('index'))
def check_my_notification(user_pk): return Notification.query.filter(Notification.receiver_pk==user_pk, Notification.confirm==None).order_by(db.desc(Notification.send_time)).all()
def get_post_list(wallid,limit): cnt=int(limit) post=Post.query.filter(Post.wall_id==wallid).order_by(db.desc(Post.created_time)).slice(cnt,cnt+5).all() # post=Post.query.filter_by(wall_id=wallid).all() return post
def get_newspeed_post(find_list,cnt): posts=Post.query.filter(or_(Post.wall_id.in_(find_list), Post.user_id.in_(find_list) )).order_by(db.desc(Post.created_time)).slice(cnt,cnt+5).all() # posts=Post.query.filter(Post.user_id.in_([user_id])).all() # filter(or_(User.name == 'ed', User.name == 'wendy')) return posts
def get_all_posts(): return Post.query.filter(Post.wall_id == session['wall_host_id']).order_by(db.desc(Post.edited_time))
def newsfeed_get_all_posts(celebrities): return Post.query.filter( (Post.wall_id == session['user_id']) | (Post.user_id == session['user_id']) | (Post.user_id.in_(celebrities) ) | \ (Post.wall_id.in_(celebrities))).order_by(db.desc(Post.edited_time))
def get_next_match(): next_match=Match.query.filter(Match.win_team_pk!=None).order_by(db.desc(Match.date)).with_entities(Match.round_pk).first() round= Round.query.filter_by(pk=next_match[0]).with_entities(Round.round).first() return round[0]
def get_places(start): return Place.query.order_by(db.desc(Place.rank)).slice(start, start+8)
def season_next_match(): next_match=Match.query.order_by(db.desc(Match.date)).first() return find_round(next_match.round_pk)
def latest_booking(self): # filter booking where room_id == self.id and book_date is max return Booking.query.filter_by(room_id=self.id).order_by(db.desc(Booking.book_date)).first()
def keep_getting_post_5(wall_id, num): post = Post.query.filter(Post.wall_id == wall_id).order_by(db.desc(Post.edited_time)).slice(num, num+5).all() return post
def get_posts(wall_id, start_index): post = Post.query.filter(Post.wall_id == wall_id).order_by(db.desc(Post.edited_time)).offset(start_index).limit(5) return post
def get_newsfeed_posts(lists, num): post = Post.query.filter(Post.user_id.in_(lists) | Post.wall_id.in_(lists)).order_by(db.desc(Post.edited_time)).slice(num, num+5).all() return post
def get_post_5(wall_id): post = Post.query.filter(Post.wall_id == wall_id).order_by(db.desc(Post.edited_time)).limit(5) return post
def get_point_list_by_desc(league): return Team.query.filter_by(league=league).order_by(db.desc(Team.point)).all()