當前位置: 首頁>>代碼示例>>Python>>正文


Python swapper.load_model方法代碼示例

本文整理匯總了Python中swapper.load_model方法的典型用法代碼示例。如果您正苦於以下問題:Python swapper.load_model方法的具體用法?Python swapper.load_model怎麽用?Python swapper.load_model使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在swapper的用法示例。


在下文中一共展示了swapper.load_model方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: organizations_pk

# 需要導入模塊: import swapper [as 別名]
# 或者: from swapper import load_model [as 別名]
def organizations_pk(self):
        """
        returns primary keys of organizations the user is associated to
        """
        logger.warn(
            "User.organizations_pk is deprecated in favor of User.organizations_dict"
            " and will be removed in a future version"
        )
        manager = load_model('openwisp_users', 'OrganizationUser').objects
        qs = (
            manager.filter(user=self, organization__is_active=True)
            .select_related()
            .only('organization_id')
            .values_list('organization_id')
        )
        return qs 
開發者ID:openwisp,項目名稱:openwisp-users,代碼行數:18,代碼來源:models.py

示例2: _read_subnet_data

# 需要導入模塊: import swapper [as 別名]
# 或者: from swapper import load_model [as 別名]
def _read_subnet_data(self, reader):
        subnet_model = load_model('openwisp_ipam', 'Subnet')
        subnet_name = next(reader)[0].strip()
        subnet_value = next(reader)[0].strip()
        subnet_org = self._get_or_create_org(next(reader)[0].strip())
        try:
            subnet = subnet_model.objects.get(
                subnet=subnet_value, organization=subnet_org
            )
        except ValidationError as e:
            raise CsvImportException(str(e))
        except subnet_model.DoesNotExist:
            try:
                subnet = subnet_model(
                    name=subnet_name, subnet=subnet_value, organization=subnet_org
                )
                subnet.full_clean()
                subnet.save()
            except ValidationError as e:
                raise CsvImportException(str(e))
        return subnet 
開發者ID:openwisp,項目名稱:openwisp-ipam,代碼行數:23,代碼來源:models.py

示例3: _read_ipaddress_data

# 需要導入模塊: import swapper [as 別名]
# 或者: from swapper import load_model [as 別名]
def _read_ipaddress_data(self, reader, subnet):
        ipaddress_model = load_model('openwisp_ipam', 'IpAddress')
        ipaddress_list = []
        for row in reader:
            if not ipaddress_model.objects.filter(
                subnet=subnet, ip_address=row[0].strip(),
            ).exists():
                instance = ipaddress_model(
                    subnet=subnet,
                    ip_address=row[0].strip(),
                    description=row[1].strip(),
                )
                try:
                    instance.full_clean()
                except ValueError as e:
                    raise CsvImportException(str(e))
                ipaddress_list.append(instance)
        for ip in ipaddress_list:
            ip.save() 
開發者ID:openwisp,項目名稱:openwisp-ipam,代碼行數:21,代碼來源:models.py

示例4: export_csv

# 需要導入模塊: import swapper [as 別名]
# 或者: from swapper import load_model [as 別名]
def export_csv(self, subnet_id, writer):
        ipaddress_model = load_model('openwisp_ipam', 'IpAddress')
        subnet = load_model('openwisp_ipam', 'Subnet').objects.get(pk=subnet_id)
        writer.writerow([subnet.name])
        writer.writerow([subnet.subnet])
        writer.writerow('')
        fields = [
            ipaddress_model._meta.get_field('ip_address'),
            ipaddress_model._meta.get_field('description'),
        ]
        writer.writerow(field.name for field in fields)
        for obj in subnet.ipaddress_set.all():
            row = []
            for field in fields:
                row.append(str(getattr(obj, field.name)))
            writer.writerow(row) 
開發者ID:openwisp,項目名稱:openwisp-ipam,代碼行數:18,代碼來源:models.py

示例5: auto_add_to_devices

# 需要導入模塊: import swapper [as 別名]
# 或者: from swapper import load_model [as 別名]
def auto_add_to_devices(self):
        """
        When ``auto_add`` is ``True``, adds the credentials
        to each relevant ``Device`` and ``DeviceConnection`` objects
        """
        if not self.auto_add:
            return
        device_model = load_model('config', 'Device')
        devices = device_model.objects.exclude(config=None)
        org = self.organization
        if org:
            devices = devices.filter(organization=org)
        # exclude devices which have been already added
        devices = devices.exclude(deviceconnection__credentials=self)
        for device in devices:
            DeviceConnection = load_model('connection', 'DeviceConnection')
            conn = DeviceConnection(device=device, credentials=self, enabled=True)
            conn.full_clean()
            conn.save() 
開發者ID:openwisp,項目名稱:openwisp-controller,代碼行數:21,代碼來源:models.py

示例6: ready

# 需要導入模塊: import swapper [as 別名]
# 或者: from swapper import load_model [as 別名]
def ready(self):
        """
        connects the ``config_modified`` signal
        to the ``update_config`` celery task
        which will be executed in the background
        """
        config_modified.connect(
            self.config_modified_receiver, dispatch_uid='connection.update_config'
        )
        Config = load_model('config', 'Config')
        Credentials = load_model('connection', 'Credentials')
        post_save.connect(
            Credentials.auto_add_credentials_to_device,
            sender=Config,
            dispatch_uid='connection.auto_add_credentials',
        ) 
開發者ID:openwisp,項目名稱:openwisp-controller,代碼行數:18,代碼來源:apps.py

示例7: create_guest

# 需要導入模塊: import swapper [as 別名]
# 或者: from swapper import load_model [as 別名]
def create_guest():
    Person = swapper.load_model('kernel', 'person')
    password = ''.join(random.choice(string.ascii_letters) for i in range(10))

    guest_user = User.objects.create_user(
        username=settings.GUEST_USERNAME,
        password=password
    )
    guest_person, _ = Person.objects.get_or_create(
        user=guest_user,
        short_name=settings.GUEST_USERNAME,
        full_name=settings.GUEST_USERNAME
    )

    Guest = swapper.load_model('kernel', 'Guest')
    Guest.objects.get_or_create(person=guest_person, start_date=datetime.date.today())
    return guest_user 
開發者ID:IMGIITRoorkee,項目名稱:omniport-backend,代碼行數:19,代碼來源:create_guest.py

示例8: clean

# 需要導入模塊: import swapper [as 別名]
# 或者: from swapper import load_model [as 別名]
def clean(self):
        if not self.subnet:
            return
        allowed_master = None
        for subnet in load_model('django_ipam', 'Subnet').objects.filter().values():
            if self.id == subnet['id']:
                continue
            if ip_network(self.subnet).overlaps(subnet['subnet']):
                if not self.master_subnet and not subnet['subnet'].subnet_of(ip_network(self.subnet)):
                    raise ValidationError({
                        'subnet': _('Subnet overlaps with %s') % subnet['subnet']
                    })
                if not allowed_master or subnet['subnet'].subnet_of(allowed_master):
                    allowed_master = subnet['subnet']

        if self.master_subnet:
            if not ip_network(self.subnet).subnet_of(ip_network(self.master_subnet.subnet)):
                raise ValidationError({
                    'master_subnet': _('Invalid master subnet')
                })
            if ip_network(self.master_subnet.subnet) != allowed_master and not \
                    allowed_master.subnet_of(ip_network(self.subnet)):
                raise ValidationError({
                    'subnet': _('Subnet overlaps with %s') % allowed_master
                }) 
開發者ID:openwisp,項目名稱:django-ipam,代碼行數:27,代碼來源:models.py

示例9: _read_subnet_data

# 需要導入模塊: import swapper [as 別名]
# 或者: from swapper import load_model [as 別名]
def _read_subnet_data(self, reader):
        subnet_model = load_model('django_ipam', 'Subnet')
        subnet_name = next(reader)[0].strip()
        subnet_value = next(reader)[0].strip()
        try:
            subnet = subnet_model.objects.get(name=subnet_name,
                                              subnet=subnet_value)
        except ValidationError as e:
            raise CsvImportException(str(e))
        except subnet_model.DoesNotExist:
            try:
                subnet = subnet_model(name=subnet_name,
                                      subnet=subnet_value)
                subnet.full_clean()
                subnet.save()
            except ValidationError as e:
                raise CsvImportException(str(e))
        return subnet 
開發者ID:openwisp,項目名稱:django-ipam,代碼行數:20,代碼來源:models.py

示例10: _read_ipaddress_data

# 需要導入模塊: import swapper [as 別名]
# 或者: from swapper import load_model [as 別名]
def _read_ipaddress_data(self, reader, subnet):
        ipaddress_model = load_model('django_ipam', 'IpAddress')
        ipaddress_list = []
        for row in reader:
            if not ipaddress_model.objects.filter(subnet=subnet,
                                                  ip_address=row[0].strip(),
                                                  description=row[1].strip()).exists():
                instance = ipaddress_model(subnet=subnet,
                                           ip_address=row[0].strip(),
                                           description=row[1].strip())
                try:
                    instance.full_clean()
                except ValueError as e:
                    raise CsvImportException(str(e))
                ipaddress_list.append(instance)
        for ip in ipaddress_list:
            ip.save() 
開發者ID:openwisp,項目名稱:django-ipam,代碼行數:19,代碼來源:models.py

示例11: send_token

# 需要導入模塊: import swapper [as 別名]
# 或者: from swapper import load_model [as 別名]
def send_token(self):
        OrganizationUser = swapper.load_model('openwisp_users', 'OrganizationUser')
        org_user = OrganizationUser.objects.filter(user=self.user).first()
        if not org_user:
            raise exceptions.NoOrgException(
                'User {} is not member ' 'of any organization'.format(self.user)
            )
        org_radius_settings = org_user.organization.radius_settings
        message = _('{} verification code: {}').format(
            org_radius_settings.organization.name, self.token
        )
        sms_message = SmsMessage(
            body=message,
            from_phone=str(org_radius_settings.sms_sender),
            to=[str(self.user.phone_number)],
        )
        sms_message.send(meta_data=org_radius_settings.sms_meta_data) 
開發者ID:openwisp,項目名稱:openwisp-radius,代碼行數:19,代碼來源:models.py

示例12: organizations_dict

# 需要導入模塊: import swapper [as 別名]
# 或者: from swapper import load_model [as 別名]
def organizations_dict(self):
        """
        Returns a dictionary which represents the organizations which
        the user is member of, or which the user manages or owns.
        """
        cache_key = 'user_{}_organizations'.format(self.pk)
        organizations = cache.get(cache_key)
        if organizations is not None:
            return organizations

        manager = load_model('openwisp_users', 'OrganizationUser').objects
        org_users = manager.filter(
            user=self, organization__is_active=True
        ).select_related('organization', 'organizationowner')

        organizations = {}
        for org_user in org_users:
            org = org_user.organization
            org_id = str(org.pk)
            organizations[org_id] = {
                'is_admin': org_user.is_admin,
                'is_owner': hasattr(org_user, 'organizationowner'),
            }

        cache.set(cache_key, organizations, 86400 * 2)  # Cache for two days
        return organizations 
開發者ID:openwisp,項目名稱:openwisp-users,代碼行數:28,代碼來源:models.py

示例13: connect_receivers

# 需要導入模塊: import swapper [as 別名]
# 或者: from swapper import load_model [as 別名]
def connect_receivers(self):
        OrganizationUser = load_model('openwisp_users', 'OrganizationUser')
        OrganizationOwner = load_model('openwisp_users', 'OrganizationOwner')
        signal_tuples = [(post_save, 'post_save'), (post_delete, 'post_delete')]

        for model in [OrganizationUser, OrganizationOwner]:
            for signal, name in signal_tuples:
                signal.connect(
                    self.update_organizations_dict,
                    sender=model,
                    dispatch_uid='{}_{}_update_organizations_dict'.format(
                        name, model.__name__
                    ),
                ) 
開發者ID:openwisp,項目名稱:openwisp-users,代碼行數:16,代碼來源:apps.py

示例14: set_default_group

# 需要導入模塊: import swapper [as 別名]
# 或者: from swapper import load_model [as 別名]
def set_default_group(sender, instance, created, **kwargs):
    if created:
        RadiusGroup = swapper.load_model("django_freeradius", "RadiusGroup")
        RadiusUserGroup = swapper.load_model("django_freeradius", "RadiusUserGroup")
        queryset = RadiusGroup.objects.filter(default=True)
        if queryset.exists():
            ug = RadiusUserGroup(user=instance, group=queryset.first())
            ug.full_clean()
            ug.save() 
開發者ID:openwisp,項目名稱:django-freeradius,代碼行數:11,代碼來源:utils.py

示例15: clean

# 需要導入模塊: import swapper [as 別名]
# 或者: from swapper import load_model [as 別名]
def clean(self):
        if not self.subnet:
            return
        allowed_master = None
        for subnet in load_model('openwisp_ipam', 'Subnet').objects.filter().values():
            if self.id == subnet['id']:
                continue
            if ip_network(self.subnet).overlaps(subnet['subnet']):
                if not self.master_subnet and not subnet['subnet'].subnet_of(
                    ip_network(self.subnet)
                ):
                    raise ValidationError(
                        {'subnet': _('Subnet overlaps with %s') % subnet['subnet']}
                    )
                if not allowed_master or subnet['subnet'].subnet_of(allowed_master):
                    allowed_master = subnet['subnet']

        if self.master_subnet:
            if not ip_network(self.subnet).subnet_of(
                ip_network(self.master_subnet.subnet)
            ):
                raise ValidationError({'master_subnet': _('Invalid master subnet')})
            if ip_network(
                self.master_subnet.subnet
            ) != allowed_master and not allowed_master.subnet_of(
                ip_network(self.subnet)
            ):
                raise ValidationError(
                    {'subnet': _('Subnet overlaps with %s') % allowed_master}
                ) 
開發者ID:openwisp,項目名稱:openwisp-ipam,代碼行數:32,代碼來源:models.py


注:本文中的swapper.load_model方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。