How to use the kolibri.core.auth.models.Facility.objects.get function in kolibri

To help you get started, we’ve selected a few kolibri examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github learningequality / kolibri / kolibri / core / auth / models.py View on Github external
def get_facility(self):
        """
        Gets the ``Classroom``'s parent ``Facility``.

        :return: A ``Facility`` instance.
        """
        return Facility.objects.get(id=self.parent_id)
github learningequality / kolibri / kolibri / core / auth / permissions / general.py View on Github external
def _user_is_admin_for_own_facility(self, user, obj=None):

        # import here to avoid circular imports
        from ..models import Facility

        if not hasattr(user, "dataset"):
            return False

        # if we've been given an object, make sure it too is from the same dataset (facility)
        if obj:
            if not hasattr(obj, "dataset") or not user.dataset == obj.dataset:
                return False

        facility = Facility.objects.get(dataset=user.dataset)
        return user.has_role_for_collection(role_kinds.ADMIN, facility)
github learningequality / kolibri / kolibri / core / auth / management / commands / importusers.py View on Github external
def handle(self, *args, **options):
        if options["facility"]:
            default_facility = Facility.objects.get(pk=options["facility"])
        else:
            default_facility = Facility.get_default_facility()

        if not default_facility:
            raise CommandError(
                "No default facility exists, please make sure to provision this device before running this command"
            )

        fieldnames = ["full_name", "username", "password", "facility", "class"]
        # open using default OS encoding
        with open(options["filepath"]) as f:
            header = next(csv.reader(f, strict=True))
            if all(col in fieldnames for col in header):
                # Every item in the first row matches an item in the fieldnames, it is a header row
                if "username" not in header:
                    raise CommandError(
github learningequality / kolibri / kolibri / core / auth / management / commands / bulkexportusers.py View on Github external
def get_facility(self, options):
        if options["facility"]:
            default_facility = Facility.objects.get(pk=options["facility"])
        else:
            default_facility = Facility.get_default_facility()
        if not default_facility:
            self.overall_error.append(MESSAGES[NO_FACILITY])
            raise CommandError(self.overall_error[-1])

        return default_facility
github learningequality / kolibri / kolibri / core / auth / management / commands / importusers.py View on Github external
def infer_facility(user, default_facility):
    if "facility" in user and user["facility"]:
        try:
            # Try lookup by id first, then name
            return Facility.objects.get(pk=user["facility"])
        except (Facility.DoesNotExist, ValueError):
            try:
                return Facility.objects.get(name=user["facility"])
            except Facility.DoesNotExist:
                raise CommandError(
                    "Facility matching identifier {facility} was not found".format(
                        facility=user["facility"]
                    )
                )
    else:
        return default_facility
github learningequality / kolibri / kolibri / core / auth / permissions / general.py View on Github external
def _user_is_admin_for_own_facility(user, obj=None):

    # import here to avoid circular imports
    from ..models import Facility

    if not hasattr(user, "dataset"):
        return False

    # if we've been given an object, make sure it too is from the same dataset (facility)
    if obj:
        if not hasattr(obj, "dataset") or not user.dataset == obj.dataset:
            return False

    facility = Facility.objects.get(dataset=user.dataset)
    return user.has_role_for_collection(role_kinds.ADMIN, facility)
github learningequality / kolibri / kolibri / core / auth / csv_utils.py View on Github external
def infer_facility(facility_id, facility=None):
    if facility_id:
        try:
            # Try lookup by id first, then name
            facility = Facility.objects.get(pk=facility_id)
        except (Facility.DoesNotExist, ValueError):
            try:
                facility = Facility.objects.get(name=facility_id)
            except Facility.DoesNotExist:
                raise ValueError(
                    "Facility matching identifier {facility} was not found".format(
                        facility=facility_id
                    )
                )
    elif facility is not None:
        return facility
    else:
        facility = Facility.get_default_facility()
        if facility:
            logger.info(
                "No facility specified, using the default facility {}".format(
                    facility.name
                )
            )
github learningequality / kolibri / kolibri / core / auth / management / commands / bulkimportusers.py View on Github external
def get_facility(self, options):
        if options["facility"]:
            default_facility = Facility.objects.get(pk=options["facility"])
        else:
            default_facility = Facility.get_default_facility()
        if not default_facility:
            self.overall_error.append(MESSAGES[NO_FACILITY])
            raise CommandError(self.overall_error[-1])

        return default_facility