-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #108 from kkamkou/issue-103
Issue 103
- Loading branch information
Showing
22 changed files
with
214 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,18 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
(cd ..; alembic upgrade head) | ||
case "$1" in | ||
web) | ||
(cd ..; alembic upgrade head) | ||
python -m gitmostwanted.web | ||
;; | ||
|
||
python -m gitmostwanted.web | ||
celery) | ||
rm -f /tmp/celerybeat-schedule.dat | ||
celery -A gitmostwanted.app.celery worker -B -s /tmp/celerybeat-schedule.dat --autoreload --loglevel=DEBUG | ||
;; | ||
|
||
*) | ||
echo $"Usage: $0 {web|celery}" | ||
exit 1 | ||
esac |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from flask import Blueprint, g, request, render_template | ||
from gitmostwanted.models.repo import Repo | ||
from gitmostwanted.models.user import UserAttitude | ||
from gitmostwanted.models import report | ||
from gitmostwanted.app import db | ||
|
||
repo_trending = Blueprint('repo_trending', __name__) | ||
|
||
|
||
@repo_trending.route('/', defaults={'rng': 'day'}) | ||
@repo_trending.route('/trending/<rng>/') | ||
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 = model.query.join(Repo).order_by(model.cnt_watch.desc()) | ||
if not g.user: | ||
return list_by_range_filtered(query.add_columns(db.null())) | ||
|
||
return list_by_range_filtered( | ||
query.add_columns(UserAttitude.attitude).outerjoin( | ||
UserAttitude, | ||
(UserAttitude.user_id == g.user.id) & (UserAttitude.repo_id == Repo.id) | ||
) | ||
) | ||
|
||
|
||
def list_by_range_filtered(query): | ||
langs = Repo.language_distinct() | ||
|
||
lang = request.args.get('lang') | ||
if lang != 'All' and (lang,) in langs: | ||
query = query.filter(Repo.language == lang) | ||
|
||
status = request.args.get('status') | ||
if status in ('promising', 'hopeless'): | ||
query = query.filter(Repo.status == status) | ||
|
||
if bool(request.args.get('mature')): | ||
query = query.filter(Repo.mature.is_(True)) | ||
|
||
return render_template('index.html', entries=query, languages=langs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
from flask import Blueprint, g, redirect, request, session, url_for | ||
from gitmostwanted.services import oauth as service_oauth | ||
from gitmostwanted.models.user import User | ||
from gitmostwanted.app import app, db | ||
|
||
user_oauth = Blueprint('user_oauth', __name__) | ||
oauth = service_oauth.instance(app) | ||
|
||
|
||
@app.before_request | ||
def load_user_from_session(): | ||
if str(request.url_rule) in ['/logout']: | ||
return None | ||
g.user = User.query.get(session['user_id']) if 'user_id' in session else None | ||
|
||
|
||
@user_oauth.route('/logout') | ||
def logout(): | ||
session.pop('github_token', None) | ||
session.pop('user_id', None) | ||
return redirect('/') | ||
|
||
|
||
@user_oauth.route('/oauth/login') | ||
def login(): | ||
return oauth.github\ | ||
.authorize(callback=url_for('user_oauth.authorized', next=url_next(), _external=True)) | ||
|
||
|
||
@user_oauth.route('/oauth/authorized') | ||
def authorized(): | ||
next_url = url_next() or url_for('/') | ||
|
||
resp = oauth.github.authorized_response() | ||
if resp is None: | ||
return redirect(next_url) | ||
|
||
session.permanent = True | ||
session['github_token'] = (resp['access_token'], '') | ||
me = oauth.github.get('user') | ||
session['user_id'] = user_get_or_create(me.data['id'], me.data['email'], me.data['login']).id | ||
|
||
return redirect(next_url) | ||
|
||
|
||
@oauth.github.tokengetter | ||
def github_tokengetter(): | ||
return session.get('github_token') | ||
|
||
|
||
def user_get_or_create(uid, uemail, uname): | ||
entity = User.query.filter_by(github_id=uid).first() | ||
if entity: | ||
return entity | ||
entity = User(github_id=uid, username=uname, email=uemail or None) | ||
db.session.add(entity) | ||
db.session.commit() | ||
return entity | ||
|
||
|
||
def url_next(): | ||
return request.args.get('next') or request.referrer or None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.