本文整理汇总了Python中account.models.SignupCode类的典型用法代码示例。如果您正苦于以下问题:Python SignupCode类的具体用法?Python SignupCode怎么用?Python SignupCode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SignupCode类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: cohort_member_add
def cohort_member_add(request, pk):
if not request.user.is_staff:
raise Http404()
cohort = Cohort.objects.get(pk=pk)
if "invite_next" in request.POST:
try:
N = int(request.POST["invite_next"])
except ValueError:
return redirect("waitinglist_cohort_detail", cohort.id)
# people who are NOT invited or on the site already
waiting_list = WaitingListEntry.objects.exclude(
email__in=SignupCode.objects.values("email")
).exclude(
email__in=User.objects.values("email")
)
emails = waiting_list.values_list("email", flat=True)[:N]
else:
email = request.POST["email"].strip()
if email:
emails = [email]
else:
emails = []
for email in emails:
if not SignupCode.objects.filter(email=email).exists():
signup_code = SignupCode.create(email=email, max_uses=1, expiry=730)
signup_code.save()
SignupCodeCohort.objects.create(signup_code=signup_code, cohort=cohort)
return redirect("waitinglist_cohort_detail", cohort.id)
示例2: invite
def invite(cls, from_user, to_email, message=None, send=True):
if not from_user.invitationstat.can_send():
raise NotEnoughInvitationsError()
signup_code = SignupCode.create(
email=to_email,
inviter=from_user,
expiry=settings.PINAX_INVITATIONS_DEFAULT_EXPIRATION,
check_exists=False # before we are called caller must check for existence
)
signup_code.save()
join = cls.objects.create(
from_user=from_user,
message=message,
status=JoinInvitation.STATUS_SENT,
signup_code=signup_code
)
def send_invite(*args, **kwargs):
signup_code.send(*args, **kwargs)
InvitationStat.objects.filter(user=from_user).update(
invites_sent=models.F("invites_sent") + 1
)
invite_sent.send(sender=cls, invitation=join)
if send:
send_invite()
else:
join.send_invite = send_invite
return join
示例3: setUp
def setUp(self):
self.to_user = User.objects.create(username="foo1")
self.from_user = User.objects.create(username="foo2")
self.signup_code = SignupCode.create(email="[email protected]")
self.signup_code.save()
self.status = JoinInvitation.STATUS_ACCEPTED
self.invitation = JoinInvitation.objects.create(
from_user=self.from_user, status=self.status, signup_code=self.signup_code
)
示例4: setup_signup_code
def setup_signup_code(self):
code = self.get_code()
if code:
try:
self.signup_code = SignupCode.check_code(code)
except SignupCode.InvalidCode:
self.signup_code = None
self.signup_code_present = True
else:
self.signup_code = None
self.signup_code_present = False
示例5: is_open
def is_open(self):
code = self.request.REQUEST.get('code')
if code:
try:
self.signup_code = SignupCode.check(code)
except SignupCode.InvalidCode:
return settings.ACCOUNT_OPEN_SIGNUP
else:
return True
else:
return settings.ACCOUNT_OPEN_SIGNUP
示例6: handle
def handle(self, *args, **options):
site = Site.objects.get_current()
expiry = int(args[2]) if len(args) > 2 else 768
with open(args[1], mode="w") as fh:
for i in range(int(args[0])):
signup = SignupCode.create(max_uses=1, expiry=expiry, check_exists=False)
fh.write("http://{0}{1}?code={2},".format(site.domain,
urlresolvers.reverse('account_signup'),
signup.code))
signup.save()
示例7: clean_code
def clean_code(self):
try:
signup_code = SignupCode.check(self.cleaned_data.get("code"))
except SignupCode.InvalidCode:
if not settings.ACCOUNT_OPEN_SIGNUP:
raise forms.ValidationError(_("Signup code is invalid."))
else:
return None
else:
if not settings.ACCOUNT_OPEN_SIGNUP and signup_code is None:
raise forms.ValidationError(_("Code is required to signup."))
return signup_code
示例8: test_valid_code
def test_valid_code(self):
signup_code = SignupCode.create()
signup_code.save()
with self.settings(ACCOUNT_OPEN_SIGNUP=False):
data = {
"username": "foo",
"password": "bar",
"password_confirm": "bar",
"email": "[email protected]",
"code": signup_code.code,
}
response = self.client.post(reverse("account_signup"), data)
self.assertEqual(response.status_code, 302)
示例9: test_register_with_moderation
def test_register_with_moderation(self):
signup_code = SignupCode.create()
signup_code.save()
with self.settings(ACCOUNT_OPEN_SIGNUP=True, ACCOUNT_APPROVAL_REQUIRED=True):
data = {
"username": "foo",
"password": "bar",
"password_confirm": "bar",
"email": "[email protected]",
"code": signup_code.code,
}
response = self.client.post(reverse("account_signup"), data)
self.assertEqual(response.status_code, 200)
self.assertFalse(self.client.session.get('_auth_user_id'))
u = User.objects.get(username=data['username'])
self.assertFalse(u.is_active)
示例10: is_open
def is_open(self):
code = self.request.REQUEST.get("code")
if code:
try:
self.signup_code = SignupCode.check(code)
except SignupCode.InvalidCode:
if self.messages.get("invalid_signup_code"):
messages.add_message(
self.request,
self.messages["invalid_signup_code"]["level"],
self.messages["invalid_signup_code"]["text"] % {
"code": code
}
)
return settings.ACCOUNT_OPEN_SIGNUP
else:
return True
else:
return settings.ACCOUNT_OPEN_SIGNUP
示例11: is_open
def is_open(self):
code = self.request.REQUEST.get('code')
if code:
try:
self.signup_code = SignupCode.check(code)
except SignupCode.InvalidCode:
if self.messages.get('invalid_signup_code'):
messages.add_message(
self.request,
self.messages['invalid_signup_code']['level'],
self.messages['invalid_signup_code']['text'].format(**{
'code': code
})
)
return settings.ACCOUNT_OPEN_SIGNUP
else:
return True
else:
return settings.ACCOUNT_OPEN_SIGNUP
示例12: get
def get(self, *args, **kwargs):
if self.request.user.is_authenticated():
return redirect(default_redirect(self.request, settings.ACCOUNT_LOGIN_REDIRECT_URL))
code = self.request.GET.get("code")
try:
self.signup_code = SignupCode.check(code)
except SignupCode.InvalidCode:
if not settings.ACCOUNT_OPEN_SIGNUP:
return self.closed(code=code)
else:
if self.messages.get("invalid_signup_code"):
messages.add_message(
self.request,
self.messages["invalid_signup_code"]["level"],
self.messages["invalid_signup_code"]["text"] % {
"code": code
}
)
if not settings.ACCOUNT_OPEN_SIGNUP and self.signup_code is None:
return self.closed()
return super(SignupView, self).get(*args, **kwargs)
示例13: invite
def invite(cls, from_user, to_email, message=None):
if not from_user.invitationstat.can_send():
raise NotEnoughInvitationsError()
signup_code = SignupCode.create(
email=to_email,
inviter=from_user,
expiry=DEFAULT_INVITE_EXPIRATION,
check_exists=False # before we are called caller must check for existence
)
signup_code.save()
join = cls.objects.create(
from_user=from_user,
message=message,
status=JoinInvitation.STATUS_SENT,
signup_code=signup_code
)
signup_code.send()
stat = from_user.invitationstat
stat.invites_sent += 1
stat.save()
invite_sent.send(sender=cls, invitation=join)
return join