예제 #1
0
def update_contract_form(contract_id):
    """ 업로드폼에서 입력한 값들을 수정하기 위해 DB값을 읽어와 업로드폼 화면으로 전달한다. """
    
    contract = dao.query(Contract).filter_by(id=contract_id).first()
    form = ContractUploadForm(request.form, contract)
        
    return render_template('upload.html', contract=contract, form=form)
예제 #2
0
def unregist():
    user_id = session['user_info'].id

    try:
        user = dao.query(User).filter_by(id=user_id).first()
        Log.info("unregist:" + user.username)

        if user.id == user_id:
            dao.delete(user)
            # 업로드된 파일 삭제
            try:
                upload_folder = \
                    os.path.join(current_app.root_path,
                                 current_app.config['UPLOAD_FOLDER'])
                __delete_files(upload_folder, user.username)
            except Exception as e:
                Log.error("파일 삭제에 실패했습니다. : %s" + \
                          str(e))

            dao.commit()

        else:
            Log.error("존재하지 않는 사용자의 탈퇴시도 : %d", user_id)
            raise Exception

    except Exception as e:
        Log.error(str(e))
        dao.rollback()
        raise e

    return redirect(url_for('.logout'))
예제 #3
0
def __get_user(username):
    try:
        current_user = dao.query(User).\
                            filter_by(username=username).\
                            first()

        Log.debug(current_user)
        return current_user

    except Exception as e:
        Log.error(str(e))
        raise e
예제 #4
0
def get_contract_info(contract_id):
    """업로드된 계약서 관련 정보(다운로드 폴더, 파일명, 전체 파일 경로 등)을 얻는다.
       내부 함수인 __get_download_info()에 사용된다.
    """

    contract = dao.query(Contract).filter_by(id=contract_id).first()
    download_folder = \
        os.path.join(current_app.root_path,
                     current_app.config['UPLOAD_FOLDER'])
    download_filepath = os.path.join(download_folder, contract.filename)

    return (download_folder, contract.filename, download_filepath,
            contract.comment)
예제 #5
0
def show_all(page=1):

    user_id = session['user_info'].id
    per_page = current_app.config['PER_PAGE']

    contract_count = dao.query(Contract).count()
    pagination = Pagination(page, per_page, contract_count)

    if page != 1:
        offset = per_page * (page - 1)
    else:
        offset = 0

    contract_pages = dao.query(Contract). \
                        filter_by(user_id=user_id). \
                        order_by(Contract.upload_date.desc()). \
                        limit(per_page). \
                        offset(offset). \
                        all()

    return render_template('list.html',
                           pagination=pagination,
                           contracts=contract_pages,
                           sizeof_fmt=sizeof_fmt)
예제 #6
0
def login():
    """아이디/비밀번호 기반의 로그인 기능을 제공함
    로그인 성공 시 세션에 사용자 정보를 저장하여 사용함
    """

    form = LoginForm(request.form)
    next_url = form.next_url.data
    login_error = None

    if form.validate():
        session.permanent = True

        username = form.username.data
        password = form.password.data
        next_url = form.next_url.data

        Log.info('(%s)next_url is %s' % (request.method, next_url))

        try:
            user = dao.query(User). \
                filter_by(username=username). \
                first()

        except Exception as e:
            Log.error(str(e))
            raise e

        if user:
            if not check_password_hash(user.password, password):
                login_error = 'Invalid password'

            else:
                # 세션에 추가할 정보를 session 객체의 값으로 추가함
                # 가령, User 클래스 같은 사용자 정보를 추가하는 객체 생성하고
                # 사용자 정보를 구성하여 session 객체에 추가
                session['user_info'] = user

                if next_url != '':
                    return redirect(next_url)
                else:
                    return redirect(url_for('.index'))
        else:
            login_error = 'User does not exist!'

    return render_template('login.html',
                           next_url=next_url,
                           error=login_error,
                           form=form)
예제 #7
0
def search_contract():
    search_word = request.form['search_word']

    if (search_word == ''):
        return show_all()

    user_id = session['user_info'].id

    contracts=dao.query(Contract).filter_by(user_id=user_id). \
               filter(or_(Contract.filename_orig.like("%" + search_word + "%"),
                          Contract.upload_date.like("%" + search_word + "%"))). \
               order_by(Contract.upload_date.desc()).all()

    return render_template('list.html',
                           contracts=contracts,
                           sizeof_fmt=sizeof_fmt)
예제 #8
0
def update_contract(contract_id):
    """ 계약서 업로드 화면에서 사용자가 수정한 내용을 DB에 업데이트 한다. """

    form = ContractUploadForm(request.form)

    if form.validate(): 
        
        try :
            #: 변경전 원래의 contract 테이블 값을 읽어 온다.
            contract = dao.query(Contract).filter_by(id=contract_id).first()
            dao.commit()
    
        except Exception as e:
            dao.rollback()
            Log.error("Update DB error : " + str(e))
            raise e
    
        return redirect(url_for('.show_all'))
    else:
        return render_template('upload.html', contract=contract, form=form)
예제 #9
0
def remove(contract_id):
    """ DB에서 해당 데이터를 삭제하고 관련된 파일을 함께 삭제한다."""

    user_id = session['user_info'].id
    
    try:
        contract = dao.query(Contract).filter_by(id=str(contract_id)).first()
        
        dao.delete(contract)
        dao.commit()

        upload_folder = os.path.join(current_app.root_path, 
                                     current_app.config['UPLOAD_FOLDER'])
        os.remove(upload_folder + str(contract.filename))

    except Exception as e:
        dao.rollback()
        Log.error("Contract remove error => " + contract_id + ":" + user_id + \
                  ", " + str(e))
        raise e
    
    return redirect(url_for('.show_all'))