Пример #1
0
    def postSection(category):
        if request.method == 'POST':
            if request.form['submit'] == 'add':
                postId = Posts.add(request.form["title"], category)
                renderer.blog(Model.post(postId), Model.categoriesBlogPage(),
                              Model.mdHTML(postId))
            elif request.form['submit'] == 'delete':
                renderer.deletePost(Model.post(request.form["id"]))
                Posts.delete(request.form["id"])
            elif request.form['submit'] == 'rename':
                Posts.rename(request.form["id"], request.form["title"])
                renderer.blog(Model.post(request.form["id"]),
                              Model.categoriesBlogPage(),
                              Model.mdHTML(request.form["id"]))

            renderer.postCard(Model.posts(), Model.postDate())
            renderer.recentPost(Model.posts(), Model.postDate())
            renderer.createSearchJson(Model.posts())

        categoryName = Posts.prettifyCategory(category)
        if category in Category.getCategories():
            posts = Posts.getPosts(category=category)
            return render_template('post-section.html',
                                   category=categoryName,
                                   posts=posts)
        else:
            return abort(404, description=category + " Not Found")
Пример #2
0
    def postManager(postPath):
        category, postId = PostManager.splitPath(postPath)
        if request.method == 'POST':
            if request.form["submit"] == "Save":
                if request.files['image'].filename.endswith(".gif"):
                    abort(404, description=".gif not allowed")
                PostManager.savePageInfo(postId, request.form, request.files)
                renderer.blog(Model.post(postId), Model.categoriesBlogPage(),
                              Model.mdHTML(postId))
                renderer.postCard(Model.posts(), Model.postDate())
                renderer.recentPost(Model.posts(), Model.postDate())
                renderer.createSearchJson(Model.posts())
                return {'postId': postId}
            elif request.form["submit"] == "save-md":
                PostManager.saveMD(postId, request.form)
            elif request.form["submit"] == "delete":
                PostManager.deleteImage(postId, request.form['id'],
                                        request.form['format'])
            elif request.form["submit"] == "upload":
                imgId, imgFormat = PostManager.uploadImage(
                    postId, request.files['image'])
                renderer.blog(Model.post(postId), Model.categoriesBlogPage(),
                              Model.mdHTML(postId))
                renderer.postCard(Model.posts(), Model.postDate())
                renderer.recentPost(Model.posts(), Model.postDate())
                renderer.createSearchJson(Model.posts())
                return {
                    "category": category,
                    "postId": postId,
                    "imgId": imgId,
                    "imgFormat": imgFormat
                }
            elif request.form["submit"] == "setup-md":
                PostManager.setupMD(postId, request.form)
            elif request.form["submit"] == 'date':
                saveDate(postId, request.form['date'])

            renderer.blog(Model.post(postId), Model.categoriesBlogPage(),
                          Model.mdHTML(postId))
            renderer.postCard(Model.posts(), Model.postDate())
            renderer.recentPost(Model.posts(), Model.postDate())
            renderer.createSearchJson(Model.posts())

        postDetail, postImage = PostManager.loadPageInfo(postId)
        return render_template('post.html',
                               post=postDetail,
                               category=category,
                               postImage=postImage,
                               images=PostManager.loadImages(postId),
                               mdConfig=PostManager.loadMDConfig(postId),
                               mdData=PostManager.loadMD(postId),
                               categories=Category.prettifyCategories(),
                               date=loadDates()[postId])
Пример #3
0
    def categorySection():
        if request.method == 'POST':
            if request.form['submit'] == 'add':
                Category.add(request.form["name"])
                renderer.refreshBlogs()
            elif request.form['submit'] == 'delete':
                Category.delete(request.form["name"])
            elif request.form['submit'] == 'rename':
                Category.rename(request.form["old-name"],
                                request.form["new-name"])

            renderer.refreshBlogs()
            renderer.postCard(Model.posts(), Model.postDate())
            renderer.recentPost(Model.posts(), Model.postDate())
            renderer.createSearchJson(Model.posts())

        categories = Category.prettifyCategories()
        return render_template('category-section.html', categories=categories)
Пример #4
0
    def siteDetail():
        if request.method == 'POST':
            SiteSetup.saveSiteDetail(request.form, request.files)

            # save favIcon if profile image is available
            saveFavIcon()

            # render all required files
            renderer.siteDetail = Model.formatSiteJson()
            renderer.homePage(Model.galleries(), Model.services())
            renderer.thanksPage()
            renderer.searchPage()
            renderer.categoryPage()
            renderer.postCard(Model.posts(), Model.postDate())
            renderer.recentPost(Model.posts(), Model.postDate())
            renderer.refreshBlogs()
            renderer.moreGalleryPage(Model.moreGalleries())

        # Load site-detail.json file and image-data
        formData = SiteSetup.loadSiteDetail()
        imageData = SiteSetup.loadImage()
        return render_template('site-detail.html',
                               formData=formData,
                               imageData=imageData)