def top(page, sort_by, filter_worth_by): query = Repo.filter_by_args(Repo.query, request.args).filter(Repo.mature.is_(True)) sorts = { 'wanted': [Repo.worth.desc(), Repo.stargazers_count.desc()], 'stars': [Repo.stargazers_count.desc()] } if filter_worth_by not in ('rising', 'solid'): filter_worth_by = 'solid' query = query.filter( (Repo.worth >= app.config['REPOSITORY_WORTH_SOLID']) if filter_worth_by == 'solid' else ( (Repo.worth > app.config['REPOSITORY_WORTH_DEFAULT']) & (Repo.worth < app.config['REPOSITORY_WORTH_SOLID']) ) ) for f in [sort for sort in (sorts['wanted'] if sort_by not in sorts else sorts[sort_by])]: query = query.order_by(f) if not g.user: query = query.add_columns(db.null()) else: query = UserAttitude.join_by_user_and_repo(query, g.user.id, Repo.id)\ .add_columns(UserAttitude.attitude) entries = query.paginate(page if page > 0 else 1, per_page=20, error_out=False) if entries.pages and entries.pages < entries.page: return top(entries.pages, sort_by, filter_worth_by) return render_template( 'repository/top.html', languages=Repo.language_distinct(), repos=entries, page=page, sort_by=sort_by, filter_worth_by=filter_worth_by )
def top(sort_by, page): query = Repo.filter_by_args(Repo.query, request.args).filter(Repo.worth > 4) sorts = { 'wanted': [Repo.worth.desc(), Repo.stargazers_count.desc()], 'stars': [Repo.stargazers_count.desc()] } for f in [ sort for sort in ( sorts['wanted'] if sort_by not in sorts else sorts[sort_by]) ]: query = query.order_by(f) if not g.user: query = query.add_columns(db.null()) else: query = UserAttitude.join_by_user_and_repo(query, g.user.id, Repo.id)\ .add_columns(UserAttitude.attitude) entries = query.paginate(page if page > 0 else 1, per_page=20, error_out=False) if entries.pages and entries.pages < entries.page: return top(sort_by, entries.pages) return render_template('repository/top.html', languages=Repo.language_distinct(), repos=entries, page=page, sort_by=sort_by)
def repo_like(repo_name: str, uid: int): repo = Repo.get_one_by_full_name(repo_name) if not repo: return None db.session.merge(UserAttitude.like(uid, repo.id)) db.session.commit() return repo.id
def repo_starred_star(user_id: int, access_token: str): starred, code = user_starred(access_token) if not starred: return False attitudes = UserAttitude.liked_by_user(user_id) lst = [user_starred_star(r.repo.full_name, access_token) for r in attitudes if not [x for x in starred if x['full_name'] == r.repo.full_name]] return len(lst)
def change(repo_id, attitude): if not verify_attitude(attitude): return abort(403) if not Repo.query.get(repo_id): return abort(404) db.session.merge( UserAttitude(user_id=g.user.id, repo_id=repo_id, attitude=attitude)) db.session.commit() return jsonify(attitude=attitude)
def change(repo_id, attitude): if not verify_attitude(attitude): return abort(403) if not Repo.query.get(repo_id): return abort(404) db.session.merge( UserAttitude(user_id=g.user.id, repo_id=repo_id, attitude=attitude)) db.session.commit() return make_response(render_template_string('Ok'), 204)
def repo_starred_star(user_id: int, access_token: str): starred, code = user_starred(access_token) if not starred: return False attitudes = UserAttitude.list_liked_by_user(user_id) lst_in = [repo_like(s['full_name'], user_id) for s in starred if not [a for a in attitudes if s['full_name'] == a.repo.full_name]] lst_out = [user_starred_star(r.repo.full_name, access_token) for r in attitudes if not [x for x in starred if x['full_name'] == r.repo.full_name]] return len(lst_out), len(list(filter(None, lst_in)))
def list_by_range(rng): map_list = {'day': 'ReportAllDaily', 'week': 'ReportAllWeekly', 'month': 'ReportAllMonthly'} model = getattr(report, map_list.get(rng, map_list.get('day'))) query = Repo.filter_by_args(model.query, request.args)\ .join(Repo)\ .order_by(model.cnt_watch.desc()) if not g.user: query = query.add_columns(db.null()) else: query = UserAttitude.join_by_user_and_repo(query, g.user.id, Repo.id)\ .add_columns(UserAttitude.attitude) return render_template('index.html', entries=query, languages=Repo.language_distinct())
def list_by_attitude(attitude, page): q = UserAttitude.join_by_user_and_repo(Repo.query, g.user.id, Repo.id)\ .add_columns(UserAttitude.attitude if attitude else db.null())\ .filter(UserAttitude.attitude == attitude) q = Repo.filter_by_args(q, request.args) entries = q.paginate(page if page > 0 else 1, per_page=20, error_out=False) if entries.pages and entries.pages < entries.page: return list_by_attitude(attitude, entries.pages) return render_template( 'repository/attitude.html', repos=entries, attitude=attitude, languages=Repo.language_distinct() )
def list_by_attitude(attitude, page): q = UserAttitude.join_by_user_and_repo(Repo.query, g.user.id, Repo.id)\ .add_columns(UserAttitude.attitude if attitude else db.null())\ .filter(UserAttitude.attitude == attitude) q = Repo.filter_by_args(q, request.args) entries = q.paginate(page if page > 0 else 1, per_page=20, error_out=False) if entries.pages and entries.pages < entries.page: return list_by_attitude(attitude, entries.pages) return render_template('repository/attitude.html', repos=entries, attitude=attitude, languages=Repo.language_distinct())
def repo_starred_star(user_id: int, access_token: str): starred, code = user_starred(access_token) if not starred: return False attitudes = UserAttitude.list_liked_by_user(user_id) lst_in = [ repo_like(s['full_name'], user_id) for s in starred if not [a for a in attitudes if s['full_name'] == a.repo.full_name] ] lst_out = [ user_starred_star(r.repo.full_name, access_token) for r in attitudes if not [x for x in starred if x['full_name'] == r.repo.full_name] ] return len(lst_out), len(list(filter(None, lst_in)))
def top(page): q = Repo.filter_by_args(Repo.query, request.args)\ .filter(Repo.worth > 4)\ .order_by(Repo.worth.desc())\ .order_by(Repo.created_at.asc()) if not g.user: q = q.add_columns(db.null()) else: q = UserAttitude.join_by_user_and_repo(q, g.user.id, Repo.id)\ .add_columns(UserAttitude.attitude) entries = q.paginate(page if page > 0 else 1, per_page=20, error_out=False) if entries.pages and entries.pages < entries.page: return top(entries.pages) return render_template( 'repository/top.html', repos=entries, page=page, languages=Repo.language_distinct() )
def top(page, sort_by, filter_worth_by): query = Repo.filter_by_args(Repo.query, request.args).filter(Repo.mature.is_(True)) sorts = { 'wanted': [Repo.worth.desc(), Repo.stargazers_count.desc()], 'stars': [Repo.stargazers_count.desc()] } if filter_worth_by not in ('rising', 'solid'): filter_worth_by = 'solid' query = query.filter(( Repo.worth >= app.config['REPOSITORY_WORTH_SOLID'] ) if filter_worth_by == 'solid' else ( (Repo.worth > app.config['REPOSITORY_WORTH_DEFAULT']) & (Repo.worth < app.config['REPOSITORY_WORTH_SOLID']))) for f in [ sort for sort in ( sorts['wanted'] if sort_by not in sorts else sorts[sort_by]) ]: query = query.order_by(f) if not g.user: query = query.add_columns(db.null()) else: query = UserAttitude.join_by_user_and_repo(query, g.user.id, Repo.id)\ .add_columns(UserAttitude.attitude) entries = query.paginate(page if page > 0 else 1, per_page=20, error_out=False) if entries.pages and entries.pages < entries.page: return top(entries.pages, sort_by, filter_worth_by) return render_template('repository/top.html', languages=Repo.language_distinct(), repos=entries, page=page, sort_by=sort_by, filter_worth_by=filter_worth_by)
def top(page): q = Repo.filter_by_args(Repo.query, request.args)\ .filter(Repo.worth > 6)\ .order_by(Repo.worth.desc())\ .order_by(Repo.stargazers_count.desc()) if not g.user: q = q.add_columns(db.null()) else: q = UserAttitude.join_by_user_and_repo(q, g.user.id, Repo.id)\ .add_columns(UserAttitude.attitude) entries = q.paginate(page if page > 0 else 1, per_page=20, error_out=False) if entries.pages and entries.pages < entries.page: return top(entries.pages) return render_template('repository/top.html', repos=entries, page=page, languages=Repo.language_distinct())