def addto_user(request, pk): user = get_object_or_404(get_user_model(), pk=pk) amount = int(request.POST.get("amount")) InvitationStat.add_invites_to_user(user=user, amount=amount) return HttpResponse(json.dumps({ "html": amount }), content_type="application/json")
def invite_stat(request, pk): user = get_object_or_404(get_user_model(), pk=pk) return HttpResponse(json.dumps({ "html": render_to_string("kaleo/_invite_stat.html", {"stat": user.invitationstat}, context_instance=RequestContext(request)) }), content_type="application/json")
def invite_stat(request, pk): user = get_object_or_404(get_user_model(), pk=pk) return HttpResponse(json.dumps({ "html": render_to_string( "kaleo/_invite_stat.html", { "stat": user.invitationstat }, context_instance=RequestContext(request) ) }), content_type="application/json")
def topoff(cls, amount): "Makes sure all users have a certain number of invites" for user in get_user_model().objects.all(): cls.topoff_user(user, amount)
def add_invites(cls, amount): for user in get_user_model().objects.all(): cls.add_invites_to_user(user, amount)
def handle(self, *args, **kwargs): for user in get_user_model().objects.all(): stat, _ = InvitationStat.objects.get_or_create(user=user) stat.invites_allocated = -1 stat.save()
def get_user_lookup_kwargs(kwargs): result = {} username_field = getattr(get_user_model(), "USERNAME_FIELD", "username") for key, value in kwargs.items(): result[key.format(username=username_field)] = value return result
from django.db.models.signals import post_save from django.dispatch import receiver from account.models import SignupCodeResult, EmailConfirmation from account.signals import signup_code_used, email_confirmed, user_signed_up from kaleo.compat import get_user_model from kaleo.models import JoinInvitation, InvitationStat User = get_user_model() @receiver(signup_code_used, sender=SignupCodeResult) def handle_signup_code_used(sender, **kwargs): result = kwargs.get("signup_code_result") try: invite = result.signup_code.joininvitation invite.accept(result.user) except JoinInvitation.DoesNotExist: pass @receiver(email_confirmed, sender=EmailConfirmation) def handle_email_confirmed(sender, **kwargs): email_address = kwargs.get("email_address") JoinInvitation.process_independent_joins( user=email_address.user, email=email_address.email )
import json from django.http import HttpResponse from django.shortcuts import get_object_or_404 from django.template import RequestContext from django.template.loader import render_to_string from django.views.decorators.http import require_POST from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import permission_required from kaleo.compat import get_user_model from kaleo.forms import InviteForm from kaleo.models import JoinInvitation, InvitationStat User = get_user_model() @login_required @require_POST def invite(request): form = InviteForm(request.POST, user=request.user) if form.is_valid(): email = form.cleaned_data["email_address"] JoinInvitation.invite(request.user, email) form = InviteForm(user=request.user) data = { "html": render_to_string("kaleo/_invite_form.html", { "form": form, "user": request.user