本文整理汇总了Python中south.signals.post_migrate.connect函数的典型用法代码示例。如果您正苦于以下问题:Python connect函数的具体用法?Python connect怎么用?Python connect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了connect函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: patch
def patch():
global PATCHED
post_migrate.connect(_invalidate_on_migration)
if 'south' in settings.INSTALLED_APPS:
from south.signals import post_migrate as south_post_migrate
south_post_migrate.connect(_invalidate_on_migration)
_patch_cursor()
_patch_atomic()
_patch_orm()
PATCHED = True
示例2: post_migrate
continue
role.save()
role.permission_flags.add(permissionflag)
role.save()
if verbosity >= 2:
print "Created new role '%s' for group '%s' and assigned permission '%s'" % (rolename, group.name, permissionflag.name)
# handle both post_syncdb and post_migrate (if south is used)
def syncdb_compat(app_label, handler=None, *args, **kwargs):
if app_label=='community':
app = get_app(app_label)
models = get_models(app)
handler(app=app, created_models=models, verbosity=1, **kwargs)
def syncdb_compat_init_data(app, *args, **kwargs):
syncdb_compat(app, handler=init_data, *args, **kwargs)
def syncdb_compat_create_permission_flags(app, *args, **kwargs):
syncdb_compat(app, handler=create_permission_flags, *args, **kwargs)
if 'south' in settings.INSTALLED_APPS:
from south.signals import post_migrate
post_migrate.connect(syncdb_compat_init_data, dispatch_uid="communitytools.sphenecoll.sphene.community.management")
post_migrate.connect(syncdb_compat_create_permission_flags)
else:
from django.db.models.signals import post_syncdb
post_syncdb.connect(init_data, sender=models, dispatch_uid="communitytools.sphenecoll.sphene.community.management")
post_syncdb.connect(create_permission_flags)
示例3: update_permissions
from south.signals import post_migrate
def update_permissions(**kwargs):
import sys
sys.stdout.write("If there are new content types or permissions added, remember to run-> labgeeks update_permissions\n\n")
post_migrate.connect(update_permissions)
示例4: SiteSettings
perm, created = Permission.objects.get_or_create(codename='can_view', name='Can View Users', content_type=ct)
group, created = Group.objects.get_or_create(name='Volunteer')
if created:
p = Permission.objects.get(codename='add_userevent')
group.permissions.add(p)
group, created = Group.objects.get_or_create(name='Org_Admin')
if created:
p = Permission.objects.get(codename='add_organization')
group.permissions.add(p)
group, created = Group.objects.get_or_create(name='NHS_Admin')
if created:
p = Permission.objects.get(codename='can_view')
group.permissions.add(p)
if not SiteSettings.objects.exists():
settings = SiteSettings(site=Site.objects.get(pk=1), candidate_leadership_hours=50,
candidate_service_hours=100, member_service_hours=6).save()
def create_userprof(sender, instance, created, **kwargs):
"""for when the user is created on the first syncdb"""
if created and instance.is_superuser:
try:
up = instance.user_profile
except ObjectDoesNotExist:
UserProfile(user=instance, email_valid=True, grad_class=2000, membership_status='MEM').save()
#post_migrate.connect(add_user_permissions, sender=auth_models)
post_migrate.connect(add_groups)
post_save.connect(create_userprof, sender=User, dispatch_uid="create_userprof")
示例5: update_permissions_after_migration
# register a signal do update permissions every migration.
# This is based on app django_extensions update_permissions command
from south.signals import post_migrate
def update_permissions_after_migration(app,**kwargs):
"""
Update app permission just after every migration.
This is based on app django_extensions update_permissions management command.
"""
import settings
from django.db.models import get_app, get_models
from django.contrib.auth.management import create_permissions
create_permissions(get_app(app), get_models(), 2 if settings.DEBUG else 0)
post_migrate.connect(update_permissions_after_migration)
示例6:
# coding: utf-8
from south.signals import post_migrate, pre_migrate
from new_django_project._lib.db import load_customized_sql
pre_migrate.connect(load_customized_sql(name='pre_migrate'), weak=False)
post_migrate.connect(load_customized_sql(name='post_migrate'), weak=False)
示例7: sync_create_groups
# Remove all social auth associations
user.social_auth.all().delete()
@receiver(post_syncdb)
def sync_create_groups(sender, app, **kwargs):
'''
Create groups on syncdb.
'''
if (app == 'accounts'
or getattr(app, '__name__', '') == 'weblate.accounts.models'):
create_groups(False)
if 'south' in settings.INSTALLED_APPS:
from south.signals import post_migrate
post_migrate.connect(sync_create_groups)
@receiver(post_save, sender=User)
def create_profile_callback(sender, instance, created=False, **kwargs):
'''
Automatically adds user to Users group.
'''
if created:
# Add user to Users group if it exists
try:
group = Group.objects.get(name='Users')
instance.groups.add(group)
except Group.DoesNotExist:
pass
示例8: _migrate_perms
def _migrate_perms(*args, **kwargs):
"""
Ensure that all declared permissions on a model have been installed once
South migrations have been run.
"""
import sys
from django.contrib.auth.models import Permission
from django.contrib.contenttypes.models import ContentType
from django.db.models import get_app, get_models
for model in get_models(get_app(kwargs['app'])):
content_type = ContentType.objects.get_for_model(model)
for codename, name in model._meta.permissions:
perm, created = Permission.objects.get_or_create(
content_type=content_type,
codename=codename,
defaults={
'name': name
}
)
if created:
sys.stdout.write(
"Installed new permission {app_label}.{codename}\n".format(
app_label=model._meta.app_label,
codename=codename
)
)
post_migrate.connect(_migrate_perms)
示例9: get_preindex_plugins
sync_docs.copy_designs(
db=self.db(app_label),
design_name=app_label,
temp=temp,
delete=delete,
)
def get_preindex_plugins():
return PREINDEX_PLUGINS.values()
def catch_signal(app, **kwargs):
"""Function used by syncdb signal"""
app_name = app.__name__.rsplit('.', 1)[0]
app_label = app_name.split('.')[-1]
if app_label in PREINDEX_PLUGINS:
PREINDEX_PLUGINS[app_label].sync_design_docs()
signals.post_syncdb.connect(catch_signal)
# and totally unrelatedly...
def sync_south_app(app, **kwargs):
syncdb(get_app(app), None, **kwargs)
post_migrate.connect(sync_south_app)
示例10: post_save_handler
if os.path.isfile(theme_info_file):
config = ConfigParser.ConfigParser()
config.read(theme_info_file)
default = ConfigParser.DEFAULTSECT
theme_name = config.get(default, 'name', self.directory_name)
theme_description = config.get(default, 'description', '')
else:
theme_name = self.directory_name
theme_description = ''
self.name = theme_name
self.description = theme_description
if commit:
self.save()
def post_save_handler(sender, instance, **kwargs):
if instance.active:
for theme in Theme.objects.filter(active=True).exclude(id=instance.id):
theme.active = False
theme.save()
Theme.objects.clear_cache()
def check_for_themes(sender, **kwargs):
from merengue.theming.checker import check_themes
check_themes()
signals.post_save.connect(post_save_handler, sender=Theme)
post_migrate.connect(check_for_themes)
示例11: update_contenttypes
# coding:utf-8
from django.contrib.contenttypes.models import ContentType
from django.db.models import signals
from django.utils.encoding import smart_unicode
from django.conf import settings
def update_contenttypes(app, **kwargs):
#No post_syncdb o app é um object, já no post_migrate é uma string
if not isinstance(app, str):
app = app.__name__.split('.')[-2]
for ct in ContentType.objects.filter(app_label=app):
try:
name = smart_unicode(ct.model_class()._meta.verbose_name_raw)
if ct.name != name:
print "Updating ContentType's name: '%s' -> '%s'" % (ct.name, name)
ct.name=name
ct.save()
except: pass
# Se tiver a aplicação south no INSTALLED_APPS,
# ele conecta o update_contenttypes ao post_migrate
if 'south' in settings.INSTALLED_APPS:
from south.signals import post_migrate
post_migrate.connect(update_contenttypes)
signals.post_syncdb.connect(update_contenttypes)
示例12: ensure_auth_objects
password='',
first_name='Guest',
last_name='McGuesterson',
)
user.set_unusable_password()
user.save()
member = Member.objects.get(user=user)
member.hidden = True
member.save()
else:
user = User.objects.get(id=settings.ANONYMOUS_USER_ID)
try:
member = user.member
except Member.DoesNotExist:
user.member, created = Member.objects.get_or_create(user=user)
user.save()
return user
post_save.connect(create_member, sender=AnonymousUser)
post_save.connect(create_rank, sender=AuthenticatedUserGroup)
def ensure_auth_objects(*args, **kwargs):
try:
get_anonymous_user()
get_authenticated_user_group()
except:
pass
post_migrate.connect(ensure_auth_objects)
post_syncdb.connect(ensure_auth_objects)
示例13: __unicode__
callback = models.TextField()
def __unicode__(self):
return "Achievement(%s, %s)" % (self.name, self.bonus)
class UserAchievement(models.Model):
user = models.ForeignKey(User)
achievement = models.ForeignKey(Achievement, related_name="userachievements")
registered_at = models.DateTimeField(auto_now_add=True)
class AchievementEngineConf(AppConf):
""" Configuration class used by Django AppConf to ease the setup"""
USE_CELERY = False
CLASSES = []
class Meta:
prefix = 'achievement'
#def configure_classes(self, value):
# pass
# connect to the end of the syncdb command signal to reload achievements at that time.
if 'south' in settings.INSTALLED_APPS:
from south.signals import post_migrate
post_migrate.connect(load_classes)
else:
from django.db.models.signals import post_syncdb
post_syncdb.connect(load_classes)
示例14: map
from django.db import connection
from south import migration
from south.signals import post_migrate
from boris import reporting
# Get a list of all the apps that use migrations.
APPS_TO_WAIT_FOR = map(methodcaller('app_label'), migration.all_migrations())
def install_views(app, **kwargs):
global APPS_TO_WAIT_FOR
APPS_TO_WAIT_FOR.remove(app)
if len(APPS_TO_WAIT_FOR) == 0:
print "Installing reporting views ..."
cursor = connection.cursor()
sql_file = open(join(dirname(reporting.__file__), 'sql', 'reporting-views.mysql.sql'), 'r')
try:
cursor.execute(sql_file.read())
finally:
sql_file.close()
post_migrate.connect(install_views)
示例15: isinstance
auth = resource._meta.authorization
content_type = ContentType.objects.get_for_model(resource._meta.queryset.model)
if isinstance(auth, SpiffAuthorization):
conditions = auth.conditions()
operations = auth.operations()
if len(conditions) == 0:
conditions = (None,)
for condition in conditions:
for operation in operations:
# build our permission slug
if condition:
codename = "%s_%s_%s" % (operation[0], condition[0], content_type.model)
name = "Can %s %s, when %s" % (operation[1], content_type.name,
condition[1])
else:
codename = "%s_%s" % (operation[1], content_type.model)
name = "Can %s %s" % (operation[1], content_type.name)
# if it doesn't exist..
if not Permission.objects.filter(content_type=content_type, codename=codename):
# add it
Permission.objects.create(content_type=content_type,
codename=codename,
name=name[:49])
funcLog().debug("Created permission %s.%s (%s)", content_type.app_label, codename, name)
# check for all our view permissions after a syncdb
post_migrate.connect(add_resource_permissions)
post_syncdb.connect(add_resource_permissions)