# Path: app/helpers/paging.py
# def get_paging(start, max_results, query=False, results_per_page=15, window_size=15):
# def get_paging_results(start, max_results, id, results, results_per_page):
# 
# Path: app/helpers/session.py
# def add_sessions_to_app(app):
# def get_session():
# def is_logged():
# def login(email):
# def logout():
# def reset():
# def get_user_id():
# def get_last_visited_url():
# def set_last_visited_url():
# def login_required(meth):
#     def new(*args):
# def login_required_for_reviews(meth):
#     def new(*l):
# 
# Path: app/models/applicants.py
# def get_where(context='', query=None, user_id=None):
# def query(context='', query=None, offset=0, limit=50, order='creation_ts desc', user_id=None):
# def get_by_id(id):
# def admit(ids, user_id):
# def reject(ids, user_id):
# def undecide(ids, user_id):
# def grant(user_id, id, amount):
# def add_comment(id, comment):
# def rate(ids, score):
# def get_counts():
# def get_by_secret_md5(secret_md5):
# def get_dummy_record():
# def get_stats():
# 
# Path: app/models/comments.py
# def add_comment(user_id, applicant_id, comment):
# def delete_comment(user_id, id):
# def get_comments(applicant_id):
# 
# Path: app/models/votes.py
# def add(ids, score, user_id):
# def update_calculated_votes(applicant_id):
# def get_votes(applicant_id):


import web
import config
from app.helpers import paging
from app.helpers import session
from app.models import applicants
from app.models import comments
from app.models import votes
from config import view
        i = web.input(context='', id=[])
        
        if i.id:
            applicants.undecide(i.id, session.get_user_id())
        raise web.seeother(web.ctx.environ['HTTP_REFERER'])

class rate:
    @session.login_required
    def POST(self):
        i = web.input(context='', id=[], score=[])
        score = web.intget(i.score[0] or i.score[1], '')
        
        if i.id and score:
#            applicants.rate(i.id, score, session.get_user_id())
            votes.add(i.id, score, session.get_user_id())
        raise web.seeother(web.ctx.environ['HTTP_REFERER'])

class comment:
    @session.login_required
    def POST(self, id):
        i = web.input(comment='')
        
        if i.id and i.comment:
            comments.add_comment(session.get_user_id(), id, i.comment)
        
        raise web.seeother(web.ctx.environ['HTTP_REFERER'])

class delete_comment:
    @session.login_required
    def GET(self, comment_id):

# Path: app/helpers/paging.py
# def get_paging(start, max_results, query=False, results_per_page=15, window_size=15):
# def get_paging_results(start, max_results, id, results, results_per_page):
# 
# Path: app/helpers/session.py
# def add_sessions_to_app(app):
# def get_session():
# def is_logged():
# def login(email):
# def logout():
# def reset():
# def get_user_id():
# def get_last_visited_url():
# def set_last_visited_url():
# def login_required(meth):
#     def new(*args):
# def login_required_for_reviews(meth):
#     def new(*l):
# 
# Path: app/models/applicants.py
# def get_where(context='', query=None, user_id=None):
# def query(context='', query=None, offset=0, limit=50, order='creation_ts desc', user_id=None):
# def get_by_id(id):
# def admit(ids, user_id):
# def reject(ids, user_id):
# def undecide(ids, user_id):
# def grant(user_id, id, amount):
# def add_comment(id, comment):
# def rate(ids, score):
# def get_counts():
# def get_by_secret_md5(secret_md5):
# def get_dummy_record():
# def get_stats():
# 
# Path: app/models/comments.py
# def add_comment(user_id, applicant_id, comment):
# def delete_comment(user_id, id):
# def get_comments(applicant_id):
# 
# Path: app/models/votes.py
# def add(ids, score, user_id):
# def update_calculated_votes(applicant_id):
# def get_votes(applicant_id):


# Path: app/controllers/actions.py
import web
import config
from app.helpers import paging
from app.helpers import session
from app.models import applicants
from app.models import comments
from app.models import votes
from config import view

        i = web.input(context='', id=[])
        
        if i.id:
            applicants.undecide(i.id, session.get_user_id())
        raise web.seeother(web.ctx.environ['HTTP_REFERER'])

class rate:
    @session.login_required
    def POST(self):
        i = web.input(context='', id=[], score=[])
        score = web.intget(i.score[0] or i.score[1], '')
        
        if i.id and score:
#            applicants.rate(i.id, score, session.get_user_id())
            votes.add(i.id, score, session.get_user_id())
        raise web.seeother(web.ctx.environ['HTTP_REFERER'])

class comment:
    @session.login_required
    def POST(self, id):
        i = web.input(comment='')
        
        if i.id and i.comment:
            comments.add_comment(session.get_user_id(), id, i.comment)
        
        raise web.seeother(web.ctx.environ['HTTP_REFERER'])

class delete_comment:
    @session.login_required
    def GET(self, comment_id):

        comments.delete_comment(session.get_user_id(), comment_id)