コード例 #1
0
ファイル: views.py プロジェクト: backmeup/backmeup-frontend
def additional_context(request):
    context = {}

    if 'datasource_profile_id' in request.session:
        rest_datasource = RestDatasourceProfile(username=request.user.username)
        profile = rest_datasource.get(request.session['datasource_profile_id'])
        if 'identification' in profile:
            title = _(profile['pluginName'] + " - %(account)s") % {'account': profile['identification']}
        else:
            title = profile['title']
        profile['good_title'] = title
        context['datasource_profile'] = profile

    if 'datasink_profile_id' in request.session:
        rest_datasink = RestDatasinkProfile(username=request.user.username)
        profile = rest_datasink.get(request.session['datasink_profile_id'])
        if 'identification' in profile:
            title = _(profile['pluginName'] + " - %(account)s") % {'account': profile['identification']}
        else:
            title = profile['title']
        profile['good_title'] = title
        context['datasink_profile'] = profile

    context['search_form'] = SearchForm(request.POST or None)

    return context
コード例 #2
0
ファイル: views.py プロジェクト: backmeup/backmeup-frontend
def index(request):
    context = additional_context(request)
    if request.user.is_authenticated():

        ### delete job form start
        job_delete_form = JobDeleteForm(request.POST or None)
        if job_delete_form.is_valid():
            result = job_delete_form.rest_save(username=request.user.username)
            if result:
                messages.add_message(request, messages.SUCCESS, _(u'Backup was successfully deleted.'))
            else:
                messages.add_message(request, messages.ERROR, _(u'Backup couldn\'t be deleted.'))
        context['job_delete_form'] = job_delete_form

        rest_jobs = RestJobs(username=request.user.username)
        jobs = rest_jobs.get_all()
        #### delete job form end

        if jobs and 'errorType' in jobs:
            if jobs['errorType'] == 'org.backmeup.model.exceptions.UnknownUserException':
                logout(request)
                redirect('index')
            else:
                messages.error(request, _(jobs['errorMessage']))
                context['needs_email_validation'] = True
        else:
            rest_datasource_profile = RestDatasourceProfile(username=request.user.username)
            datasource_profiles = rest_datasource_profile.get_all()

            rest_datasink_profile = RestDatasinkProfile(username=request.user.username)
            datasink_profiles = rest_datasink_profile.get_all()

            for job in jobs:
                # need to cut of first 3 numbers to get valid unix timestamp
                if 'createDate' in job:
                    job['createDate'] = datetime.datetime.fromtimestamp(job['createDate']/1000)
                if 'startDate' in job:
                    job['startDate'] = datetime.datetime.fromtimestamp(job['startDate']/1000)
                if 'lastBackup' in job:
                    job['lastBackup'] = datetime.datetime.fromtimestamp(job['lastBackup']/1000)
                if 'nextBackup' in job:
                    job['nextBackup'] = datetime.datetime.fromtimestamp(job['nextBackup']/1000)
                if 'lastSuccessful' in job:
                    job['lastSuccessful'] = datetime.datetime.fromtimestamp(job['lastSuccessful']/1000)
                
                job['datasink']['title'] = get_sink_title(datasink_profiles, job['datasink']['datasinkId'])
                #job['datasources'] = []
                for datasource in job['datasources']:
                    datasource['title'] = get_source_title(datasource_profiles, datasource['datasourceId'])
            context['jobs'] = jobs

    return render_to_response(
        "www/index.html",
        context,
        context_instance=RequestContext(request))
コード例 #3
0
ファイル: views.py プロジェクト: backmeup/backmeup-frontend
def datasink_auth(request):
    if request.session['auth_data']['type'] == 'Input':
        # make sure 'requiredInputs' (= list of dicts) is sorted by 'order' dict value(s)
        request.session['auth_data']['requiredInputs'] = sorted(request.session['auth_data']['requiredInputs'], key=lambda k: k['order']) 
    
    exta_data = {
        'auth_data': request.session['auth_data'],
    }
    
    form = DatasinkAuthForm(request.POST or None, extra_data=exta_data)

    if not form.fields and request.session['auth_data']['type'] == 'Input':
        request.session['datasink_profile_id'] = request.session['auth_data']['profileId']
        return redirect('job-create')
    
    # the form won't be valid if auth type is OAuth
    # so form.is_valid() works for auth type Input only.
    if form.is_valid() or request.session['auth_data']['type'] == 'OAuth':
        data = {
            "keyRing": request.session['key_ring'],
        }
        
        if request.session['auth_data']['type'] == 'Input':
            for key in form.cleaned_data:
                if key.startswith('input_key_'):
                    value = form.cleaned_data[key.replace('input_key_', 'input_value_')]
                    data[form.cleaned_data[key]] = value
        elif request.session['auth_data']['type'] == 'OAuth':
            data.update(request.session['auth_data']['oauth_data'])
        
        rest_datasink_profile = RestDatasinkProfile(username=request.user.username)
        result = rest_datasink_profile.auth_post(profile_id=request.session['auth_data']['profileId'], data=data)
        
        if hasError(result):
            del result.session['auth_data']
            messages.add_message(request, messages.ERROR, getErrorMsg(result))
            return redirect('datasource-select')
        else:
            request.session['datasink_profile_id'] = request.session['auth_data']['profileId']
            del request.session['auth_data']
            return redirect('job-create')
        
    context = additional_context(request)
    context['form'] = form

    return render_to_response(
        "www/datasink_auth.html",
        context,
        context_instance=RequestContext(request))
コード例 #4
0
ファイル: views.py プロジェクト: backmeup/backmeup-frontend
def job_log(request, job_id):
    rest_jobs = RestJobs(username=request.user.username)
    job_status = rest_jobs.get_job_status(job_id=job_id)

    rest_jobs = RestJobs(username=request.user.username)
    jobs = rest_jobs.get_all()

    job = get_job(jobs, job_id=job_id)

    rest_datasource_profile = RestDatasourceProfile(username=request.user.username)
    datasource_profiles = rest_datasource_profile.get_all()

    rest_datasink_profile = RestDatasinkProfile(username=request.user.username)
    datasink_profiles = rest_datasink_profile.get_all()

    job['datasink']['title'] = get_sink_title(datasink_profiles, job['datasink']['datasinkId'])
    #job['datasources'] = []
    for datasource in job['datasources']:
        datasource['title'] = get_source_title(datasource_profiles, datasource['datasourceId'])
    log=job_status['backupStatus']
    for l in log:
	l['message']=l['message'].encode("utf-8")
	if 'timeStamp' in l:
		l['timeStamp'] = datetime.datetime.fromtimestamp(int(l['timeStamp'])/1000)
    context = {
        'job': job,
        'log': log,
    }
    try:
        context['current_status'] = job_status['backupStatus'][0]['type']
    except:
        pass

    return render_to_response(
        "www/job_log.html",
        context,
        context_instance=RequestContext(request))
コード例 #5
0
ファイル: views.py プロジェクト: backmeup/backmeup-frontend
def datasink_select(request):
    
    rest_datasink = RestDatasink()
    datasinks = rest_datasink.get_all()

    datasink_choices = []

    for item in datasinks:
        datasink_choices.append((item['datasinkId'], item['title']))
    
    rest_datasink_profile = RestDatasinkProfile(username=request.user.username)
    datasink_profiles = rest_datasink_profile.get_all()
    datasink_profile_choices = []
    if len(datasink_profiles):
        for item in datasink_profiles:
            # no need to show profiles without 'identification'
            # * it's not a completely authenticated profile
            # * it's a profile whitch doesn't require authentication
            if 'identification' in item:
                title = _(item['pluginName'] + " - %(account)s") % {'account': item['identification']}
                datasink_profile_choices.append( (item['datasinkProfileId'], title) )
    
    if len(datasink_profile_choices):
        datasink_profile_choices = [("", "---")] + datasink_profile_choices
    
    extra_data = {
        'datasink_choices': datasink_choices,
        'datasink_profile_choices': datasink_profile_choices,
    }
    
    form = DatasinkSelectForm(request.POST or None, extra_data=extra_data)
    if form.is_valid():
        
        if form.cleaned_data['datasink']:
            rest_datasink_profile = RestDatasinkProfile(username=request.user.username)
            profile_name = _("%(plugin)s - profile") % {'plugin': form.cleaned_data['datasink']}
            data = {
                "profileName": profile_name,
                "keyRing": request.session['key_ring'],
            }
            result = rest_datasink_profile.auth(datasink_id=form.cleaned_data['datasink'], data=data)
            
            if hasError(result):
                messages.add_message(request, messages.ERROR, getErrorMsg(result))
            else:
                request.session['auth_data'] = result
                if result['type'] == 'OAuth':
                    request.session['next_step'] = 'datasink-auth'
                    return redirect(result['redirectURL'])
                return redirect('datasink-auth')
        elif form.cleaned_data['datasink_profile']:
            request.session['datasink_profile_id'] = form.cleaned_data['datasink_profile']
            try:
                del request.session['auth_data']
            except Exception:
                pass
            return redirect('job-create')

    context = additional_context(request)
    context['form'] = form

    return render_to_response(
        "www/datasink_select.html",
        context,
        context_instance=RequestContext(request))