Example #1
0
def themes():
    all_themes = get_themes()

    for theme in all_themes:
        theme['url'] = request.url_root + 'api/themes/download/{}'.format(theme['name'])

    print(request.url_root)
    return jsonify({'themes': all_themes})
Example #2
0
def themes_download(theme_name):
    theme = get_themes(theme_name)
    tarname = 'lwpcms/themes/tar/{}.tar.gz'.format(theme['name'])

    if not os.path.exists('lwpcms/themes/tar'):
        os.mkdir('lwpcms/themes/tar')

    if not os.path.exists(tarname):
        make_tarfile(tarname, 'lwpcms/' + theme['path'])

    return send_file('themes/tar/' + theme['name'] + '.tar.gz')
Example #3
0
def get_static_1(theme_name, file_name):
    theme = get_themes(theme_name)

    if theme is not None:
        path = "{}/{}".format(theme["path"], file_name)
        mimetype = ""

        if "css" in file_name or "css" in file_name:
            mimetype = "text/css"

        elif "image" in file_name or "jpg" in file_name or "png" in file_name:
            mimtype = "image/jpg"

        return send_file(path, mimetype=mimetype)
    else:
        return "No activated theme", 400
Example #4
0
def render_themes():
    sidenav = get_sidenav()

    if request.method == 'POST':
        if 'theme_path' in request.form:
            theme_path = request.form['theme_path']

            with open('lwpcms/{}/theme.json'.format(theme_path)) as file:
                data = json.loads(file.read())
                theme = data['theme']
                
                if 'activated' in theme:
                    activated = theme['activated']
                else:
                    activated = False

            
                if activated:
                    activated = False
                else:
                    activated = True

                theme['activated'] = activated

                with open('lwpcms/{}/theme.json'.format(theme_path), 'w') as jsonFile:
                    jsonFile.write(
                            json.dumps(
                                data,
                                sort_keys=True,indent=4,
                                separators=(',', ': ')
                                )
                            )

                    abs_templates_path = os.path.abspath('lwpcms/templates')
                    
                    if os.path.isdir('{}/theme'.format(abs_templates_path)):
                        shutil.rmtree('{}/theme'.format(abs_templates_path))

                    return redirect('/admin/themes')

    themes = get_themes()

    return render_template('admin_themes.html', sidenav=sidenav, themes=themes)
Example #5
0
def render_themes():
    sidenav = get_sidenav()

    if request.method == "POST":
        if "theme_path" in request.form:
            theme_path = request.form["theme_path"]

            with open("lwpcms/{}/theme.json".format(theme_path)) as file:
                data = json.loads(file.read())
                theme = data["theme"]

                if "activated" in theme:
                    activated = theme["activated"]
                else:
                    activated = False

                if activated:
                    activated = False
                else:
                    activated = True

                theme["activated"] = activated

                with open("lwpcms/{}/theme.json".format(theme_path), "w") as jsonFile:
                    jsonFile.write(json.dumps(data, sort_keys=True, indent=4, separators=(",", ": ")))

                    abs_templates_path = os.path.abspath("lwpcms/templates")

                    if os.path.isdir("{}/theme".format(abs_templates_path)):
                        shutil.rmtree("{}/theme".format(abs_templates_path))

                    return redirect("/admin/themes")

    themes = get_themes()

    return render_template("themes.html", sidenav=sidenav, themes=themes)