Exemplo n.º 1
0
def context_processor():
    apps = []
    tags = []
    apps_db = Apps.query.all()
    for app_db in apps_db:
        if not app_db.groups:
            app_db.groups = None
        if check_groups(app_db.groups, current_user):
            apps.append(app_db)
            tags += app_db.tags.split(",")

    tags_form = TagsForm()
    tags_form.tags.choices += [(tag, tag) for tag in tags]
    print(tags_form.tags.choices)
    settings = Settings.query.first()
    if settings.background == "random":
        if len(os.listdir(backgrounds_images_folder)) < 1:
            settings.background = None
        else:
            settings.background = (
                f"static/images/backgrounds/"
                f"{random.choice(os.listdir(backgrounds_images_folder))}")
    return dict(
        test_key="test",
        process_js_sources=process_js_sources,
        process_css_sources=process_css_sources,
        apps=apps,
        settings=settings,
        tags_form=tags_form,
    )
Exemplo n.º 2
0
def settings():
    settings_db = Settings.query.first()
    if not check_groups(settings_db.settings_access_groups, current_user):
        return redirect(url_for("main.home"))

    config_form = ConfigForm()
    user_form = UserForm()
    user_form.role.choices += [(role, role)
                               for role in settings_db.roles.split(",")]
    with open(os.path.join(user_data_folder, "config.ini"),
              "r") as config_file:
        config_form.config.data = config_file.read()
    files_html = load_files_html()

    template_apps = []
    config = ConfigParser()
    for template_app_ini in os.listdir(template_apps_folder):
        config.read(os.path.join(template_apps_folder, template_app_ini))
        entry = config[template_app_ini.replace(".ini", "")]
        template_apps.append(
            f"{template_app_ini.replace('.ini', '')}&&{entry['icon']}")

    users = User.query.all()
    config_readme = get_config_html()
    return render_template(
        "settings_system/settings.html",
        config_form=config_form,
        files_html=files_html,
        user_form=user_form,
        template_apps=",".join(template_apps),
        version=version,
        revision_number=revision_number,
        users=users,
        config_readme=config_readme,
    )
Exemplo n.º 3
0
def app_view(app_id):
    settings = Settings.query.first()
    if not check_groups(settings.home_access_groups, current_user):
        return redirect(url_for("user_system.login"))
    app_db = Apps.query.filter_by(id=app_id).first()
    return render_template(
        "main/app-view.html", url=f"{app_db.prefix}{app_db.url}", title=app_db.name
    )
Exemplo n.º 4
0
def home():
    tags_form = TagsForm()
    tags_form.tags.choices += [(tag.name, tag.name)
                               for tag in Tags.query.order_by(Tags.name).all()]
    settings = Settings.query.first()
    if not check_groups(settings.home_access_groups, current_user):
        return redirect(url_for("error_pages.unauthorized"))
    return render_template("main/home.html", tags_form=tags_form)
Exemplo n.º 5
0
def context_processor():
    apps = []
    temp_tags = []
    tags = []
    apps_db = Apps.query.all()
    for app_db in apps_db:
        if app_db.urls:
            url_list = app_db.urls.replace("},{", "}%,%{").split("%,%")
            app_db.urls_json = []
            for url in url_list:
                app_db.urls_json.append(json.loads(url))
        if not app_db.groups:
            app_db.groups = None
        if check_groups(app_db.groups, current_user):
            apps.append(app_db)
            if app_db.tags:
                temp_tags += app_db.tags.split(",")

    tags_form = TagsForm()
    if len(temp_tags) > 0:
        temp_tags = list(dict.fromkeys([tag.strip() for tag in temp_tags]))
    tags_form.tags.choices += [(tag, tag) for tag in temp_tags]
    for tag in temp_tags:
        tag_db = Tags.query.filter_by(name=tag).first()
        if tag_db:
            tags.append(tag_db)
    tags.sort(key=tag_sort_func)
    settings = Settings.query.first()
    if settings.background == "random":
        if len(os.listdir(backgrounds_images_folder)) < 1:
            settings.background = None
        else:
            settings.background = (
                f"static/images/backgrounds/"
                f"{random.choice(os.listdir(backgrounds_images_folder))}"
            )
    update_message = get_update_message_html()
    return dict(
        test_key="test",
        process_js_sources=process_js_sources,
        process_css_sources=process_css_sources,
        apps=apps,
        settings=settings,
        tags=tags,
        tags_form=tags_form,
        update_message=update_message,
    )
Exemplo n.º 6
0
def home():
    settings = Settings.query.first()
    if not check_groups(settings.home_access_groups, current_user):
        return redirect(url_for("error_pages.unauthorized"))
    return render_template("main/home.html")