def home(request):
    """
    Controller for the app home page.
    """

    text_input_options = TextInput(name='urls_url',
                                   icon_append='glyphicon glyphicon-link',

                                   )

    if request.POST and 'urls_url' in request.POST:
        urls_url = request.POST['urls_url']

        # configure and submit condor job
        jm = app.get_job_manager()
        job_name = 'SSW Download-%s' % time.time()
        job_description = _get_description(urls_url)
        job = jm.create_job(job_name, request.user, 'ssw_download', description=job_description)
        job.set_attribute('arguments', '"%s $(job_name).nc"' % (urls_url, ))
        # job.set_attribute('arguments', [urls_url, '%s.nc' % job.name])
        job.execute()

        # redirect to jobs page
        return redirect('jobs/')

    context = {'text_input_options': text_input_options}

    return render(request, 'ssw_downloader/home.html', context)
def _get_job(job_id):
    jm = app.get_job_manager()
    job = jm.get_job(job_id)

    file_name = '%s.nc' % job.condorpy_job.job_name
    file_path = os.path.join(job.initial_dir, file_name)

    return job, file_name, file_path

# def _can_convert():
#     hm = app.get_handoff_manager()
#     app_name = 'netcdf_to_gssha'
#     handler_name = 'convert-netcdf'
#     capabilities = hm.get_capabilities(app_name)
#     for handler in capabilities:
#         if handler.name == handler_name:
#             return True
def jobs(request):
    """
    Controller for the jobs page.
    """

    jm = app.get_job_manager()

    jobs = jm.list_jobs(request.user)

    jobs_table_options = JobsTable(jobs=jobs,
                                   column_fields=('id', 'description', 'run_time'),
                                   hover=True,
                                   striped=False,
                                   bordered=False,
                                   condensed=False,
                                   results_url='ssw_downloader:results',
                                   )

    context = {'jobs_table_options': jobs_table_options}

    return render(request, 'ssw_downloader/jobs.html', context)