def get(apostile_id): apostile = session.query(Apostile).filter(Apostile.id == apostile_id).first() if not user_is_logged() and apostile.is_archived: return render_template('message.html', title='Не знайдено', msg=f'Апостиль не знайдено', **user_config()) document = session.query(Document).filter(Document.id == apostile.document_id).first() TrustedClass = TrustedInstitution if apostile.trusted_type == 'institution' else TrustedPerson trusted = session.query(TrustedClass).filter(TrustedClass.id == apostile.trusted_id).first().info() return render_template('apostile.html', title='Знайдено апостиль', **user_config(), doc=document, ap=apostile, tr=trusted)
def edit_holder(h_id): holder = session.query(User).filter(User.id == h_id).first() return render_template('update_holder.html', title='Редагування держателя', **user_config(), h=holder, redirect=request.args['redirect'])
def edit_trusted(table, tr_id): if table == 'person': tr = session.query(TrustedPerson).filter( TrustedPerson.id == tr_id).first() return render_template('update_trusted_person.html', title='Оновлення особи', **user_config(), redirect=request.args['redirect'], tr=tr) else: tr = session.query(TrustedInstitution).filter( TrustedInstitution.id == tr_id).first() return render_template('update_trusted_institution.html', title='Оновлення організації', **user_config(), redirect=request.args['redirect'], tr=tr)
def list_all(): per_page = 10 page = int(request.args.get('page', 1)) query = request.args.get('search', '').lower() apostiles = [a for a in session.query(Apostile).all() if query in str(a.number) or (query in query in 'доступний' and not a.is_archived) or (query in query in 'заархівований' and a.is_archived)] return render_template('apostiles.html', title='Апостилі', **user_config(), s=query, aps=apostiles[ per_page * ( page - 1):per_page * page], pages=[page, ceil(len(apostiles) / per_page)])
def search(): id_, date_ = request.form['id'], request.form['date'] if user_is_logged(): cond = and_(Apostile.number == id_, Apostile.date == date_) else: cond = and_(Apostile.number == id_, Apostile.date == date_, Apostile.is_archived == False) apostile = session.query(Apostile).filter(cond).first() if apostile: return redirect(f'/apostile/{apostile.id}') return render_template('message.html', title='Не знайдено', msg=f'Апостиль №{id_} від {date_} не знайдено', **user_config())
def list_all_trs(): per_page = 5 page = int(request.args.get('page', 1)) query = request.args.get('search', '').lower() trs = list(session.query(TrustedInstitution).all()) + list( session.query(TrustedPerson).all()) trs = [t.info() for t in trs] trs = [t for t in trs if query.lower() in ''.join(t.values()).lower()] trs = sorted(trs, key=lambda t: t['person_name']) return render_template('trusteds.html', title='Завірятелі', **user_config(), s=query, trs=trs[per_page * (page - 1):per_page * page], pages=[page, ceil(len(trs) / per_page)], url=request.url)
def create_holder_post(): count = session.query(User).filter( User.email == request.form['email']).count() if count: return render_template( 'message.html', title='Помилка', msg=f'Користувач з поштою {request.form["email"]} уже існує', **user_config()) holder = User(email=request.form['email'], name=request.form['name'], password_hash=request.form['pass'], role='holder', is_active=True, created_at=datetime.date.today()) session.add(holder) session.commit() return redirect('/holder')
def get_all_holders(): per_page = 5 page = int(request.args.get('page', 1)) query = request.args.get('search', '').lower() holders = session.query(User).filter(User.role == 'holder').all() holders = [ h for h in holders if query in h.name.lower() or query in h.email.lower() ] holders = sorted(holders, key=lambda h: h.name) return render_template('holders.html', title='Держателі', **user_config(), s=query, holders=holders[per_page * (page - 1):per_page * page], pages=[page, ceil(len(holders) / per_page)], url=request.url)
def create_institution(): return render_template('create_trusted_institution.html', title='Нова довірена особа', **user_config())
def apostile_create_post(): count = session.query(Apostile).filter(Apostile.number == int(request.form['number'])).count() if count: return render_template('message.html', title='Помилка', msg=f'Апостиль з номером {request.form["number"]} уже існує', **user_config()) doc = Document( country=request.form['country'], date=request.form['doc_date'], author_name=request.form['person_name'], author_info=request.form['person_position'], stamp_info=request.form['stamp_info'] if request.form['stamp_info'] else '-/-/-' ) session.add(doc) session.flush() tr_id, tr_type = find_trusted_by_str(request.form['ap_author']) ap = Apostile( number=int(request.form['number']), date=request.form['ap_date'], is_archived=False, trusted_id=tr_id, trusted_type=tr_type, document_id=doc.id ) session.add(ap) session.flush() session.commit() return redirect(f'/apostile/{ap.id}')
def apostile_create(): trs = list(session.query(TrustedInstitution).filter(TrustedInstitution.is_archived == False).all()) + \ list(session.query(TrustedPerson).filter(TrustedPerson.is_archived == False).all()) trs = sorted([tr.short() for tr in trs]) return render_template('create_apostile.html', title='Сворення апостилю', **user_config(), trs=trs)
def index(): return render_template('index.html', title='Пошук апостилів', **user_config())
def create_holder(): return render_template('create_holder.html', title='Новий держатель', **user_config())