Beispiel #1
0
def home(request):
    if not request.user.is_authenticated():
        return HttpResponseRedirect(reverse('account.views.login_page', args=[]))
    profile = request.user.profile
    try:
        profile.evernote_token = request.session['oauth_token']
        profile.evernote_token_expires_time = request.session['expires']
        profile.evernote_shard = request.session['edam_shard']
        profile.evernote_uid = request.session['edam_userId']
        profile.save()
        del request.session['oauth_token']
        del request.session['expires']
        del request.session['edam_shard']
        del request.session['edam_userId']
    except KeyError:
        pass
    if profile.evernote_token == "" \
            or profile.evernote_token_expires_time < datetime.now():
        everAuth = EvernoteAPI()
        callback_url = request.build_absolute_uri(everAuth.token_callback_url)
        return everAuth.get_token(request, callback_url)
    everAPI = EvernoteAPI(profile.evernote_token, profile.evernote_shard)
    allnotes = everAPI.get_notes_with_tag("evervim")
    allnotes = [{'title': n.title, 'id': n.guid} for n in allnotes]
    return render_to_response('home.html', {'notes': allnotes},
            context_instance=RequestContext(request))
Beispiel #2
0
def home(request):
    extra_data = request.user.social_auth.all()[0].extra_data
    evernote_api = EvernoteAPI(extra_data['oauth_token'], extra_data['store_url'])
    shard_url = '/'.join(extra_data['store_url'].split('/')[:-1])
    
    INIT_LOAD_SIZE = 18
    note_offset, resource_offset, image_guids = evernote_api.get_image_resource_guids(0, 0, INIT_LOAD_SIZE)
    
    no_more_images = False
    if len(image_guids) != INIT_LOAD_SIZE:
        no_more_images = True
        
    return render_to_response('home.html', dict(note_offset=note_offset, resource_offset=resource_offset,
                                                image_guids=image_guids, shard_url=shard_url,
                                                token=extra_data['oauth_token'], no_more_images=no_more_images))
Beispiel #3
0
def load_more(request, note_offset, resource_offset):
    if not request.user.is_authenticated():
        return HttpResponseForbidden('')
    
    note_offset, resource_offset = map(int, [note_offset, resource_offset])
    extra_data = request.user.social_auth.all()[0].extra_data
    evernote_api = EvernoteAPI(extra_data['oauth_token'], extra_data['store_url'])
    shard_url = '/'.join(extra_data['store_url'].split('/')[:-1])
    
    LOAD_SIZE = 12
    note_offset, resource_offset, image_guids = evernote_api.get_image_resource_guids(note_offset, resource_offset, LOAD_SIZE)
    if len(image_guids) == 0:
        return HttpResponse('', content_type="text/plain")
    
    no_more_images = False
    if len(image_guids) < LOAD_SIZE:
        no_more_images = True
    
    rows = get_template('rows.html').render(Context(dict(token=extra_data['oauth_token'], shard_url=shard_url, image_guids=image_guids)))
    json = simplejson.dumps(dict(note_offset=note_offset, resource_offset=resource_offset, rows=rows, no_more_images=no_more_images))
    return HttpResponse(json, mimetype='application/json')
Beispiel #4
0
def home(request):
    if not request.user.is_authenticated():
        return HttpResponseRedirect(
            reverse('account.views.login_page', args=[]))
    profile = request.user.profile
    try:
        profile.evernote_token = request.session['oauth_token']
        profile.evernote_token_expires_time = request.session['expires']
        profile.evernote_shard = request.session['edam_shard']
        profile.evernote_uid = request.session['edam_userId']
        profile.save()
        del request.session['oauth_token']
        del request.session['expires']
        del request.session['edam_shard']
        del request.session['edam_userId']
    except KeyError:
        pass
    if profile.evernote_token == "" \
            or profile.evernote_token_expires_time < datetime.now():
        everAuth = EvernoteAPI()
        callback_url = request.build_absolute_uri(everAuth.token_callback_url)
        return everAuth.get_token(request, callback_url)
    everAPI = EvernoteAPI(profile.evernote_token, profile.evernote_shard)
    allnotes = everAPI.get_notes_with_tag("evervim")
    allnotes = [{'title': n.title, 'id': n.guid} for n in allnotes]
    return render_to_response('home.html', {'notes': allnotes},
                              context_instance=RequestContext(request))
Beispiel #5
0
def get_evernote_token(request):
    """ View that handles the callback from the Evernote OAuth call and
        stores the OAuth token for the user
    """
    if request.user.is_authenticated:
        everAuth = EvernoteAPI()
        credentials = everAuth.get_user_token(request)
        """ credentials is of the form: { 'oauth_token': token,
                                          'expires'    : datetime,
                                          'edam_shard' : shard,
                                          'edam_userId': uid }
        """                        
        try:
            expires_time = datetime.fromtimestamp(int(credentials['expires']))
        except TypeError:
            logging.error("Error parsing token expires time")
            expires_time = datetime.now()
        request.session['oauth_token'] = credentials['oauth_token']
        request.session['expires'] = expires_time
        request.session['edam_shard'] = credentials['edam_shard']
        request.session['edam_userId'] = credentials['edam_userId']
    return HttpResponseRedirect(settings.EVERNOTE_OAUTH_COMPLETE_URL)
Beispiel #6
0
def get_evernote_token(request):
    """ View that handles the callback from the Evernote OAuth call and
        stores the OAuth token for the user
    """
    if request.user.is_authenticated:
        everAuth = EvernoteAPI()
        credentials = everAuth.get_user_token(request)
        """ credentials is of the form: { 'oauth_token': token,
                                          'expires'    : datetime,
                                          'edam_shard' : shard,
                                          'edam_userId': uid }
        """
        try:
            expires_time = datetime.fromtimestamp(int(credentials['expires']))
        except TypeError:
            logging.error("Error parsing token expires time")
            expires_time = datetime.now()
        request.session['oauth_token'] = credentials['oauth_token']
        request.session['expires'] = expires_time
        request.session['edam_shard'] = credentials['edam_shard']
        request.session['edam_userId'] = credentials['edam_userId']
    return HttpResponseRedirect(settings.EVERNOTE_OAUTH_COMPLETE_URL)