Exemplo n.º 1
0
def edit_page(id):
    """

    Returns:

    """
    form = PageEditorForm()
    form.id = id
    page = Page()
    page_element = PageElement()
    form.parent_id.choices = page.get_id_label_list()
    page_elements = list()

    if id > 0:
        page.set_id(id)
        page.load()
        page_elements = page_element.get_list_for_page(page.get_id())

    if request.method == "POST":
        if form.validate_on_submit():
            page.prepare_form_input(request.form)
            page.save()
            page.load()
        else:
            form.get_error_messages()

    form.init_values(page)

    return render_template("content/pages/edit_page.html",
                           form=form,
                           page_elements=page_elements)
Exemplo n.º 2
0
def image_upload():
    """

    Returns:

    """
    try:
        if "file" in request.files:
            file = request.files["file"]
            if file and allowed_file(file.filename):

                filename = secure_filename(file.filename)
                id = escape(request.form["id"])
                type = escape(request.form["type"])
                module = escape(request.form["module"])
                max_files = escape(request.form["max_files"])
                max_size = escape(request.form["max_size"])
                image_format = escape(request.form["image_format"])
                """
                z.B: ein page objekt erzeugen die id setzen und laden
                anhand von max_files prüfen ob eine liste benötigt wird
                wenn ja bild hinzufügen. andernfalls mit image_format einfach nur dem wert im
                dataitem setzen
                """

                if module == "pages":
                    module_object = Page()
                    module_object.set_id(id)
                    module_object.load()

                base_path = current_app.config["ROOT_DIR"] + "app/static/"
                final_upload_path = base_path + type + "/" + module + "/" + id + "/"

                if not os.path.isdir(final_upload_path):
                    os.makedirs(final_upload_path)

                final_path = os.path.join(final_upload_path, filename)

                if int(max_files) > 1:
                    current_data = module_object.get_list_or_dict(image_format)
                    if len(current_data) < max_files:
                        module_object.add(image_format, final_path)
                    else:
                        return make_response(400)
                else:
                    module_object.set(image_format, final_path)

                file.save(final_path)

                module_object.save()

                return filename
        return make_response(500)
    except Exception as error:
        print(error)
Exemplo n.º 3
0
def add_page():
    """

    Returns:

    """

    form = PageEditorForm()
    page = Page()
    page.init_default()
    page.save()

    return render_template("content/pages/add_page.html",
                           form=form,
                           form_object=page)
Exemplo n.º 4
0
def add_page():
    """

    Returns:

    """

    form = PageEditorForm()
    page = Page()
    page.init_default()
    page.set("ctrl_template", "standard")
    page.set("ctrl_index", 1)
    page.save()

    return render_template("content/pages/add_page.html",
                           form=form,
                           form_object=page)
Exemplo n.º 5
0
def addPage(request):
    if request.method == 'GET':
        page_url = request.GET.get('url')
        category_id = request.GET.get('category')

        webpage = urllib2.urlopen(page_url).read()
        soup = BeautifulSoup(''.join(webpage))
        user = User.objects.get(pk=request.user.id)
        category = Category.objects.get(id=category_id)

        page_title = soup('title')[0].string
        page_title = slugify.slugify_ru(page_title)
        file_name = u''.join(e for e in page_title if e.isalnum())
        file_name = slugify.slugify_ru(file_name)
        os.system(STATIC_ROOT+"/webkit2png.py -D "+STATIC_ROOT+"'/images/'"+str(request.user.id)+"  -T -o "+file_name+" "+page_url)
        page = Page(title=page_title, url=page_url, image_file=file_name+'.png',category=category, user=user)
        page.save()
        return redirect('home')
    else:
        return Response(status=403)
Exemplo n.º 6
0
def page(name="MainPage"):
    page = Page.query.filter_by(name=name).first()
    form = PageEditForm()
    action = request.args.get('action')
    if request.method == 'POST':
        if 'save' in request.form:
            if page:
                page.source = form.rawtext.data
                page.type = form.texttype.data
                page.save()
            else:
                page = Page(name=name, source=form.rawtext.data)
                page.save()
                save_action(u"修改页面" + u'"' + page.title + u'"')
            return redirect(url_for('home.page', name=name))
        elif 'preview' in request.form:
            form = PageEditForm(request.form)
            preview = form.rawtext.data
            return render_template("home/editpage.html",
                                   form=form,
                                   page=page,
                                   preview=preview)
        else:
            # for cancel
            return render_template("home/page.html", page=page)
    else:
        if action == "edit":
            if not page:
                flash(u"建立一个新页面")
                form.set_default_text(text=u"在这里编辑内容")
                return render_template("home/editpage.html",
                                       form=form,
                                       page=page)
            else:
                source = page.source
                form.set_default_text(text=source)
                return render_template("home/editpage.html",
                                       form=form,
                                       page=page)
        # render to template
        return render_template("home/page.html", page=page)
Exemplo n.º 7
0
def initdb():
    # fix for CASCADE not work issue
    db.session.execute('PRAGMA foreign_keys=ON;')
    try:
        db.create_all()
    except:
        db.drop_all()
    # add some records
    try:
        # add some users
        admin = createUser(u'admin', u'111111', u'*****@*****.**', 300)
        simon = createUser(u'simon', u'111111', u'*****@*****.**', 300)
        ray = createUser(u'ray', u'111111', u'*****@*****.**')
        yxm0513 = createUser(u'yxm0513', u'111111', u'*****@*****.**', 200)
        gonglidi = createUser(u'gonglidi', u'111111', u'*****@*****.**')
        infoprint(u"create users table successfully.", 'successfully')

        # add some tags
        
        
        # search function
        search_url = 'http://api.douban.com/book/subjects?tag=python&max-results=200'
        books = parse(search_url)
        link = ''
        ID = []
        for e in books['entries']:
            if hasattr(e, 'link'):
                link = e.link
                p = re.compile(r'(?P<id>\d+)')
                r = p.search(link)
                id = r.group("id")
                ID.append(id)
        # add some book info from douban
        #ID = range(11505944, 11505960)
        for id in ID:
            book = parse(setting.DOUBAN_API_PATH + '/' + str(id))
            title = u''
            summary = u''
            tags = u''
            for e in book['entries']:
                if hasattr(e, 'title'):
                    title = e.title
                if hasattr(e, 'summary'):
                    summary = e.summary
                if hasattr(e, 'db_tag'):
                    if 'python' in e.db_tag.get('name').lower():
                        tags = e.db_tag.get('name')
                    else:
                        tags = e.db_tag.get('name') + ',python'
                post = createPost(simon, title, summary, tags=tags)
        infoprint(u"create posts table successfully.", 'successfully')  
        
        
        # add some page info
        rules_source = u"""
免责条款
=================================
:作者: simon.yang.sh <at> gamil <dot> com   
:版本: 0.1 of 2012/07

关于提交内容
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    * 如果你觉得有什么破坏条款的请 联系我们
    * 如果你愿意监督我们的内容,联系我们吧。
"""
        rules = Page(u"免责条款", rules_source)
        rules.save()
        about_source = u"""
===================================
关于我们
===================================


我们想做的是什么呢,简单的说就是
    
   *用 digg的方式给用户提供一个读书的榜单.*

缘由:

   通常我们会在很多论坛看见很多新手问类似于,“我想学python,各位大侠有没有好的书推荐”, 我们为什么不用digg的方式来给我们构建这么的榜单呢,让大家的投票说话。

我们有什么不一样:
 * 我们只做过滤工作,给用户需要的信息 -- 做信息的减法
 * 豆瓣也有书,但不是一个榜单。
 * 我们很社会化,可构建圈子,评论也需要言简意赅,字数被限制在140个字符
 * 未来期望构建知识的架构图,树形的展示知识的架构,给学习者直观的知道,学习者可以由浅入深的研究自己希望的课题。

"""
        about = Page(u"关于我们", about_source)
        about.save()
        api_source = u"""
API
===================================
  * Coming Soon!!!
"""
        api = Page(u"API", api_source)
        api.save()
        help_source = u"""
帮助
===================================
  * Coming Soon!!!
"""
        helppage = Page(u"帮助", help_source)
        helppage.save()
        infoprint(u"create pages table successfully.", 'successfully')  
    except Exception as e:
        infoprint(u"create tables failed: %s" % e, 'error')

    cate1 = Category(name=u"计算机")
    cate2 = Category(name=u"编程", parent=cate1)
    cate1.save()
    cate2.save()
    infoprint(u"create categories table successfully.", 'successfully')  
Exemplo n.º 8
0
def initdb():
    # fix for CASCADE not work issue
    db.session.execute('PRAGMA foreign_keys=ON;')
    try:
        db.create_all()
    except:
        db.drop_all()
    # add some records
    try:
        # add some users
        admin = createUser(u'admin', u'111111', u'*****@*****.**',
                           300)
        simon = createUser(u'simon', u'111111', u'*****@*****.**', 300)
        ray = createUser(u'ray', u'111111', u'*****@*****.**')
        yxm0513 = createUser(u'yxm0513', u'111111', u'*****@*****.**', 200)
        gonglidi = createUser(u'gonglidi', u'111111', u'*****@*****.**')
        infoprint(u"create users table successfully.", 'successfully')

        # add some tags

        # search function
        search_url = 'http://api.douban.com/book/subjects?tag=python&max-results=200'
        books = parse(search_url)
        link = ''
        ID = []
        for e in books['entries']:
            if hasattr(e, 'link'):
                link = e.link
                p = re.compile(r'(?P<id>\d+)')
                r = p.search(link)
                id = r.group("id")
                ID.append(id)
        # add some book info from douban
        #ID = range(11505944, 11505960)
        for id in ID:
            book = parse(setting.DOUBAN_API_PATH + '/' + str(id))
            title = u''
            summary = u''
            tags = u''
            for e in book['entries']:
                if hasattr(e, 'title'):
                    title = e.title
                if hasattr(e, 'summary'):
                    summary = e.summary
                if hasattr(e, 'db_tag'):
                    if 'python' in e.db_tag.get('name').lower():
                        tags = e.db_tag.get('name')
                    else:
                        tags = e.db_tag.get('name') + ',python'
                post = createPost(simon, title, summary, tags=tags)
        infoprint(u"create posts table successfully.", 'successfully')

        # add some page info
        rules_source = u"""
免责条款
=================================
:作者: simon.yang.sh <at> gamil <dot> com   
:版本: 0.1 of 2012/07

关于提交内容
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    * 如果你觉得有什么破坏条款的请 联系我们
    * 如果你愿意监督我们的内容,联系我们吧。
"""
        rules = Page(u"免责条款", rules_source)
        rules.save()
        about_source = u"""
===================================
关于我们
===================================


我们想做的是什么呢,简单的说就是
    
   *用 digg的方式给用户提供一个读书的榜单.*

缘由:

   通常我们会在很多论坛看见很多新手问类似于,“我想学python,各位大侠有没有好的书推荐”, 我们为什么不用digg的方式来给我们构建这么的榜单呢,让大家的投票说话。

我们有什么不一样:
 * 我们只做过滤工作,给用户需要的信息 -- 做信息的减法
 * 豆瓣也有书,但不是一个榜单。
 * 我们很社会化,可构建圈子,评论也需要言简意赅,字数被限制在140个字符
 * 未来期望构建知识的架构图,树形的展示知识的架构,给学习者直观的知道,学习者可以由浅入深的研究自己希望的课题。

"""
        about = Page(u"关于我们", about_source)
        about.save()
        api_source = u"""
API
===================================
  * Coming Soon!!!
"""
        api = Page(u"API", api_source)
        api.save()
        help_source = u"""
帮助
===================================
  * Coming Soon!!!
"""
        helppage = Page(u"帮助", help_source)
        helppage.save()
        infoprint(u"create pages table successfully.", 'successfully')
    except Exception as e:
        infoprint(u"create tables failed: %s" % e, 'error')

    cate1 = Category(name=u"计算机")
    cate2 = Category(name=u"编程", parent=cate1)
    cate1.save()
    cate2.save()
    infoprint(u"create categories table successfully.", 'successfully')