Ejemplo n.º 1
0
def easy_invite(request, emails=None):

    dajax = Dajax()

    try:
        emails_original = emails
        emails = emails.split(',')

        sender = request.user.profile
        default_group = sender.default_group
        domain = RequestSite(request).domain

        invited = []

        for email in emails:
            email = email.strip()
            if len(email) > 7 and re.match(
                    "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$",
                    email) is not None:
                invitation = Invitation(sender=request.user.profile,
                                        email=email,
                                        default_group=default_group)
                invitation.save()
                EmailInvitation(invitation=invitation,
                                sender=sender,
                                domain=domain).send_email()
                invited.append(email)

        if invited:
            template = 'core/tags/easy_invite_success'
        else:
            template = 'core/tags/easy_invite_failure'
    except:
        template = 'core/tags/easy_invite_failure'

    invite_markup = render_to_string(template, {},
                                     context_instance=RequestContext(request),
                                     response_format='html')

    dajax.add_data(
        {
            'target': "div.easy-invite[emails='{0!s}']".format(
                (emails_original)),
            'content': invite_markup
        }, 'anaf.add_data')
    return dajax.json()
Ejemplo n.º 2
0
def user_invite(request, emails=None, response_format='html'):
    "Invite people to Anaf"

    user_limit = settings.ANAF_SUBSCRIPTION_USER_LIMIT

    # Check whether any invites can be made at all
    if user_limit > 0:
        user_number = User.objects.filter(disabled=False).count()
        invites_left = user_limit - user_number
        if user_number >= user_limit:
            return HttpResponseRedirect(reverse('core_billing_upgrade'))
    else:
        invites_left = 100000000000000

    invited = []
    if request.POST or emails:
        sender = request.user.profile
        default_group = sender.default_group
        domain = RequestSite(request).domain
        if not emails:
            emails = request.POST.get('emails').split(',')

        # Check whether the number of invites + current users exceeds the limit
        if user_limit > 0:
            user_number = User.objects.filter(disabled=False).count()
            if len(emails) + user_number > user_limit:
                return HttpResponseRedirect(reverse('core_billing_upgrade'))

        for email in emails:
            email = email.strip()
            if len(email) > 7 and re.match("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$", email) is not None:
                if 0 < user_limit <= user_number:
                    break
                invitation = Invitation(
                    sender=request.user.profile, email=email, default_group=default_group)
                invitation.save()
                EmailInvitation(
                    invitation=invitation, sender=sender, domain=domain).send_email()
                invited.append(email)

    return render_to_response('core/administration/user_invite',
                              {'user_limit': user_limit,
                               'emails': emails,
                               'invites_left': invites_left,
                               'invited': invited},
                              context_instance=RequestContext(request), response_format=response_format)
Ejemplo n.º 3
0
Archivo: ajax.py Proyecto: tovmeod/anaf
def easy_invite(request, emails=None):

    dajax = Dajax()

    try:
        emails_original = emails
        emails = emails.split(',')

        sender = request.user.profile
        default_group = sender.default_group
        domain = RequestSite(request).domain

        invited = []

        for email in emails:
            email = email.strip()
            if len(email) > 7 and re.match("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$", email) is not None:
                invitation = Invitation(
                    sender=request.user.profile, email=email, default_group=default_group)
                invitation.save()
                EmailInvitation(
                    invitation=invitation, sender=sender, domain=domain).send_email()
                invited.append(email)

        if invited:
            template = 'core/tags/easy_invite_success'
        else:
            template = 'core/tags/easy_invite_failure'
    except:
        template = 'core/tags/easy_invite_failure'

    invite_markup = render_to_string(template,
                                     {},
                                     context_instance=RequestContext(request),
                                     response_format='html')

    dajax.add_data({'target': "div.easy-invite[emails='{0!s}']".format(
                   (emails_original)), 'content': invite_markup}, 'anaf.add_data')
    return dajax.json()