Example #1
0
def picker(request):
    """
        Uhm.
    """
    PARENT_FOLDER_ID = settings.GOOGLE_DRIVE_ROOT_FOLDER_ID
    drive = Drive()
    token = Drive.get_access_token()
    return render_to_response('pages/picker.html',locals(), context_instance=global_context(request))
Example #2
0
def google_refresh_token(request):
    '''
        A one time view to get a refresh token from google
    '''
    FLOW = Drive.create_flow()
    FLOW.params['state'] = xsrfutil.generate_token(settings.SECRET_KEY, request.user)
    authorize_url = FLOW.step1_get_authorize_url()
    return HttpResponseRedirect(authorize_url)
Example #3
0
def google_auth_callback(request):
    '''
        Auth Callback to save the given google_api_credentials json into a file for later use
    '''
    FLOW = Drive.create_flow()
    if not xsrfutil.validate_token(settings.SECRET_KEY, request.REQUEST['state'], request.user):
        return  HttpResponseBadRequest()
    credential = FLOW.step2_exchange(request.REQUEST)
    # Store to file
    docs_client_json = str(credential.to_json())
    file_path = settings.GOOGLE_API_CREDENTIALS_FILE_PATH
    with open(file_path, 'w') as f:
        f.write(docs_client_json)

    return HttpResponse("Restart your server for google drive to work.")
Example #4
0
def global_context(request, token_info=True, user_info=True):
    """
        Some basic variables useful in templates
        Usage : add context_instance=global_context(request) to the kwargs of the response function
    """
    erp_profile = None
    profile = None
    if user_info:
    	erp_profile = request.user.erp_profile if hasattr(request.user, "erp_profile") else None
    	if hasattr(request.user, "profile"):
        	profile = request.user.profile 
    	else:
        	profile = None
    token = None
    if token_info and settings.USE_GOOGLE_DRIVE:
    	drive = Drive()
    	token = Drive.get_access_token()
    local_context = {
        'user' : request.user,
        'erp_profile' : erp_profile,
        'user_profile' : profile,
        'session' : request.session,
        'google_access_token' : token,
        'experimental' : settings.EXPERIMENTAL_MODE,
        'SITE_URL' : settings.SITE_URL,
        'FEST_NAME' : settings.FEST_NAME,
        'SETTINGS' : settings,
    }

    # Handle experimental mode.
    if 'experimental' in request.GET.keys(): # Take from get
        request.session['experimental'] = request.GET['experimental']
    if ('experimental' in request.session.keys()): # Take from preset value
        local_context['experimental'] = request.session['experimental']
    print local_context["experimental"]
    context =  RequestContext(request, local_context)
    return context