예제 #1
0
파일: views.py 프로젝트: dlanger/canary
def serve_redirects(redirect_code):
    """
    Serve a redirect.
    
    If a valid redirect code is supplied, redirect the client to the target_url
    of the redirect, and then queue up (to keep out of request stream time) 
    storing that visit. If an invalid code, 404.
    
    """
    try:
        target_redirect = RedirectModel.all() \
                            .filter('hashed_key = ', redirect_code) \
                            .filter('enabled = ', True).fetch(1)
    except (Error, CapabilityDisabledError), e:
        logging.error("Database error when loading redirect - ", e)
        return render_template('500.html'), 500
예제 #2
0
파일: views.py 프로젝트: dlanger/canary
def list_redirects():
    """
    List all redirects belonging to the current user.
    
    Search by user_id (as opposed to user), since the latter can change
    if someone changes their gmail address mid-session.
    
    """
    current_user = users.get_current_user()
    try:
        redirects = RedirectModel.all() \
                        .order('-enabled').order('-modified') \
                        .filter("user_id =", current_user.user_id())
    except (Error, CapabilityDisabledError), e:
        logging.error("Database error when loading list of redirects - ", e)
        return render_template('500.html'), 500
예제 #3
0
파일: views.py 프로젝트: dlanger/canary
def edit_redirect(redirect_code):
    """
    API endpoint to update information about a redirect.
    
    Changes some aspect of the redirect, and returns the success of that 
    change by the response code (400 if trying to edit a redirect that
    doesn't exist or a bad change, 500 if there's a problem with editing, 
    200 if OK).
    
    """
    try:
        target_redirect = RedirectModel.all().filter('hashed_key = ', \
            redirect_code).fetch(1)
    except (Error, CapabilityDisabledError), e:
        logging.error("Database error when loading redirect - ", e)
        return render_template('none.html'), 500
예제 #4
0
파일: views.py 프로젝트: dlanger/canary
def list_visits(redirect_code):
    """
    List all visits to a redirect.
    
    Returns a JSON object that contains all information about visits to the
    redirect specified in the URL. By default returns default_results_returned
    results, but this can be overridden with the records query parameter.
    
    """
    default_results_returned = 10    
    current_user = users.get_current_user()
    try:
        target_redirect = RedirectModel.all() \
            .filter("user_id = ", current_user.user_id()) \
            .filter("hashed_key = ", redirect_code).fetch(1)      
    except (Error, CapabilityDisabledError), e:
        logging.error("Database error when loading list of visits - ", e)
        return render_template('none.html'), 500