当前位置: 首页>>代码示例>>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;未经允许,请勿转载。