예제 #1
0
    def __init__(self, facility, *args, **kwargs):
        super(FacilityUserForm, self).__init__(*args, **kwargs)

        self.fields["default_language"].choices = [
            (lang_code, get_language_name(lang_code))
            for lang_code in get_installed_language_packs()
        ]

        # Select the initial default language,
        #   but only if we're not in the process of updating it to something else.
        if not self.fields[
                "default_language"].initial and "default_language" not in self.changed_data:
            self.fields["default_language"].initial = (
                self.instance
                and self.instance.default_language) or get_default_language()

        # Passwords only required on new, not on edit
        self.fields["password_first"].required = self.instance.pk == ""
        self.fields["password_recheck"].required = self.instance.pk == ""

        # Across POST and GET requests
        self.fields["zone_fallback"].initial = facility.get_zone()
        self.fields["facility"].initial = facility
        self.fields["facility"].queryset = Facility.objects.by_zone(
            facility.get_zone())
        self.fields["group"].queryset = FacilityGroup.objects.filter(
            facility=facility)
예제 #2
0
def update_languages(request):
    # also refresh language choices here if ever updates js framework fails, but the language was downloaded anyway
    installed_languages = get_installed_language_packs(force=True)

    # here we want to reference the language meta data we've loaded into memory
    context = update_context(request)
    context.update({
        "installed_languages": installed_languages.values(),
    })
    return context
예제 #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)
    def handle(self, *args, **options):

        if len(args) == 0:
            print self.help
            return

        languages = [args[0]]

        if languages[0] == "all":

            languages = get_installed_language_packs(force=True).keys()

        if options["update"]:
            for language in languages:
                call_command("retrievecontentpack", "download", language)

        for language in languages:

            print ""

            print "STATS FOR LANGUAGE {language}:".format(language=language)

            print ""

            try:
                print "\tMetadata:"
                for key, val in self.get_content_pack_metadata(language).items():
                    print "\t\t{key}: {val}".format(key=key, val=val)
            except IOError:
                print "\t\tDOES NOT EXIST!"
                continue

            print ""

            print "\tNumber of topics:", len(self.get_content_items_by_kind(language=language, kind="Topic"))
            print "\tNumber of videos:", len(self.get_content_items_by_kind(language=language, kind="Video"))
            print "\tNumber of unique videos:", len(set([item["youtube_id"] for item in self.get_content_items_by_kind(language=language, kind="Video")]))
            print "\tNumber of exercises:", len(self.get_content_items_by_kind(language=language, kind="Exercise"))
            print "\tNumber of unique exercises:", len(set([item["id"] for item in self.get_content_items_by_kind(language=language, kind="Exercise")]))
            print "\tNumber of assessment items:", self.count_assessment_items(language=language)

            print "\tNumber of subtitle files:", len(self.get_subtitles(language=language))

            print ""
예제 #5
0
파일: views.py 프로젝트: zhudy/ka-lite
    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)
예제 #6
0
파일: forms.py 프로젝트: Aypak/ka-lite
    def __init__(self, facility, *args, **kwargs):
        super(FacilityUserForm, self).__init__(*args, **kwargs)

        self.fields["default_language"].choices = [(lang_code, get_language_name(lang_code)) for lang_code in get_installed_language_packs()]

        # Select the initial default language,
        #   but only if we're not in the process of updating it to something else.
        if not self.fields["default_language"].initial and "default_language" not in self.changed_data:
            self.fields["default_language"].initial = (self.instance and self.instance.default_language) or get_default_language()

        # Passwords only required on new, not on edit
        self.fields["password_first"].required = self.instance.pk == ""
        self.fields["password_recheck"].required = self.instance.pk == ""

        # Across POST and GET requests
        self.fields["zone_fallback"].initial = facility.get_zone()
        self.fields["facility"].initial = facility
        self.fields["facility"].queryset = Facility.objects.by_zone(facility.get_zone())
        self.fields["group"].queryset = FacilityGroup.objects.filter(facility=facility)
예제 #7
0
    def handle(self, *args, **options):

        if len(args) == 0:
            print self.help
            return

        languages = [args[0]]

        if languages[0] == "all":

            languages = get_installed_language_packs(force=True).keys()

        if options["update"]:
            for language in languages:
                call_command("retrievecontentpack", "download", language)

        for language in languages:

            print ""

            print "STATS FOR LANGUAGE {language}:".format(language=language)

            print ""

            try:
                print "\tMetadata:"
                for key, val in self.get_content_pack_metadata(
                        language).items():
                    print "\t\t{key}: {val}".format(key=key, val=val)
            except IOError:
                print "\t\tDOES NOT EXIST!"
                continue

            print ""

            print "\tNumber of topics:", len(
                self.get_content_items_by_kind(language=language,
                                               kind="Topic"))
            print "\tNumber of videos:", len(
                self.get_content_items_by_kind(language=language,
                                               kind="Video"))
            print "\tNumber of unique videos:", len(
                set([
                    item["youtube_id"]
                    for item in self.get_content_items_by_kind(
                        language=language, kind="Video")
                ]))
            print "\tNumber of exercises:", len(
                self.get_content_items_by_kind(language=language,
                                               kind="Exercise"))
            print "\tNumber of unique exercises:", len(
                set([
                    item["id"] for item in self.get_content_items_by_kind(
                        language=language, kind="Exercise")
                ]))
            print "\tNumber of assessment items:", self.count_assessment_items(
                language=language)

            print "\tNumber of subtitle files:", len(
                self.get_subtitles(language=language))

            print ""