示例#1
0
    def __init__(self, *args, **kwargs):
        self.extra_data = kwargs.pop('extra_data')
        super(JobCreateForm, self).__init__(*args, **kwargs)
        
        rest_datasource_profile = RestDatasourceProfile(username=self.extra_data['username'])
        result = rest_datasource_profile.options(profile_id=self.extra_data['datasource_profile_id'], 
            data={'keyRing': self.extra_data['key_ring']})
        
        if result and 'sourceOptions' in result:
            for i, item in enumerate(result['sourceOptions']):
                self.fields['datasource_options_value_%s' % i] = forms.BooleanField(label=item, required=False)
                self.fields['datasource_options_key_%s' % i] = forms.CharField(widget=forms.HiddenInput, initial=item)
        
        rest_actions = RestAction()
        actions = rest_actions.get_all()
        
        for i, action in enumerate(actions):
            if action.get('visibility', "") == "job":
                action['options'] = rest_actions.options(action_id=action['actionId'])
            
                self.fields['actions_value_%d' % i] = forms.BooleanField(label=_(action['title']), required=False, help_text=_(action['description']))
                self.fields['actions_key_%d' % i] = forms.CharField(widget=forms.HiddenInput, initial=action['actionId'])
            
                for j, option in enumerate(action['options']):
                    self.fields['actions_value_%d_option_%d' % (i, j)] = forms.CharField(label=_(option), required=False, widget=forms.PasswordInput)
		    self.fields['actions_value_%d_option_%d' % (i, j)].initial = ""
                    self.fields['actions_key_%d_option_%d' % (i, j)] = forms.CharField(widget=forms.HiddenInput, initial=option)
示例#2
0
def job_edit(request, job_id):
    rest_jobs = RestJobs(username=request.user.username)
    job = rest_jobs.get(job_id=job_id)
    
    datasource_profile_id = job['sourceProfiles'][0]['id']
    datasink_profile_id = job['sinkProfileId']
    
    rest_datasource_profile = RestDatasourceProfile(username=request.user.username)
    datasource_profile_options = rest_datasource_profile.options(profile_id=datasource_profile_id, 
        data={'keyRing': request.session['key_ring']})['sourceOptions']
    
    rest_actions = RestAction()
    actions = rest_actions.get_all()
    
    for action in actions:
        action['options'] = rest_actions.options(action_id=action['actionId'])
        action['checked'] = False
        
        for job_action in job['actions']:
            if job_action['id'] == action['actionId']:
                action['checked'] = True
    
    extra_data = {
        'job': job,
        'datasource_profile_options': datasource_profile_options,
        'actions': actions,
    }
    
    form = JobEditForm(request.POST or None, extra_data=extra_data)
    
    if form.is_valid():
        new_source_options = []
        new_actions = []

        for key in form.cleaned_data:

            if key.startswith('datasource_options_value_') and form.cleaned_data[key]:
                new_source_options.append(form.cleaned_data[key.replace('_value_', '_key_')])

            if key.startswith('actions_value_') and form.cleaned_data[key]:
                value = form.cleaned_data[key.replace('_value_', '_key_')]
                new_actions.append(value)

        rest_jobs = RestJobs(username=request.user.username)
        data = {
            "keyRing": request.session['key_ring'],
            'timeExpression': form.cleaned_data['time_expression'],
            'sourceProfiles': datasource_profile_id,
            'sinkProfileId': datasink_profile_id,
            'jobTitle': form.cleaned_data['title'],
            'actions': new_actions,
        }
        for item in new_source_options:
            params_key = str(data['sourceProfiles']) + "." + item
            data[params_key] = "true"
        job_result = rest_jobs.put(job_id=job_id ,data=data)
        if hasError(job_result):
            messages.add_message(request, messages.ERROR, getErrorMsg(job_result))
        else:
            return redirect('index')
    
    return render_to_response("www/job_edit.html", {
        'form': form,
    }, context_instance=RequestContext(request))