本文整理汇总了Python中registration.signals.user_activated.connect函数的典型用法代码示例。如果您正苦于以下问题:Python connect函数的具体用法?Python connect怎么用?Python connect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了connect函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ready
def ready(self):
from shuup.core.models import CompanyContact
from .notify_events import send_company_activated_first_time_notification
from .signals import handle_user_activation
user_activated.connect(handle_user_activation)
if not hasattr(django.conf.settings, "ACCOUNT_ACTIVATION_DAYS"):
# Patch settings to include ACCOUNT_ACTIVATION_DAYS;
# it's a setting owned by `django-registration-redux`,
# but not set to a default value. If it's not set, a crash
# will occur when attempting to create an account, so
# for convenience, we're doing what `django-registration-redux`
# didn't wanna.
django.conf.settings.ACCOUNT_ACTIVATION_DAYS = 7
if not hasattr(django.conf.settings, "REGISTRATION_AUTO_LOGIN"):
# By default, Django-Registration considers this False, but
# we override it to True. unless otherwise set by the user.
django.conf.settings.REGISTRATION_AUTO_LOGIN = True
if not hasattr(django.conf.settings, "REGISTRATION_EMAIL_HTML"):
# We only provide txt templates out of the box, so default to
# false for HTML mails.
django.conf.settings.REGISTRATION_EMAIL_HTML = False
company_contact_activated.connect(
send_company_activated_first_time_notification,
sender=CompanyContact,
)
示例2: activate
def activate():
from django.db.models.signals import post_delete
from django.db.models.signals import post_save
from django.contrib.auth.models import Group
from django.contrib.auth.models import User
post_save.connect(dispatch_post_save_signal, sender=User)
post_save.connect(dispatch_post_save_signal, sender=Group)
post_delete.connect(dispatch_delete_signal, sender=User)
post_delete.connect(dispatch_delete_signal, sender=Group)
try:
from registration.signals import user_activated
from registration.signals import user_registered
user_activated.connect(dispatch_user_activated)
user_registered.connect(dispatch_user_registered)
except ImportError:
pass
示例3: ready
def ready(self):
if not hasattr(django.conf.settings, "ACCOUNT_ACTIVATION_DAYS"):
# Patch settings to include ACCOUNT_ACTIVATION_DAYS;
# it's a setting owned by `django-registration-redux`,
# but not set to a default value. If it's not set, a crash
# will occur when attempting to create an account, so
# for convenience, we're doing what `django-registration-redux`
# didn't wanna.
django.conf.settings.ACCOUNT_ACTIVATION_DAYS = 7
if not hasattr(django.conf.settings, "REGISTRATION_AUTO_LOGIN"):
# By default, Django-Registration considers this False, but
# we override it to True. unless otherwise set by the user.
django.conf.settings.REGISTRATION_AUTO_LOGIN = True
# connect signal here since the setting value has changed
user_activated.connect(login_user)
if not hasattr(django.conf.settings, "REGISTRATION_EMAIL_HTML"):
# We only provide txt templates out of the box, so default to
# false for HTML mails.
django.conf.settings.REGISTRATION_EMAIL_HTML = False
示例4:
dd_orders = DocDataPaymentOrder.objects.filter(email=user.email).all()
from bluebottle.wallposts.models import SystemWallPost
wallposts = None
for dd_order in dd_orders:
dd_order.customer_id = user.id
dd_order.save()
dd_order.order.user = user
dd_order.order.save()
dd_order.order.donations.update(user=user)
ctype = ContentType.objects.get_for_model(Donation)
for donation_id in dd_order.order.donations.values_list('id', flat=True):
qs = SystemWallPost.objects.filter(related_type=ctype, related_id=donation_id)
if not wallposts:
wallposts = qs
else:
pass
# This causes errors...
# wallposts += qs
if wallposts:
wallposts.update(author=user)
# On account activation try to connect anonymous donations to this fails.
user_activated.connect(link_anonymous_donations)
from signals import *
from fundmail import *
示例5: __unicode__
def __unicode__(self):
return u'Profile link.'
@models.permalink
def get_absolute_url(self):
return self.url
# Mozilla persona flow:
# Welcome email when a new account is created:
user_created.connect(
communications.send_welcome_email, dispatch_uid='browserid_welcome_email')
# Create a profile on new account creation:
user_created.connect(
Profile.active.get_or_create_for_user,
dispatch_uid='browserid_create_profile')
# US Ignite registration flow:
# Welcome email when new account is created:
user_activated.connect(
communications.send_welcome_email, dispatch_uid='registration_welcome_email')
user_activated.connect(
Profile.active.get_or_create_for_user,
dispatch_uid='registration_create_profile')
# Search:
watson.register(
Profile.objects.filter(is_public=True, user__is_active=True),
search.ProfileSearchAdapter
)
示例6: AuthorizationCode
class AuthorizationCode(BaseAppModel):
application = models.ForeignKey(Application)
user_profile = models.ForeignKey(UserProfile)
token = models.CharField(max_length=50)
def __unicode__(self):
return "%s : %s" % (self.application, self.token)
class AccessToken(BaseAppModel):
user_profile = models.ForeignKey(UserProfile)
application = models.ForeignKey(Application)
token = models.CharField(max_length=50)
def __unicode__(self):
return "%s : %s" % (self.user_profile, self.token)
def create_first_application(sender, **kwargs):
user_profile = kwargs["user"].get_profile()
if not Application.objects.filter(user_profile=user_profile).count():
client_id = "".join([random.choice(CLIENT_PARAMS_SPACE) \
for ii in range(0, 50)])
client_secret = "".join([random.choice(CLIENT_PARAMS_SPACE) \
for ii in range(0, 50)])
Application.objects.create(user_profile=user_profile,
client_id=client_id,
client_secret=client_secret)
user_activated.connect(create_first_application)
示例7: createUserScore
DEFAULT_USER_ID = 1
TAG_MAX_LEN = 32
HOST_CHOICES = (('ig', 'imgur'),) # keys are ideally 2 letters,
# cannot start with a number
# signals
def createUserScore(sender, **kwargs):
u = kwargs.get('user')
if u is not None:
us = UserScore(user=u)
us.save()
else:
print "user_activated signal caught, but UserScore not created"
user_activated.connect(createUserScore) # catch django_registration's
# user_activated signal and create
# necessary objects for user
# utility functions
def group(queryset, group, intermediate=False):
if intermediate:
for obj in queryset:
obj.gif.group = group
else:
for obj in queryset:
obj.group = group
return queryset
示例8: type
return notification
@property
def type(self):
return NOTIFICATION_TYPES.get(self.type_id, None)
def is_read(self):
# FIXME: this still modifies the model
if self.read is None and (not hasattr(self.type, 'is_read')
or hasattr(self.type, 'is_read')
and self.type.is_read(self)):
self.read = now()
self.save()
return self.read
def html(self):
try:
template = get_template('heronotification/%s.html' % self.type.__name__.lower())
except TemplateDoesNotExist:
template = get_template('heronotification/notification_base.html')
rendered = mark_safe(template.render(Context({'notification': self})))
return rendered
def welcome_new_user(sender, user, request, **kwargs):
welcome(user, get_system_user())
user_activated.connect(welcome_new_user)
示例9: autologin
"""
my_ct = ContentType.objects.get_for_model(self)
# get all user-specific permissions
user_levels = {}
for rm in UserObjectRoleMapping.objects.filter(object_id=self.id, object_ct=my_ct).all():
user_levels[rm.user.username] = rm.role.codename
levels = {}
for rm in GenericObjectRoleMapping.objects.filter(object_id=self.id, object_ct=my_ct).all():
levels[rm.subject] = rm.role.codename
levels['users'] = user_levels
return levels
# Logic to login a user automatically when it has successfully
# activated an account:
from registration.signals import user_activated
from django.contrib.auth import login
def autologin(sender, **kwargs):
user = kwargs['user']
request = kwargs['request']
# Manually setting the default user backed to avoid the
# 'User' object has no attribute 'backend' error
user.backend = 'django.contrib.auth.backends.ModelBackend'
# This login function does not need password.
login(request, user)
user_activated.connect(autologin)
示例10:
from techblog import signal_listeners
from registration.signals import user_activated
from django.contrib.comments.signals import comment_was_posted
user_activated.connect(signal_listeners.on_user_activate)
comment_was_posted.connect(signal_listeners.on_article_comment)
示例11: is_auto_login_enable
from registration.contrib.autologin.conf import settings
def is_auto_login_enable():
"""get whether the registration autologin is enable"""
if not settings.REGISTRATION_AUTO_LOGIN:
return False
if 'test' in sys.argv and not getattr(settings,
'_REGISTRATION_AUTO_LOGIN_IN_TESTS',
False):
# Registration Auto Login is not available in test to prevent the test
# fails of ``registration.tests.*``.
# For testing Registration Auto Login, you must set
# ``_REGISTRATION_AUTO_LOGIN_IN_TESTS`` to ``True``
return False
return True
def auto_login_reciver(sender, user, password, is_generated, request, **kwargs):
"""automatically log activated user in when they have activated"""
if not is_auto_login_enable() or is_generated:
# auto login feature is currently disabled by setting or
# the user was activated programatically by Django Admin action
# thus no auto login is required.
return
# A bit of a hack to bypass `authenticate()`
backend = get_backends()[0]
user.backend = '%s.%s' % (backend.__module__, backend.__class__.__name__)
login(request, user)
user_activated.connect(auto_login_reciver)
示例12: CharField
derived_from = CharField(max_length=64, blank=True)
creator = models.ForeignKey(User)
status = IntegerField(null=True, default=1)
author = CharField(max_length=100, blank=True, default="")
editor = CharField(max_length=100, blank=True, default="")
licensor = CharField(max_length=100, blank=True, default="")
maintainer = CharField(max_length=100, blank=True, default="")
translator = CharField(max_length=100, blank=True, default="")
coeditor = CharField(max_length=100, blank=True, default="")
def to_dict(self):
material = dict()
material['id'] = self.id
material['material_id'] = self.material_id
material['material_type'] = int(self.material_type)
material['text'] = self.text
material['version'] = self.version
material['title'] = self.title
material['description'] = self.description
material['categories'] = self.categories
material['status'] = self.status
material['modified'] = self.modified
if self.author:
material['author'] = self.author
return material
user_activated.connect(user_activated_callback, dispatch_uid="ACTIVE_USER")
示例13: get_short_name
def get_short_name(self):
return self.username
def __unicode__(self):
return '%s - %s' % (self.email, self.username)
def avatar_thumb(self):
if self.image:
return '<img src="%s%s" width="80px" height="80px"/>' %\
(settings.MEDIA_URL, get_thumbnail(self.image, '80x80', crop='center', quality=99).name)
else:
return '<img src="%simg/blank_user_80_80.jpg" width="80px" height="80px"/>' % settings.STATIC_URL
avatar_thumb.short_description = 'Avatar'
avatar_thumb.allow_tags = True
def user_activated_handler(sender, user, request, **kwargs):
# do something after account activation
pass
user_activated.connect(user_activated_handler, sender=None)
def user_registered_handler(sender, user, request, **kwargs):
# do something after account registration
pass
user_registered.connect(user_registered_handler, sender=None)
示例14: SocialUserForm
from registration.signals import user_activated
from socialregistration.forms import UserForm
from userprofile.models import UserProfile
class SocialUserForm(UserForm):
"""
A UserForm that also creates a UserProfile on saving
"""
def save(self, *args, **kwargs):
user = super(SocialUserForm, self).save(*args, **kwargs)
UserProfile.objects.create(user=user)
def create_userprofile(sender, **kwargs):
userprofile = UserProfile.objects.create(user=kwargs.get('user'))
user_activated.connect(create_userprofile, dispatch_uid="asdf")
示例15: view_locale
def view_locale(request):
loc_info = "getlocale: " + str(locale.getlocale()) + \
"<br/>getdefaultlocale(): " + str(locale.getdefaultlocale()) + \
"<br/>fs_encoding: " + str(sys.getfilesystemencoding()) + \
"<br/>sys default encoding: " + str(sys.getdefaultencoding())
return HttpResponse(loc_info)
class HomeView(TemplateView):
template_name = 'home.html'
def get_context_data(self, **kwargs):
context = super(HomeView, self).get_context_data(**kwargs)
context['stories'] = Story.objects.all().order_by('-date_created')[:5]
context['image'] = Source.objects.filter(source_type__label='photograph').filter(personassociatedsource__association__label='primary topic of').order_by('?')[0]
return context
class ContributeView(TemplateView):
template_name = 'contribute.html'
def user_created(sender, user, request, **kwargs):
g = Group.objects.get(name='contributor')
g.user_set.add(user)
g.save()
user_activated.connect(user_created)