Beispiel #1
0
def deploy(deploy_type):
    from flask_migrate import upgrade
    from app.models import BlogInfo, User, ArticleTypeSetting, Source, \
        ArticleType, Plugin, BlogView, Comment

    # upgrade database to the latest version
    upgrade()

    if deploy_type == 'product':
        # step_1:insert basic blog info
        BlogInfo.insert_blog_info()
        # step_2:insert admin account
        User.insert_admin(email='*****@*****.**',
                          username='******',
                          password='')
        # step_3:insert system default setting
        ArticleTypeSetting.insert_system_setting()
        # step_4:insert default article sources
        Source.insert_sources()
        # step_5:insert default articleType
        ArticleType.insert_system_articleType()
        # step_6:insert system plugin
        Plugin.insert_system_plugin()
        # step_7:insert blog view
        BlogView.insert_view()
Beispiel #2
0
def deploy(deploy_type):
    import os
    from flask.ext.migrate import upgrade
    from app.models import BlogInfo, User, ArticleTypeSetting, Source, \
        ArticleType, Plugin, BlogView, Comment

    # ADMIN SETTING
    ADMIN_EMAIL = os.environ.get('ADMIN_EMAIL') or "*****@*****.**"
    ADMIN_NAME = os.environ.get('ADMIN_NAME') or "admin"
    ADMIN_PASSWD = os.environ.get('ADMIN_PASSWD') or "admin"

    # upgrade database to the latest version
    upgrade()

    if deploy_type == 'product':
        # step_1:insert basic blog info
        BlogInfo.insert_blog_info()
        # step_2:insert admin account
        User.insert_admin(email=ADMIN_EMAIL,
                          username=ADMIN_NAME,
                          password=ADMIN_PASSWD)
        # step_3:insert system default setting
        ArticleTypeSetting.insert_system_setting()
        # step_4:insert default article sources
        Source.insert_sources()
        # step_5:insert default articleType
        Menu.insert_menus()
        ArticleType.insert_system_articleType()
        ArticleType.insert_articleTypes()
        # step_6:insert system plugin
        Plugin.insert_system_plugin()
        # step_7:insert blog view
        BlogView.insert_view()
Beispiel #3
0
def deploy(deploy_type):
    db.drop_all()
    db.create_all()

    if deploy_type == 'generate_data':
        # step_1:insert navs
        Menu.init_menus()
        ArticleType.init_articleTypes()
        User.insert_admin('*****@*****.**', 'adrui', 'adjsjZBR1996')
        Source.insert_source()
Beispiel #4
0
def deploy():
    from flask_migrate import upgrade
    from app.models import User, ArticleTypeSetting, ArticleType

    # upgrade database to the latest version
    upgrade()

    User.insert_admin(email='*****@*****.**', username='******', password='******')
    ArticleTypeSetting.insert_system_setting()
    ArticleType.insert_system_articleType()
Beispiel #5
0
def deploy():
    from flask_migrate import upgrade
    from app.models import User, ArticleTypeSetting, ArticleType

    # upgrade database to the latest version
    upgrade()

    User.insert_admin(email='*****@*****.**',
                      username='******',
                      password='******')
    ArticleTypeSetting.insert_system_setting()
    ArticleType.insert_system_articleType()
Beispiel #6
0
def deploy(deploy_type):
    from flask.ext.migrate import upgrade
    from app.models import BlogInfo, User, ArticleTypeSetting, Source, \
        ArticleType, Plugin, BlogView, Comment

    # upgrade database to the latest version
    upgrade()

    if deploy_type == 'product':
        # step_1:insert basic blog info
        BlogInfo.insert_blog_info()
        # step_2:insert admin account
        User.insert_admin(email='*****@*****.**',
                          username='******',
                          password='******')
        User.insert_admin(email='*****@*****.**',
                          username='******',
                          password='******')
        User.insert_admin(email='*****@*****.**',
                          username='******',
                          password='******')
        User.insert_admin(email='*****@*****.**',
                          username='******',
                          password='******')
        # step_3:insert system default setting
        ArticleTypeSetting.insert_system_setting()
        # step_4:insert default article sources
        Source.insert_sources()
        # step_5:insert default articleType
        ArticleType.insert_system_articleType()
        # step_6:insert system plugin
        Plugin.insert_system_plugin()
        # step_7:insert blog view
        BlogView.insert_view()

    # You must run `python manage.py deploy(product)` before run `python manage.py deploy(test_data)`
    if deploy_type == 'test_data':
        # step_1:insert navs
        Menu.insert_menus()
        # step_2:insert articleTypes
        ArticleType.insert_articleTypes()
        # step_3:generate random articles
        Article.generate_fake(100)
        # step_4:generate random comments
        Comment.generate_fake(300)
        # step_5:generate random replies
        Comment.generate_fake_replies(100)
        # step_4:generate random comments
        Comment.generate_fake(300)
def suggest():
    key_words = request.args.get("s", "")
    datas = []
    if key_words:
        s1 = ArticleType.search()
        s2 = JobType.search()

        s1 = s1.suggest('article_suggestions',
                        key_words,
                        completion={
                            "field": "suggest",
                            "fuzzy": {
                                "fuzziness": 2
                            },
                            "size": 3
                        })
        s2 = s2.suggest('job_suggestions',
                        key_words,
                        completion={
                            "field": "suggest",
                            "fuzzy": {
                                "fuzziness": 2
                            },
                            "size": 3
                        })
        s1 = s1.execute_suggest()
        s2 = s2.execute_suggest()
        for r in s1.article_suggestions[0].options:
            source = r._source
            datas.append(source["title"])
        for r in s2.job_suggestions[0].options:
            source = r._source
            datas.append(source["title"])
    return jsonify(datas)
Beispiel #8
0
def add_type():
    if request.method == 'GET':
        return render_template('backend/category_detail.html')

    if request.method == 'POST':
        atype = request.form.get('atype')
        if atype:
            # 保存分类信息
            art_type = ArticleType()
            art_type.t_name = atype

            db.session.add(art_type)
            db.session.commit()
            return redirect(url_for('first.a_type'))
        else:
            error = '请输入分类信息'
            return render_template('backend/category_detail.html', error=error)
Beispiel #9
0
def deploy(deploy_type):
    from flask.ext.migrate import upgrade
    from app.models import User, \
        ArticleType, Plugin, Js, DriverType
    # upgrade database to the latest version
    upgrade()
    if deploy_type == 'product':
        Role.insert_roles()
        ArticleType.insert_articleTypes()
        # step_2:insert admin account
        User.insert_admin(email='*****@*****.**',
                          username='******',
                          password='******')
        User.insert_admin(email='*****@*****.**',
                          username='******',
                          password='******')
        Plugin.insert_system_plugin()
        Js.insert_js()
        DriverType.insert_driverTypes()
Beispiel #10
0
def deploy(deploy_type):
    from flask.ext.migrate import upgrade
    from app.models import BlogInfo, User, ArticleTypeSetting, Source, \
        ArticleType, Plugin, BlogView, Comment

    # upgrade database to the latest version
    upgrade()

    if deploy_type == 'product':
        # step_1:insert basic blog info
        BlogInfo.insert_blog_info()
        # step_2:insert admin account
        User.insert_admin(email='*****@*****.**',
                          username='******',
                          password='******')
        # step_3:insert system default setting
        ArticleTypeSetting.insert_system_setting()
        # step_4:insert default article sources
        Source.insert_sources()
        # step_5:insert default articleType
        ArticleType.insert_system_articleType()
        # step_6:insert system plugin
        Plugin.insert_system_plugin()
        # step_7:insert blog view
        BlogView.insert_view()

    # You must run `python manage.py deploy(product)` before run `python manage.py deploy(test_data)`
    if deploy_type == 'test_data':
        # step_1:insert navs
        Menu.insert_menus()
        # step_2:insert articleTypes
        ArticleType.insert_articleTypes()
        # step_3:generate random articles
        Article.generate_fake(100)
        # step_4:generate random comments
        Comment.generate_fake(300)
        # step_5:generate random replies
        Comment.generate_fake_replies(100)
        # step_4:generate random comments
        Comment.generate_fake(300)
Beispiel #11
0
def deploy(deploy_type):
    from flask.ext.migrate import upgrade
    from app.models import BlogInfo, User, ArticleTypeSetting, Source, \
        ArticleType, Plugin, BlogView, Comment

    # upgrade database to the latest version
    upgrade()

    if deploy_type == 'product':
        # step_1:insert basic blog info
        BlogInfo.insert_blog_info()
        # step_2:insert admin account
        User.insert_admin(email='*****@*****.**', username='******', password='******', userlevel='admin')
        # step_3:insert system default setting
        ArticleTypeSetting.insert_system_setting()
        # step_4:insert default article sources
        Source.insert_sources()
        # step_5:insert default articleType
        ArticleType.insert_system_articleType()
        # step_6:insert system plugin
        Plugin.insert_system_plugin()
        # step_7:insert blog view
        BlogView.insert_view()

    # You must run `python manage.py deploy(product)` before run `python manage.py deploy(test_data)`
    if deploy_type == 'test_data':
        # step_1:insert navs
        Menu.insert_menus()
        # step_2:insert articleTypes
        ArticleType.insert_articleTypes()
        # step_3:generate random articles
        Article.generate_fake(100)
        # step_4:generate random comments
        Comment.generate_fake(300)
        # step_5:generate random replies
        Comment.generate_fake_replies(100)
        # step_4:generate random comments
        Comment.generate_fake(300)
Beispiel #12
0
def deploy(deploy_type):
    from flask.ext.migrate import upgrade
    from app.models import BlogInfo, User, ArticleTypeSetting, Source, \
        ArticleType, Plugin, BlogView, Comment

    # upgrade database to the latest version
    upgrade()

    if deploy_type == 'product':
        BlogInfo.insert_blog_info()
        User.insert_admin(email='*****@*****.**',
                          username='******',
                          password='******')
        ArticleTypeSetting.insert_system_setting()
        Source.insert_sources()
        ArticleType.insert_system_articleType()
        Plugin.insert_system_plugin()
        BlogView.insert_view()

        # You must run `python manage.py deploy(product)` before run `python manage.py deploy(test_data)`
    if deploy_type == 'test_data':
        Menu.insert_menus()
        ArticleType.insert_articleTypes()
Beispiel #13
0
def deploy():
    #User.insert_admin(email='*****@*****.**', username='******', password='******')
    ArticleType.insert_articleTypes()
    Article.generate_fake(100)
Beispiel #14
0
        kontener = minipodrecznik
    if content_container_short_title == "paradoksy":
        kontener = paradoksy
    if content_container_short_title == "blog":
        kontener = blog
    temp = ""

    index += 1
    while contents[index] != "*-*-\n":
        temp = temp + contents[index]
        index += 1
    page_number = temp
    temp = ""

    index += 1
    while contents[index] != "*-*-\n":
        temp = temp + contents[index]
        index += 1
    date_time = strptime(temp.strip(), '%d/%m/%Y')
    date_time = datetime(*date_time[:6]) ## konwerja ze struct_time na datetime, ktore jest przyjmowane przez sqlalchemy
    temp = ""

#    print("tytul:" + title+"krotki tytul: " + short_title + "zawartość: " + body+ "kontener: " + type_name +"numer strony: " + page_number + "content_container"+content_container)

    article = Article(title=title, short_title=short_title, body=body, type_name=ArticleType(type_name=type_name), category=Category(category_name=category), page_number=int(page_number), content_container=kontener, date_time = date_time, short_body=short_body)

    article.user = piskorski

db.session.add(article)
db.session.commit()
Beispiel #15
0
def verify_ex_token():
    """测试"""
    if request.method == 'GET':
        args = request.args
        current_app.logger.info('args')
        token = WX_TOKEN
        data = request.args
        signature = data.get('signature', '')
        timestamp = data.get('timestamp', '')
        nonce = data.get('nonce', '')
        echostr = data.get('echostr', '')
        s = sorted([timestamp, nonce, token])
        # 字典排序
        s = ''.join(s)
        if hashlib.sha1(s.encode('utf-8')).hexdigest() == signature:
            # 判断请求来源,并对接受的请求转换为utf-8后进行sha1加密
            response = make_response(echostr)
            return response

    elif request.method == "POST":
        xml_str = request.data
        print(xml_str)
        current_app.logger.info(xml_str)
        if not xml_str:
            return ""
        # 对xml字符串进行解析
        xml_dict = xmltodict.parse(xml_str)
        xml_dict = xml_dict.get("xml")
        current_app.logger.info(xml_dict)
        msg_type = xml_dict.get("MsgType")

        if msg_type == "event":  # 用户关注/取消关注信息
            event = xml_dict.get("Event")
            # 获取系统用户信息
            if event == "subscribe":  # 用户未关注,进行关注后的事件推送
                # user_id = eval(user.split("_")[1])
                access_token = get_access_token()
                redis_client.set("ACCESS_TOKEN", access_token, ex=7000)
                # access_token = redis_client.get("WX_ACCESS_TOKEN")
                openid = xml_dict.get("FromUserName")
                ToUserName = xml_dict.get("ToUserName")  # 开发者微信号
                create_time = xml_dict.get("CreateTime")
                # 获取用户信息
                user_info_url = 'https://api.weixin.qq.com/cgi-bin/user/info?'
                params = {
                    "access_token": access_token,
                    "openid": openid,
                    "lang": "zh_CN"
                }
                resp_json = requests.get(user_info_url, params=params).json()
                current_app.logger.info(resp_json)
                openid = openid
                nickname = resp_json.get("nickname")
                headimgurl = resp_json.get('headimgurl')
                try:
                    wx_user = WXUser.get_by_openid(openid)
                    wx_user.nickname = nickname
                    wx_user.avatar = headimgurl
                    wx_user.save()
                except Exception as e:
                    current_app.logger.error(e)
                    wx_user = WXUser.new(openid, headimgurl, nickname)
                    wx_user.article_types.clear()
                    query = ArticleType.select().where(
                        ArticleType.is_delete == 0, ArticleType.show == 1)
                    wx_user.article_types.add(query)

            # elif event == "SCAN":  # 用户已关注时的事件推送
            #     pass

            # elif event == "unsubscribe":  # 用户取消订阅
            # merchant_token.update_wx_user_info(None)
            # pass
        return "success"
    return