예제 #1
0
파일: setup.py 프로젝트: phille97/LWPCMS
def render():
    if get_option('initialized') is not None:
        return redirect('/')

    form = SetupForm(csrf_enabled=False)

    if form.validate_on_submit():
        site_name = form.site_name.data
        user_name = form.user_name.data
        password = form.password.data
        demo = form.demo.data

        set_option('site_name', site_name)
        set_option('site_demo', demo)
        set_option('site_filespage_limit', 128)
        set_option('site_postspage_limit', 128)

        register_user(
                    name=user_name,
                    password=password
                )

        set_option('initialized', 'True')

        return redirect('/')

    return render_template('setup.html', form=form)
예제 #2
0
def render_files(page):
    sidenav = get_sidenav()

    form = UploadFileForm(csrf_enabled=False)
    if form.validate_on_submit():
        files = request.files.getlist('file')
        
        for file in files:
            upload_file(file)

    page = int(page)
    limit = int(get_option('site_filespage_limit')['value'])
    
    query = {
            'structure': '#File'
    }
    files = list(
                db.collections.find(query).sort('created', pymongo.DESCENDING).skip(page * limit)\
                        .limit(limit)
            )
    page_count = int(db.collections.count(query) / limit)
    return render_template('files.html',
        sidenav=sidenav,
        form=form,
        files=files,
        page_count=page_count
    )
예제 #3
0
def render():
    if get_option('initialized') is not None:
        return redirect('/')

    form = SetupForm(csrf_enabled=False)

    if form.validate_on_submit():
        site_name = form.site_name.data
        user_name = form.user_name.data
        password = form.password.data
        demo = form.demo.data

        set_option('site_name', site_name)
        set_option('site_demo', demo, type='boolean')
        set_option('site_filespage_limit', 128, type='integer')
        set_option('site_postspage_limit', 128, type='integer')
        set_option('site_description', 'Your Description', type='textarea')
        set_option('site_tags', 'cms,site,website,blog', type='tags')

        register_user(
                    name=user_name,
                    password=password
                )

        set_option('initialized', 'True', type='boolean', editable=False)

        return redirect('/')

    return render_template('setup.html', form=form)
예제 #4
0
def render_posts(page):
    sidenav = get_sidenav()

    page = int(page)
    limit = int(get_option('site_postspage_limit')['value'])

    query ={
        "classes": ["post"]
    }
    posts = list(
                db.collections.find(query).sort('created', pymongo.DESCENDING)\
                        .skip(page * limit).limit(limit)
                )
    page_count = int(db.collections.count(query) / limit)
    return render_template('posts.html', sidenav=sidenav,
            posts=posts, page_count=page_count)
예제 #5
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')
예제 #6
0
def render_settings():
    sidenav = get_sidenav()

    form = SettingsForm(csrf_enabled=False)
    if form.validate_on_submit():
        set_option('site_demo', form.demo.data)
        set_option('site_name', form.site_name.data)
        set_option('site_description', form.site_description.data)
        site_tags = ','.join(request.form.getlist('lwpcms_tag'))
        set_option('site_tags', site_tags)
        set_option('site_filespage_limit', form.site_filespage_limit.data)
        set_option('site_postspage_limit', form.site_postspage_limit.data)
    
    is_demo = get_option('site_demo')
    if is_demo:
        form.demo.data = is_demo['value']

    site_name = get_option('site_name')
    if site_name:
        form.site_name.data = site_name['value']

    site_description = get_option('site_description')
    if site_description:
        form.site_description.data = site_description['value']

    site_tags = get_option('site_tags')
    if site_tags:
        site_tags = site_tags['value']
    else:
        site_tags = ''
    
    site_filespage_limit = get_option('site_filespage_limit')
    if site_filespage_limit:
        form.site_filespage_limit.data = site_filespage_limit['value']

    site_postspage_limit = get_option('site_postspage_limit')
    if site_postspage_limit:
        form.site_postspage_limit.data = site_postspage_limit['value']

    
    return render_template(
            'settings.html',
            sidenav=sidenav,
            site_tags=site_tags,
            form=form
            )
예제 #7
0
파일: admin.py 프로젝트: phille97/LWPCMS
def render_files(page):
    sidenav = get_sidenav()

    form = UploadFileForm(csrf_enabled=False)
    if form.validate_on_submit():
        upload_file(form.file.data, form.title.data)

    page = int(page)
    limit = int(get_option('site_filespage_limit')['value'])
    
    query = {
        "classes": ["post", "file"]
    }
    files = list(
                db.collections.find(query).sort('created', pymongo.DESCENDING).skip(page * limit)\
                        .limit(limit)
            )
    page_count = int(db.collections.count(query) / limit)
    return render_template('admin_files.html',
        sidenav=sidenav,
        form=form,
        files=files,
        page_count=page_count
    )
예제 #8
0
파일: site.py 프로젝트: phille97/LWPCMS
def is_site_demo():
    return get_option('site_demo')['value']
예제 #9
0
def is_site_demo():
    return get_option("site_demo")["value"]