示例#1
0
def extract_catalog_files(zf, lang):
    lang = lcode_to_django_lang(lang)
    modir = get_po_filepath(lang)
    ensure_dir(modir)

    filename_mapping = {"frontend.mo": "djangojs.mo",
                        "backend.mo": "django.mo"}

    for zipmo, djangomo in filename_mapping.items():
        zipmof = zf.open(zipmo)
        mopath = os.path.join(modir, djangomo)
        logging.debug("writing to %s" % mopath)
        with open(mopath, "wb") as djangomof:
            shutil.copyfileobj(zipmof, djangomof)
示例#2
0
def extract_catalog_files(zf, lang):
    lang = lcode_to_django_lang(lang)
    modir = get_po_filepath(lang)
    ensure_dir(modir)

    filename_mapping = {"frontend.mo": "djangojs.mo",
                        "backend.mo": "django.mo"}

    for zipmo, djangomo in filename_mapping.items():
        zipmof = zf.open(zipmo)
        mopath = os.path.join(modir, djangomo)
        logging.debug("writing to %s" % mopath)
        with open(mopath, "wb") as djangomof:
            shutil.copyfileobj(zipmof, djangomof)
示例#3
0
    def login(self, request, **kwargs):
        self.method_check(request, allowed=['post'])

        logout(request)

        data = self.deserialize(request,
                                request.body,
                                format=request.META.get(
                                    'CONTENT_TYPE', 'application/json'))

        username = data.get('username', '')
        password = data.get('password', '')
        facility = data.get('facility', '')

        # first try logging in as a Django user
        if not settings.CENTRAL_SERVER:
            user = authenticate(username=username, password=password)
            if user:
                login(request, user)
                return self.create_response(
                    request, {
                        'success': True,
                        'redirect': reverse("zone_redirect")
                    })

        # Find all matching users
        users = FacilityUser.objects.filter(username=username,
                                            facility=facility)

        if users.count() == 0:
            if Facility.objects.count() > 1:
                error_message = _(
                    "Username and password do not match. Make sure you choose the right facility."
                )
            else:
                error_message = _("Username and password do not match.")
            return self.create_response(
                request, {
                    'messages': {
                        'error': error_message
                    },
                    'error_highlight': "password"
                }, HttpUnauthorized)

        for user in users:
            if settings.SIMPLIFIED_LOGIN and not user.is_teacher:
                # For simplified login, as long as it is a student account just take the first one!
                break
            # if we find a user whose password matches, stop looking
            if user.check_password(password):
                break
            else:
                user = None

        if not user:
            if Facility.objects.count() > 1:
                error_message = _(
                    "Username and password do not match. Make sure you choose the right facility."
                )
            else:
                error_message = _("Username and password do not match.")
            return self.create_response(
                request, {
                    'messages': {
                        'error': error_message
                    },
                    'error_highlight': "password"
                }, HttpUnauthorized)
        else:
            try:
                UserLog.begin_user_activity(
                    user,
                    activity_type="login",
                    language=lcode_to_django_lang(request.language)
                )  # Success! Log the event (ignoring validation failures)
            except ValidationError as e:
                logging.error("Failed to begin_user_activity upon login: %s" %
                              e)

            request.session["facility_user"] = user
            messages.success(
                request,
                _("You've been logged in! We hope you enjoy your time with KA Lite "
                  ) + _("-- be sure to log out when you finish."))

            extras = {'success': True}
            if user.is_teacher:
                extras.update({
                    "redirect":
                    reverse("coach_reports",
                            kwargs={
                                "zone_id":
                                getattr(Device.get_own_device().get_zone(),
                                        "id", "None")
                            })
                })
            return self.create_response(request, extras)
示例#4
0
    def login(self, request, **kwargs):
        self.method_check(request, allowed=['post'])

        logout(request)

        data = self.deserialize(request, request.body, format=request.META.get('CONTENT_TYPE', 'application/json'))

        username = data.get('username', '')
        password = data.get('password', '')
        facility = data.get('facility', '')

        # first try logging in as a Django user
        if not settings.CENTRAL_SERVER:
            user = authenticate(username=username, password=password)
            if user:
                login(request, user)
                return self.create_response(request, {
                    'success': True,
                    'redirect': reverse("zone_redirect")
                    })

        # Find all matching users
        users = FacilityUser.objects.filter(username=username, facility=facility)

        if users.count() == 0:
            if Facility.objects.count() > 1:
                error_message = _("Username and password do not match. Make sure you choose the right facility.")
            else:
                error_message = _("Username and password do not match.")
            return self.create_response(request, {
                'messages': {'error': error_message},
                'error_highlight': "password"
                }, HttpUnauthorized )

        for user in users:
            if settings.SIMPLIFIED_LOGIN and not user.is_teacher:
                # For simplified login, as long as it is a student account just take the first one!
                break
            # if we find a user whose password matches, stop looking
            if user.check_password(password):
                break
            else:
                user = None

        if not user:
            if Facility.objects.count() > 1:
                error_message = _("Username and password do not match. Make sure you choose the right facility.")
            else:
                error_message = _("Username and password do not match.")
            return self.create_response(request, {
                'messages': {'error': error_message},
                'error_highlight': "password"
                }, HttpUnauthorized )
        else:
            try:
                UserLog.begin_user_activity(user, activity_type="login", language=lcode_to_django_lang(request.language))  # Success! Log the event (ignoring validation failures)
            except ValidationError as e:
                logging.error("Failed to begin_user_activity upon login: %s" % e)

            request.session["facility_user"] = user
            messages.success(request, _("You've been logged in! We hope you enjoy your time with KA Lite ")
                + _("-- be sure to log out when you finish."))

            extras = {'success': True}
            if user.is_teacher:
                extras.update({
                    "redirect": reverse("coach_reports", kwargs={"zone_id": getattr(Device.get_own_device().get_zone(), "id", "None")})
                })
            return self.create_response(request, extras)