Exemplo n.º 1
0
    def check_setup_status_wrapper_fn(request, *args, **kwargs):

        if "registered" not in request.session:
            logging.error("Key 'registered' not defined in session, but should be by now.")

        if request.is_admin:
            # TODO(bcipolli): move this to the client side?
            if not request.session.get("registered", True) and BaseClient().test_connection() == "success":
                # Being able to register is more rare, so prioritize.
                messages.warning(request, mark_safe(_("Please <a href='%s'>follow the directions to register your device</a>, so that it can synchronize with the central server.") % reverse("register_public_key")))
            elif not request.session["facility_exists"]:
                zone_id = (Zone.objects.all() and Zone.objects.all()[0].id) or "None"
                messages.warning(request, mark_safe(_("Please <a href='%s'>create a facility</a> now. Users will not be able to sign up for accounts until you have made a facility.") % reverse("add_facility", kwargs={"zone_id": zone_id})))

        elif not request.is_logged_in:
            if not request.session.get("registered", True) and BaseClient().test_connection() == "success":
                # Being able to register is more rare, so prioritize.
                redirect_url = reverse("register_public_key")
            elif not request.session["facility_exists"]:
                zone = Device.get_own_device().get_zone()
                zone_id = "None" if not zone else zone.id
                redirect_url = reverse("add_facility", kwargs={"zone_id": zone_id})
            else:
                redirect_url = None
            if redirect_url:
                messages.warning(request, mark_safe(
                    _("Please login with the admin account you created, then create your facility and register this device to complete the setup.")))

        if get_installed_language_packs()['en']['language_pack_version'] == 0:
            alert_msg = "<p>{}</p>".format(_(
                "Dear Admin, you need to download a full version of the English "
                "language pack for KA Lite to work."
            )) + "<p><a href=\"{url}\">{msg}</a></p>".format(
                url=reverse("update_languages"),
                msg=_("Go to Language Management")
            )
            alert_msg = mark_safe(alert_msg)
            messages.warning(
                request,
                alert_msg
            )
        else:
            outdated_langpack_list = list(outdated_langpacks())
            if outdated_langpack_list:
                pretty_lang_names = " --- ".join(lang.get("name", "") for lang in outdated_langpack_list)
                messages.warning(
                    request, _(
                        "Dear Admin, please log in and upgrade the following "
                        "languages as soon as possible: {}"
                    ).format(pretty_lang_names)
                )

        return handler(request, *args, **kwargs)
Exemplo n.º 2
0
def homepage(request):
    """
    Homepage.
    """
    def _alert_outdated_languages(langpacks):
        pretty_lang_names = " --- ".join(lang.get("name", "") for lang in langpacks)
        messages.warning(request, _("Dear Admin, please log in and upgrade the following languages as soon as possible: {}").format(pretty_lang_names))

    outdated_langpack_list = list(outdated_langpacks())
    if outdated_langpack_list:
        _alert_outdated_languages(outdated_langpack_list)
    return {}
Exemplo n.º 3
0
    def check_setup_status_wrapper_fn(request, *args, **kwargs):

        if "registered" not in request.session:
            logging.error(
                "Key 'registered' not defined in session, but should be by now."
            )

        if request.is_admin:
            # TODO(bcipolli): move this to the client side?
            if not request.session.get("registered", True) and BaseClient(
            ).test_connection() == "success":
                # Being able to register is more rare, so prioritize.
                messages.warning(
                    request,
                    mark_safe(
                        _("Please <a href='%s'>follow the directions to register your device</a>, so that it can synchronize with the central server."
                          ) % reverse("register_public_key")))
            elif not request.session["facility_exists"]:
                zone_id = (Zone.objects.all()
                           and Zone.objects.all()[0].id) or "None"
                messages.warning(
                    request,
                    mark_safe(
                        _("Please <a href='%s'>create a facility</a> now. Users will not be able to sign up for accounts until you have made a facility."
                          ) %
                        reverse("add_facility", kwargs={"zone_id": zone_id})))

        elif not request.is_logged_in:
            if not request.session.get("registered", True) and BaseClient(
            ).test_connection() == "success":
                # Being able to register is more rare, so prioritize.
                redirect_url = reverse("register_public_key")
            elif not request.session["facility_exists"]:
                zone = Device.get_own_device().get_zone()
                zone_id = "None" if not zone else zone.id
                redirect_url = reverse("add_facility",
                                       kwargs={"zone_id": zone_id})
            else:
                redirect_url = None
            if redirect_url:
                messages.warning(
                    request,
                    mark_safe(
                        _("Please login with the admin account you created, then create your facility and register this device to complete the setup."
                          )))

        if get_installed_language_packs()['en']['language_pack_version'] == 0:
            alert_msg = "<p>{}</p>".format(
                _("Dear Admin, you need to download a full version of the English "
                  "language pack for KA Lite to work.")
            ) + "<p><a href=\"{url}\">{msg}</a></p>".format(
                url=reverse("update_languages"),
                msg=_("Go to Language Management"))
            alert_msg = mark_safe(alert_msg)
            messages.warning(request, alert_msg)
        else:
            outdated_langpack_list = list(outdated_langpacks())
            if outdated_langpack_list:
                pretty_lang_names = " --- ".join(
                    lang.get("name", "") for lang in outdated_langpack_list)
                messages.warning(
                    request,
                    _("Dear Admin, please log in and upgrade the following "
                      "languages as soon as possible: {}").format(
                          pretty_lang_names))

        return handler(request, *args, **kwargs)
Exemplo n.º 4
0
def english_content_pack_and_assessment_resources_are_current():
    return not should_upgrade_assessment_items() and ("en" not in [lp["code"] for lp in outdated_langpacks()])
Exemplo n.º 5
0
def english_content_pack_and_assessment_resources_are_current():
    return not should_upgrade_assessment_items() and ("en" not in [
        lp["code"] for lp in outdated_langpacks()
    ])