<s> import operator <EOL> from flask import render_template , request , redirect , url_for , g <EOL> from pypi_notifier import db , github <EOL> from pypi_notifier . models import Repo <EOL> list_params = { '<STR_LIT>' : '<STR_LIT:100>' } <EOL> def register_views ( app ) : <EOL> @ app . route ( '<STR_LIT>' ) <EOL> def get_user ( ) : <EOL> return str ( github . get ( '<STR_LIT:user>' ) ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> def get_repos ( ) : <EOL> repos = github . get ( '<STR_LIT>' , params = list_params ) <EOL> repos = with_organization_repos ( repos ) <EOL> selected_ids = [ r . github_id for r in g . user . repos ] <EOL> for repo in repos : <EOL> repo [ '<STR_LIT>' ] = ( repo [ '<STR_LIT:id>' ] in selected_ids ) <EOL> repos = [ r for r in repos if str ( r . get ( '<STR_LIT>' ) ) . lower ( ) == '<STR_LIT>' ] <EOL> return render_template ( '<STR_LIT>' , repos = repos ) <EOL> def with_organization_repos ( repos ) : <EOL> all_repos = { r [ '<STR_LIT:id>' ] : r for r in repos } <EOL> orgs = github . get ( '<STR_LIT>' ) <EOL> orgs_names = [ o [ '<STR_LIT>' ] for o in orgs ] <EOL> for org_name in orgs_names : <EOL> org_repos = github . get ( '<STR_LIT>' % org_name , <EOL> params = list_params ) <EOL> for repo in org_repos : <EOL> all_repos [ repo [ '<STR_LIT:id>' ] ] = repo <EOL> all_repos = all_repos . values ( ) <EOL> all_repos . sort ( key = operator . itemgetter ( '<STR_LIT>' ) ) <EOL> return all_repos <EOL> @ app . route ( '<STR_LIT>' , methods = [ '<STR_LIT:POST>' ] ) <EOL> def post_repos ( ) : <EOL> for name , github_id in request . form . iteritems ( ) : <EOL> github_id = int ( github_id ) <EOL> repo = Repo . query . filter ( <EOL> Repo . github_id == github_id , <EOL> Repo . user_id == g . user . id ) . first ( ) <EOL> if repo is None : <EOL> repo = Repo ( github_id , g . user ) <EOL> repo . name = name <EOL> db . session . add ( repo ) <EOL> ids = map ( int , request . form . itervalues ( ) ) <EOL> for repo in g . user . repos : <EOL> if repo . github_id not in ids : <EOL> db . session . delete ( repo ) <EOL> db . session . commit ( ) <EOL> return redirect ( url_for ( '<STR_LIT>' ) ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> def done ( ) : <EOL> reqs = g . user . get_outdated_requirements ( ) <EOL> return render_template ( '<STR_LIT>' , reqs = reqs ) <EOL> @ app . route ( '<STR_LIT>' , methods = [ '<STR_LIT:GET>' , '<STR_LIT:POST>' ] ) <EOL> def unsubscribe ( ) : <EOL> if request . method == '<STR_LIT:POST>' : <EOL> if request . form [ '<STR_LIT>' ] == '<STR_LIT:yes>' : <EOL> if g . user : <EOL> db . session . delete ( g . user ) <EOL> db . session . commit ( ) <EOL> return render_template ( '<STR_LIT>' ) <EOL> else : <EOL> return redirect ( url_for ( '<STR_LIT:index>' ) ) <EOL> return render_template ( '<STR_LIT>' ) </s>
