本文整理汇总了Python中sentry.db.models.utils.slugify_instance函数的典型用法代码示例。如果您正苦于以下问题:Python slugify_instance函数的具体用法?Python slugify_instance怎么用?Python slugify_instance使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了slugify_instance函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: transfer_to
def transfer_to(self, team):
from sentry.models import ReleaseProject
organization = team.organization
# We only need to delete ReleaseProjects when moving to a different
# Organization. Releases are bound to Organization, so it's not realistic
# to keep this link unless we say, copied all Releases as well.
if self.organization_id != organization.id:
ReleaseProject.objects.filter(
project_id=self.id,
).delete()
self.organization = organization
self.team = team
try:
with transaction.atomic():
self.update(
organization=organization,
team=team,
)
except IntegrityError:
slugify_instance(self, self.name, organization=organization)
self.update(
slug=self.slug,
organization=organization,
team=team,
)
示例2: save
def save(self, *args, **kwargs):
if not self.slug:
lock_key = 'slug:team'
with Lock(lock_key):
slugify_instance(self, self.name, organization=self.organization)
super(Team, self).save(*args, **kwargs)
else:
super(Team, self).save(*args, **kwargs)
示例3: save
def save(self, *args, **kwargs):
if not self.slug:
lock_key = "slug:organization"
with Lock(lock_key):
slugify_instance(self, self.name, reserved=RESERVED_ORGANIZATION_SLUGS)
super(Organization, self).save(*args, **kwargs)
else:
super(Organization, self).save(*args, **kwargs)
示例4: save
def save(self, *args, **kwargs):
if not self.slug:
lock_key = "slug:project"
with Lock(lock_key):
slugify_instance(self, self.name, organization=self.organization)
super(Project, self).save(*args, **kwargs)
else:
super(Project, self).save(*args, **kwargs)
示例5: save
def save(self, *args, **kwargs):
if not self.slug:
lock = locks.get('slug:organization', duration=5)
with TimedRetryPolicy(10)(lock.acquire):
slugify_instance(self, self.name, reserved=RESERVED_ORGANIZATION_SLUGS)
super(Organization, self).save(*args, **kwargs)
else:
super(Organization, self).save(*args, **kwargs)
示例6: save
def save(self, *args, **kwargs):
if not self.slug:
lock = locks.get('slug:project', duration=5)
with TimedRetryPolicy(10)(lock.acquire):
slugify_instance(self, self.name, organization=self.organization)
super(Project, self).save(*args, **kwargs)
else:
super(Project, self).save(*args, **kwargs)
示例7: merge_to
def merge_to(from_org, to_org):
from sentry.models import (
ApiKey, AuditLogEntry, OrganizationMember, OrganizationMemberTeam,
Project, Team
)
for from_member in OrganizationMember.objects.filter(organization=from_org):
try:
to_member = OrganizationMember.objects.get(
organization=to_org,
user=from_member.user,
)
except OrganizationMember.DoesNotExist:
from_member.update(organization=to_org)
to_member = from_member
else:
qs = OrganizationMemberTeam.objects.filter(
organizationmember=from_member,
is_active=True,
).select_related()
for omt in qs:
OrganizationMemberTeam.objects.create_or_update(
organizationmember=to_member,
team=omt.team,
defaults={
'is_active': True,
},
)
for team in Team.objects.filter(organization=from_org):
try:
with transaction.atomic():
team.update(organization=to_org)
except IntegrityError:
slugify_instance(team, team.name, organization=to_org)
team.update(
organization=to_org,
slug=team.slug,
)
for project in Project.objects.filter(organization=from_org):
try:
with transaction.atomic():
project.update(organization=to_org)
except IntegrityError:
slugify_instance(project, project.name, organization=to_org)
project.update(
organization=to_org,
slug=project.slug,
)
for model in (ApiKey, AuditLogEntry):
model.objects.filter(
organization=from_org,
).update(organization=to_org)
示例8: forwards
def forwards(self, orm):
from sentry.constants import RESERVED_ORGANIZATION_SLUGS
from sentry.db.models.utils import slugify_instance
from sentry.utils.query import RangeQuerySetWrapperWithProgressBar
Organization = orm['sentry.Organization']
queryset = Organization.objects.filter(slug__isnull=True)
for org in RangeQuerySetWrapperWithProgressBar(queryset):
slugify_instance(org, org.name, RESERVED_ORGANIZATION_SLUGS)
org.save()
transaction.commit()
示例9: save
def save(self, *args, **kwargs):
if not self.slug:
lock = locks.get('slug:project', duration=5)
with TimedRetryPolicy(10)(lock.acquire):
slugify_instance(
self,
self.name,
organization=self.organization,
reserved=RESERVED_PROJECT_SLUGS)
super(Project, self).save(*args, **kwargs)
else:
super(Project, self).save(*args, **kwargs)
self.update_rev_for_option()
示例10: create_team_and_keys_for_project
def create_team_and_keys_for_project(instance, created, **kwargs):
if not created or kwargs.get('raw'):
return
if not instance.owner:
return
if not instance.team:
team = Team(owner=instance.owner, name=instance.name)
slugify_instance(team, instance.slug)
team.save()
update(instance, team=team)
if not ProjectKey.objects.filter(project=instance, user__isnull=True).exists():
ProjectKey.objects.create(
project=instance,
)
示例11: forwards
def forwards(self, orm):
from sentry.constants import RESERVED_ORGANIZATION_SLUGS
from sentry.db.models.utils import slugify_instance
from sentry.utils.query import RangeQuerySetWrapperWithProgressBar
Project = orm['sentry.Project']
queryset = Project.objects.filter(
organization__isnull=True
).select_related('team', 'team__organization')
for project in RangeQuerySetWrapperWithProgressBar(queryset):
project.organization = project.team.organization
try:
atomic_save(project)
except IntegrityError:
# we also need to update the slug here based on the new constraints
slugify_instance(project, project.name, (
models.Q(organization=project.organization) | models.Q(team=project.team),
))
project.save()
示例12: handle
def handle(self, **options):
from django.db.models import Q
from sentry.constants import RESERVED_ORGANIZATION_SLUGS
from sentry.models import Organization, Project, Team, ProjectKey
from sentry.db.models import update
from sentry.db.models.utils import slugify_instance
from sentry.utils.query import RangeQuerySetWrapperWithProgressBar
print("Correcting data on organizations")
queryset = Organization.objects.filter(
slug__isnull=True,
)
for org in RangeQuerySetWrapperWithProgressBar(queryset):
slugify_instance(org, org.name, RESERVED_ORGANIZATION_SLUGS)
org.save()
# Create teams for any projects that are missing them
print("Correcting data on projects")
queryset = Project.objects.filter(
Q(team__isnull=True) | Q(organization__isnull=True),
).select_related('owner')
for project in RangeQuerySetWrapperWithProgressBar(queryset):
if not project.team:
organization = Organization(
name=project.name,
owner=project.owner,
)
slugify_instance(organization, organization.name, RESERVED_ORGANIZATION_SLUGS)
organization.save()
team = Team(
name=project.name,
owner=project.owner,
oprganization=organization,
)
slugify_instance(team, team.name, RESERVED_ORGANIZATION_SLUGS)
team.save()
update(project, organization=team.organization, team=team)
# Create missing project keys
print("Creating missing project keys")
queryset = Team.objects.all()
for team in RangeQuerySetWrapperWithProgressBar(queryset):
for member in team.member_set.select_related('user'):
for project in team.project_set.all():
try:
created = ProjectKey.objects.get_or_create(
project=project,
user=member.user,
)[1]
except ProjectKey.MultipleObjectsReturned:
pass
示例13: test_max_length
def test_max_length(self):
org = Organization(name='matt')
slugify_instance(org, 'matt', max_length=2)
assert org.slug == 'ma', org.slug
assert not Organization.objects.filter(slug='ma').exists()
示例14: test_reserved
def test_reserved(self):
base_slug = self.organization.slug
org = Organization(name='foo')
slugify_instance(org, base_slug, reserved=(base_slug,))
assert not org.slug.startswith(base_slug + '-'), org.slug
assert not Organization.objects.filter(slug=org.slug).exists()
示例15: save
def save(self, *args, **kwargs):
if not self.slug:
slugify_instance(self, self.name, reserved=RESERVED_TEAM_SLUGS)
super(Team, self).save(*args, **kwargs)