def download(template_type='xml'): current_app.jinja_env.filters['datetimeformat'] = datetimeformat try: templates = (db.session.query(Template).filter( Template.is_active == True, Template.type.has( TemplateType.download_type.has( DownloadType.code == template_type))).all()) contracts = Contracts().get_contracts(_config('lpu_infis_code')) obj = Departments(_config('lpu_infis_code')) departments = obj.get_departments() form_data = dict(templates=session.pop('templates', None), departments=session.pop('departments', None), start=session.pop('start', None), end=session.pop('end', None), contract_id=session.pop('contract_id', None), primary=session.pop('primary', None)) if not _config('mo_level'): flash( u'В <a href="{0}" class="text-error"><u>настройках</u></a> не задан уровень МО' .format(url_for('.settings'))) return render_template('{0}/download/index.html'.format(module.name), templates=templates, contracts=contracts, departments=departments, mo_level=_config('mo_level'), form_data=form_data) except TemplateNotFound: abort(404)
def _run_job(job_id=None, print_json=False): import json import sys from jobs import load_jobs from pprint import pprint enabled_jobs = _enabled_jobs() jobs = load_jobs() if job_id is None or len(job_id) == 0: job_ids = ' '.join(enabled_jobs) job_id = input('Name of the job to run [%s]: ' % (job_ids, )).lower() job_config = _config().get(job_id) if job_config is None: print('No config found for job: %s' % (job_id, )) sys.exit(1) cls = jobs.get(job_config.get('job_impl', job_id)) if cls is None: print('No such job: %s' % (job_id, )) sys.exit(1) job = cls(job_config) data = job.get() if print_json: print(json.dumps(data, indent=2)) else: pprint(data)
def _run_job(name=None, print_json=False): import json import sys from jobs import load_jobs from pprint import pprint jobs = load_jobs() if name is None or len(name) == 0: names = ' '.join(jobs.keys()) name = input('Name of the job to run [%s]: ' % (names,)).lower() cls = jobs.get(name) if cls is None: print('No such job: %s' % (name,)) sys.exit(1) job_conf = _config()['JOBS'].get(name) if job_conf is None: print('No config found for job: %s' % (name,)) sys.exit(1) job = cls(job_conf) data = job.get() if print_json: print(json.dumps(data, indent=2)) else: pprint(data)
def _run_job(job_id=None, print_json=False): import json import sys from jobs import load_jobs from pprint import pprint enabled_jobs = _enabled_jobs() jobs = load_jobs() if job_id is None or len(job_id) == 0: job_ids = ' '.join(enabled_jobs) job_id = input('Name of the job to run [%s]: ' % (job_ids,)).lower() job_config = _config().get(job_id) if job_config is None: print('No config found for job: %s' % (job_id,)) sys.exit(1) cls = jobs.get(job_config.get('job_impl', job_id)) if cls is None: print('No such job: %s' % (job_id,)) sys.exit(1) job = cls(job_config) data = job.get() if print_json: print(json.dumps(data, indent=2)) else: pprint(data)
def download_result(): result = list() errors = list() session['templates'] = template_ids = [ int(_id) for _id in request.form.getlist('templates[]') ] department_ids = [ int(_id) for _id in request.form.getlist('departments[]') if int(_id) ] session['departments'] = [ int(_id) for _id in request.form.getlist('departments[]') ] session['start'] = start = datetime.strptime(request.form['start'], '%d.%m.%Y') session['end'] = end = datetime.strptime(request.form['end'], '%d.%m.%Y') session['contract_id'] = contract_id = int(request.form.get('contract_id')) primary = bool(int(request.form.get('primary'))) session['primary'] = request.form.get('primary') #TODO: как-то покрасивее сделать? worker = DownloadWorker() try: result = worker.do_download(template_ids=template_ids, infis_code=_config('lpu_infis_code'), contract_id=contract_id, start=start, end=end, primary=primary, departments=department_ids) except ValueError, e: errors.append( u'Данных для выгрузки в заданный период не найдено (%s)' % e.message)
def reports(): start = None end = None files = dict() report = Reports() # if request.method == 'POST': # start = datetime.strptime(request.form['start'], '%d.%m.%Y') # end = datetime.strptime(request.form['end'], '%d.%m.%Y') data = report.get_bills(_config('lpu_infis_code')) for bill in data: files[bill.id] = get_files(DOWNLOADS_DIR, str(bill.id)) try: current_app.jinja_env.filters['datetimeformat'] = datetimeformat return render_template('{0}/reports/index.html'.format(module.name), data=data, files=files, form=Form()) except TemplateNotFound: abort(404)