Exemplo n.º 1
0
def appearance(request):

    current = Setting.objects.get_settings_dict(Setting.CATEGORY_UI)
    form = AppearanceForm(initial=current)

    if request.method == "POST":
        if "reset" in request.POST:
            Setting.objects.filter(category=Setting.CATEGORY_UI).delete()
            CustomCSSView.drop_cache()
            return redirect("manage-appearance")
        form = AppearanceForm(request.POST)
        if form.is_valid():
            for name, value in form.cleaned_data.items():
                if name not in current:
                    # New setting previously not set
                    Setting.objects.create(
                        category=Setting.CATEGORY_UI, name=name, value=value
                    )
                else:
                    if value != current[name]:
                        # Update setting
                        Setting.objects.filter(
                            category=Setting.CATEGORY_UI, name=name
                        ).update(value=value)
                    current.pop(name)
            # Drop stale settings
            if current:
                Setting.objects.filter(
                    category=Setting.CATEGORY_UI, name__in=current.keys()
                ).delete()

            # Flush cache
            CustomCSSView.drop_cache()
            return redirect("manage-appearance")

    return render(
        request,
        "manage/appearance.html",
        {
            "menu_items": MENU,
            "menu_page": "appearance",
            "form": form,
        },
    )
Exemplo n.º 2
0
def weblate_context(request):
    """Context processor to inject various useful variables into context."""
    if url_has_allowed_host_and_scheme(request.GET.get("next", ""), allowed_hosts=None):
        login_redirect_url = request.GET["next"]
    else:
        login_redirect_url = request.get_full_path()

    # Load user translations if user is authenticated
    watched_projects = None
    if hasattr(request, "user") and request.user.is_authenticated:
        watched_projects = request.user.watched_projects

    if settings.OFFER_HOSTING:
        description = _("Hosted Weblate, the place to localize your software project.")
    else:
        description = _(
            "This site runs Weblate for localizing various software projects."
        )

    context = {
        "cache_param": f"?v={weblate.GIT_VERSION}"
        if not settings.COMPRESS_ENABLED
        else "",
        "version": weblate.VERSION,
        "bread_image": get_bread_image(request.path),
        "description": description,
        "weblate_link": mark_safe(
            '<a href="{}">weblate.org</a>'.format(escape(WEBLATE_URL))
        ),
        "weblate_name_link": mark_safe(
            '<a href="{}">Weblate</a>'.format(escape(WEBLATE_URL))
        ),
        "weblate_version_link": mark_safe(
            '<a href="{}">Weblate {}</a>'.format(
                escape(WEBLATE_URL), "" if settings.HIDE_VERSION else weblate.VERSION
            )
        ),
        "donate_url": DONATE_URL,
        "site_url": get_site_url(),
        "site_domain": get_site_domain(),
        "current_date": datetime.utcnow().strftime("%Y-%m-%d"),
        "current_year": datetime.utcnow().strftime("%Y"),
        "current_month": datetime.utcnow().strftime("%m"),
        "login_redirect_url": login_redirect_url,
        "has_ocr": weblate.screenshots.views.HAS_OCR,
        "has_antispam": bool(settings.AKISMET_API_KEY),
        "has_sentry": bool(settings.SENTRY_DSN),
        "watched_projects": watched_projects,
        "allow_index": False,
        "configuration_errors": ConfigurationError.objects.filter(
            ignored=False
        ).order_by("-timestamp"),
        "preconnect_list": get_preconnect_list(),
        "custom_css_hash": CustomCSSView.get_hash(request),
    }

    add_error_logging_context(context)
    add_settings_context(context)
    add_optional_context(context)

    return context
Exemplo n.º 3
0
     name="load_zen",
 ),
 path(
     "js/save-zen/<name:project>/<name:component>/<name:lang>/",
     weblate.trans.views.edit.save_zen,
     name="save_zen",
 ),
 # Glossary add
 path(
     "js/glossary/<int:unit_id>/",
     weblate.glossary.views.add_glossary_term,
     name="js-add-glossary",
 ),
 path(
     "css/custom.css",
     CustomCSSView.as_view(),
     name="css-custom",
 ),
 # Admin interface
 path(
     "admin/",
     include(
         (weblate.wladmin.sites.SITE.urls, "weblate.wladmin"), namespace="admin"
     ),
 ),
 # Weblate management interface
 path("manage/", weblate.wladmin.views.manage, name="manage"),
 path("manage/tools/", weblate.wladmin.views.tools, name="manage-tools"),
 path("manage/users/", weblate.wladmin.views.users, name="manage-users"),
 path(
     "manage/users/check/",