コード例 #1
0
    def get(self, post_id):
        post = models.PostPublic.query.get(post_id)

        if not post:
            return flask.abort(404)

        if flask_login.current_user.id != post.writer_id:
            return flask.Response(flask.render_template(
                '403.html', form=forms.LoginForm()),
                                  mimetype='text/html',
                                  status=403)

        if not flask.request.MOBILE:
            return flask.Response(flask.render_template(
                'sub5.html',
                m_num=5,
                s_num=post.boardpublic_id,
                mode='modify',
                post=post,
                board=models.BoardPublic.query.get(post.boardpublic_id),
                form=forms.LoginForm()),
                                  mimetype='text/html')
        else:
            return flask.Response(flask.render_template(
                'mobile/sub5.html',
                m_num=5,
                s_num=post.boardpublic_id,
                mode='modify',
                post=post,
                board=models.BoardPublic.query.get(post.boardpublic_id),
                form=forms.LoginForm()),
                                  mimetype='text/html')
コード例 #2
0
    def get(self):
        board_parser = reqparse.RequestParser()
        board_parser.add_argument('board', type=int, required=True)
        args = board_parser.parse_args()
        board = models.BoardPublic.query.get(args['board'])
        if not board:
            return flask.abort(404)
        if (login.current_user.username not in admin_views.ADMIN_USERS
                and board.id in (1, 2, 3)):
            return flask.abort(403)

        if not flask.request.MOBILE:
            return flask.Response(flask.render_template(
                'sub5.html',
                m_num=5,
                s_num=args['board'],
                mode='write',
                board=board,
                form=forms.LoginForm()),
                                  mimetype='text/html')
        else:
            return flask.Response(flask.render_template(
                'mobile/sub5.html',
                m_num=5,
                s_num=args['board'],
                mode='write',
                board=board,
                form=forms.LoginForm()),
                                  mimetype='text/html')
コード例 #3
0
def VisionMentoringConfirm():
    key = flask.request.args.get('key')
    if not key:
        flask.abort(404)
    if flask_login.current_user.is_anonymous(
    ) or not flask_login.current_user.ismember:
        return flask.render_template('vm.html', form=forms.LoginForm())
    return flask.render_template('vm_confirm.html',
                                 form=forms.LoginForm(),
                                 key=key)
コード例 #4
0
def Main(template):
    banners = models.Banner.query.order_by(models.Banner.id.desc()).all()

    boardpublic_ids = [1, 2, 4, 5]
    # 1 : Notice, 2 : News, 4 : Freeboard, 5 : Q&A

    board_recents = list()
    boards = list()

    for bid in boardpublic_ids:
        board = models.BoardPublic.query.get(bid)
        if not board:
            continue
        boards.append(board)
        board_recents.append(
            db.session.query(
                models.PostPublic).filter_by(boardpublic_id=bid).order_by(
                    models.PostPublic.timestamp.desc()).limit(5).all())

    for recent_posts in board_recents:
        for post in recent_posts:
            now = datetime.datetime.utcnow()
            post.date = post.timestamp.strftime('%m.%d')
            if now - post.timestamp < datetime.timedelta(days=3):
                post.new = True

    return flask.render_template(template,
                                 bannerRec=banners,
                                 boardRec=board_recents,
                                 boards=boards,
                                 form=forms.LoginForm())
コード例 #5
0
def Login():
    form = forms.LoginForm()
    if form.validate_on_submit():
        flask_login.login_user(form.user)
        if flask_login.current_user.ismember:

            if not flask_login.current_user.last_mod:
                flask.flash('회원정보 수정내역이 없습니다. 정보를 업데이트해주세요.')
            elif datetime.datetime.utcnow(
            ) - flask_login.current_user.last_mod > datetime.timedelta(
                    days=90):
                flask.flash('회원정보를 수정한 지 90일이 지났습니다. 정보를 업데이트해주세요.')

            if flask.request.host in [
                    'gongwoo.snu.ac.kr', 'eng-stem.snu.ac.kr',
                    'honor.snu.ac.kr'
            ]:
                if flask.request.referrer.find('/stem/') > -1:
                    return flask.redirect(flask.request.referrer)
                else:
                    return flask.redirect('/stem')
            else:
                return flask.redirect('/stem')

        return flask.redirect('/')

    return flask.render_template('member/login.html', form=form)
コード例 #6
0
def ShowSub(sub):
    m_num = sub[0]
    s_num = sub[2]
    if m_num == '5':
        return flask.redirect('/sub/' + sub + '/1')  # showBoard(sub, 1)
    elif m_num == '2' and s_num == '5':
        year = datetime.date.today().year
        return flask.redirect('/sub/2-5/%d' % year)
    if not flask.request.MOBILE:
        return flask.render_template('sub' + m_num + '_' + s_num + '.html',
                                     current=member_help.Current(),
                                     m_num=int(m_num),
                                     s_num=int(s_num),
                                     form=forms.LoginForm())
    else:
        return flask.render_template('mobile/sub' + m_num + '_' + s_num +
                                     '.html',
                                     current=member_help.Current(),
                                     m_num=int(m_num),
                                     s_num=int(s_num),
                                     form=forms.LoginForm())
コード例 #7
0
def StemApply():
    fout = open('apply_log.log', 'a+')
    fout.write('Page viewed on ' +
               datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') + '\n')
    if datetime.datetime.now() < datetime.datetime(2016, 3, 10):
        display = 1
    else:
        display = 2
    fout.close()
    return flask.render_template('apply.html',
                                 form=forms.LoginForm(),
                                 display=display)
コード例 #8
0
def ShowHistory(sub, page):
    m_num = sub[0]
    s_num = sub[2]

    year = datetime.date.today().year
    years = list(range(2010, year + 1))
    if page not in years:
        page = year
    start = datetime.datetime(page, 1, 1, tzinfo=pytz.utc)
    end = datetime.datetime(page, 12, 31, tzinfo=pytz.utc)
    all_records = db.session.query(models.History).filter(
        models.History.starttime.between(start, end)).order_by(
            models.History.starttime).all()

    for post in all_records:
        post.period = post.starttime.strftime('%m.%d')
        if post.endtime:
            end_date = datetime.datetime.utcfromtimestamp(float(post.endtime))
            post.period = post.period + ' ~ ' + end_date.strftime('%m.%d')

    if not flask.request.MOBILE:
        return flask.render_template('sub2_5.html',
                                     mNum=int(m_num),
                                     sNum=int(s_num),
                                     form=forms.LoginForm(),
                                     years=years,
                                     page=page,
                                     history=all_records,
                                     admin_users=admin_views.ADMIN_USERS)
    else:
        return flask.render_template('mobile/sub2_5.html',
                                     mNum=int(m_num),
                                     sNum=int(s_num),
                                     form=forms.LoginForm(),
                                     years=years,
                                     page=page,
                                     history=all_records,
                                     admin_users=admin_views.ADMIN_USERS)
コード例 #9
0
def Register():
    if not flask_login.current_user.is_anonymous():
        return flask.abort(403)

    registerform = forms.RegisterForm()
    form = forms.LoginForm()
    if registerform.validate_on_submit():
        flask_login.login_user(registerform.user)
        if flask_login.current_user.ismember:
            flask.flash('가입을 축하드립니다. 회원님의 정보를 업데이트해주세요.')
        return flask.redirect('/')
    else:
        if not flask.request.MOBILE:
            return flask.render_template('member/register.html',
                                         registerform=form,
                                         form=form)
        else:
            return flask.render_template('mobile/member/register.html',
                                         registerform=form,
                                         form=form)
コード例 #10
0
def ViewPost(post_id):
    post = models.PostPublic.query.get(post_id)
    if not post or not post.boardpublic:
        return flask.abort(404)
    #    if post.boardpublic_id == 5 and not flask_login.current_user.ismember:
    #        return flask.abort(403)
    if post.hidden:
        if flask_login.current_user.is_anonymous():
            return flask.abort(403)
        elif not (
            (flask_login.current_user.id == post.writer_id) or
            (flask_login.current_user.username in admin_views.ADMIN_USERS)):
            return flask.abort(404)
    post.hitCount = post.hitCount + 1
    board = models.BoardPublic.query.get(post.boardpublic_id)
    db.session.commit()
    prev_post = models.PostPublic.query.filter(
        and_(
            models.PostPublic.id < post_id,
            models.PostPublic.boardpublic_id == post.boardpublic_id)).order_by(
                models.PostPublic.timestamp.desc()).first()
    next_post = models.PostPublic.query.filter(
        and_(
            models.PostPublic.id > post_id,
            models.PostPublic.boardpublic_id == post.boardpublic_id)).order_by(
                models.PostPublic.timestamp.asc()).first()

    return flask.render_template(
        'mobile/sub5.html' if flask.request.MOBILE else 'sub5.html',
        m_num=5,
        s_num=post.boardpublic_id,
        mode='view',
        post=post,
        board=board,
        prev=prev_post,
        next=next_post,
        form=forms.LoginForm(),
        admin_users=admin_views.ADMIN_USERS)
コード例 #11
0
    def post(self, post_id):
        post_parser = reqparse.RequestParser()
        post_parser.add_argument('title', type=str)
        post_parser.add_argument('body', type=str)

        args = post_parser.parse_args()
        post = models.PostPublic.query.get(post_id)

        if not post:
            return flask.abort(404)


#        if post.boardpublic_id == 5 and not flask_login.current_user.ismember:
#            return flask.abort(403)

        if flask_login.current_user.id != post.writer_id:
            return flask.Response(flask.render_template(
                'sub5_%d.html' % post.boardpublic_id,
                m_num=5,
                s_num=post.boardpublic_id,
                mode='view',
                post=post,
                board=models.BoardPublic.query.get(post.boardpublic_id),
                form=forms.LoginForm()),
                                  mimetype='text/html')

        post.title = args['title']
        post.body = args['body']

        files = flask.request.files.getlist('files')

        for file in files:
            helper.process_file(file, post)

        db.session.commit()

        return flask.redirect(flask.url_for('viewPost', id=id))
コード例 #12
0
def NotFound2():
    return flask.render_template('404.html', form=forms.LoginForm()), 404
コード例 #13
0
def Forbidden(unused_e):
    return flask.render_template('403.html', form=forms.LoginForm()), 403
コード例 #14
0
def Unauthorized(unused_e):
    return flask.render_template('member/login.html', form=forms.LoginForm())
コード例 #15
0
def ShowBoard(sub, page):
    m_num = sub[0]
    s_num = sub[2]
    searchform = forms.SearchForm()
    if m_num == '5':
        if s_num == '3':
            flask.abort(404)

        pagenation = models.PostPublic.query.filter_by(
            boardpublic_id=int(s_num)).order_by(
                models.PostPublic.timestamp.desc()).paginate(page, per_page=10)

        if searchform.search.data == 'title':
            pagenation = models.PostPublic.query.filter(
                and_(
                    models.PostPublic.boardpublic_id == int(s_num),
                    models.PostPublic.title.contains(
                        searchform.searchstr.data))).order_by(
                            models.PostPublic.timestamp.desc()).paginate(
                                page, per_page=10)
        elif searchform.search.data == 'writer':
            user_id = models.User.query.filter(
                models.User.nickname == searchform.searchstr.data).first()
            if user_id is not None:
                user_id = user_id.id
            else:
                user_id = '-1'
            pagenation = models.PostPublic.query.filter(
                and_(models.PostPublic.boardpublic_id == int(s_num),
                     models.PostPublic.writer_id == user_id)).order_by(
                         models.PostPublic.timestamp.desc()).paginate(
                             page, per_page=10)
        elif searchform.search.data == 'content':
            pagenation = models.PostPublic.query.filter(
                and_(
                    models.PostPublic.boardpublic_id == int(s_num),
                    models.PostPublic.body.contains(
                        searchform.searchstr.data))).order_by(
                            models.PostPublic.timestamp.desc()).paginate(
                                page, per_page=10)

        board = models.BoardPublic.query.get(int(s_num))
        limit = datetime.datetime.utcnow() - datetime.timedelta(days=5)

        if not board:
            flask.abort(404)

        if not flask.request.MOBILE:
            return flask.render_template('sub' + m_num + '.html',
                                         page=page,
                                         totalpage=pagenation.pages,
                                         posts=pagenation.items,
                                         board=board,
                                         m_num=int(m_num),
                                         s_num=int(s_num),
                                         limit=limit,
                                         form=forms.LoginForm(),
                                         searchform=searchform,
                                         admin_users=admin_views.ADMIN_USERS)
        else:
            return flask.render_template('/mobile/sub' + m_num + '.html',
                                         page=page,
                                         totalpage=pagenation.pages,
                                         posts=pagenation.items,
                                         board=board,
                                         m_num=int(m_num),
                                         s_num=int(s_num),
                                         limit=limit,
                                         form=forms.LoginForm(),
                                         searchform=searchform,
                                         admin_users=admin_views.ADMIN_USERS)

    elif m_num == '2' and s_num == '5':
        return ShowHistory(sub, page)

    return ShowSub(sub)