Ejemplo n.º 1
0
def get_sidenav():
    with open('lwpcms/static/shards/admin/side_nav.json') as file:
            nav = json.loads(file.read())

            call_module_event(hooks['admin_sidenav'], {'nav': nav})

            return nav
Ejemplo n.º 2
0
def render(template_name):

    package = {
            'request_get': request.args,
            'request_post': request.form,
            'request_body': request.get_data(),
            'request_unknown': request.stream.read()
            }

    if not get_option('initialized'):
        return redirect('/setup')


    if template_name is None:
        template_name = 'index.html'

    theme = get_activated_theme()

    if theme is not None:
        pages_path = 'lwpcms/{}/pages'.format(theme['path'])
        abs_pages_path = os.path.abspath(pages_path)
        abs_templates_path = os.path.abspath('lwpcms/templates')
        page_path = '{}/{}'.format(pages_path, template_name)

        if not os.path.exists('{}/theme'.format(abs_templates_path)):
            os.makedirs('{}/theme'.format(abs_templates_path))

        for filename in glob.iglob('{}/*.html'.format(abs_pages_path)):
            linked_file = '{}/theme/{}'.format(abs_templates_path, ntpath.basename(filename))
            
            if os.path.islink(linked_file):
                os.unlink(linked_file)

            os.symlink(filename, linked_file)

        call_module_event(hooks['site_request'], {'package': package})
        
        if not os.path.isfile(page_path):
            return render_template(
                    'error.html',
                    error='This page does not exist'
                    ), 404

        return render_template_string(open(page_path).read(), package=package)
    else:
        return render_template('index.html')
Ejemplo n.º 3
0
def publish_post(title, content, attachments, published=True, tags=[], id=None):
    if id is not None:
        post = db.collections.update_one(
                {
                    "_id": ObjectId(id)    
                },
                {
                    "$set": {
                        "title": title,
                        "content": content,
                        "published": published,
                        "tags": tags
                    }
                }
            )
        for attachment in attachments:
            post = db.collections.update_one(
                {
                    "_id": ObjectId(id)    
                },
                {
                    "$addToSet": {
                        "attachments": attachment
                    }
                }
            )
        return {"_id": ObjectId(id) }
    else:
        post = Post(
                classes=["post"],
                type='post',
                title=title,
                content=content,
                attachments=attachments,
                tags=tags,
                author={},
                published=published
                ).export()

        call_module_event(hooks['post_publish'], {'post': post})
        db.collections.insert_one(post)

    return post