Ejemplo n.º 1
0
def invitation_list(request):
    system_message = None
    if request.POST:
        if "invitation" in request.POST:
            invitations = request.POST.getlist("invitation")
            for invitation in invitations:
                invite = Invitation.objects.get(id=invitation)
                invite.approved_date = datetime.now()
                invite.save()
                plaintext = get_template("email/create_profile.txt")
                d = Context({"uid": invite.signup_key})
                text_content = plaintext.render(d)
                queue_email(ACCESS_REQUEST_APPROVED_SUBJECT, text_content, invite.email, ACCESS_REQUEST_APPROVED_EVENT)
            system_message = "Access request(s) approved!"

    invitation_list = Invitation.objects.filter(approved_date=None)
    paginator = Paginator(invitation_list, RECORDS_PER_PAGE)
    page = request.GET.get("page")
    try:
        invitations = paginator.page(page)
    except PageNotAnInteger:
        invitations = paginator.page(1)
    except EmptyPage:
        invitations = paginator.page(paginator.num_pages)

    return render_to_response(
        "invitation_list.html",
        {"system_message": system_message, "invitations": invitations},
        context_instance=RequestContext(request),
    )
def invite(request):
    system_message = None
    profile_id = request.session['profile_id']
    max_invitations = 5
    existing_invites = Profile_Invite.objects.filter(profile_id=profile_id)
    invites_remaining = max_invitations - existing_invites.count()

    if invites_remaining <= 0:
        system_message = "You have used all invites."
    else:
        if request.POST:
            post_form = UserInviteForm(request.POST)
            if post_form.is_valid():
                email = request.POST['email']
                message = request.POST['message']
                uid = uuid.uuid4()
                promotion = 'USER'
                p = Promotion.objects.get(code=promotion)
                promotion_id = p.pk
                p = Profile.objects.get(pk=profile_id)

                try:
                    with transaction.commit_on_success():
                        new_invite = Invitation.objects.create(
                            email=email,
                            signup_key=uid,
                            promotion_id=promotion_id,
                            approved_date=datetime.now())
                        Profile_Invite.objects.create(
                            profile_id=profile_id,
                            invitation_id=new_invite.pk,
                            message=message)
                        plaintext = get_template(
                            'email/create_profile_invite.txt')
                        d = Context({'uid': new_invite.signup_key,
                                     'message': message,
                                     'first_name': p.first_name,
                                     'last_name': p.last_name})
                        text_content = plaintext.render(d)
                        queue_email(
                            USER_INVITE_SUBJECT,
                            text_content,
                            new_invite.email,
                            USER_INVITE_EVENT)
                        system_message = 'Invitation successfully created!'
                        invites_remaining = invites_remaining - 1
                except IntegrityError:
                    system_message = "Email already exists."
            else:
                system_message = "Form validation error."

    form = UserInviteForm()
    return render_to_response('collaboration_invite.html', {
                              'system_message': system_message,
                              'max_invitations': max_invitations,
                              'invites_remaining': invites_remaining,
                              'form': form
                              }, context_instance=RequestContext(request))
Ejemplo n.º 3
0
def item_new(request, ticket_id=None):
    system_message = None
    if request.POST:
        ticket_id = request.POST["ticket_id"]
        profile_id = request.session["profile_id"]
        ticket = Ticket.objects.get(pk=ticket_id)
        ticket_profile_id = ticket.profile_id
        subject = "RE: " + ticket.short_desc
        item_type_id = 1  # hard code to 1= internal
        form = ItemForm(request.POST)
        if form.is_valid():
            comment = form.cleaned_data["comment"]
            Item.objects.create(ticket_id=ticket_id, profile_id=profile_id, item_type_id=item_type_id, comment=comment)
            if profile_id == ticket_profile_id:
                # response from customer
                queue_internal_email_alert(subject, comment, SUPPORT_TICKET_CUSTOMER_REPLY)
            else:
                # reply from staff, send email to customer
                profile = Profile.objects.get(pk=ticket_profile_id)
                email = profile.email
                plaintext = get_template("email/support_response.txt")
                d = Context({"first_name": profile.first_name, "ticket_id": ticket_id, "comment": comment})
                text_content = plaintext.render(d)
                queue_email(subject, text_content, email, SUPPORT_TICKET_REPLY)
            system_message = "Reply added"
            return ticket_detail(request, ticket_id)

        else:
            system_message = "Error"
            return render_to_response(
                "support_item_new.html",
                {"system_message": system_message, "ticket_id": ticket_id, "form": form},
                context_instance=RequestContext(request),
            )

    else:
        form = ItemForm()

        return render_to_response(
            "support_item_new.html",
            {"system_message": system_message, "ticket_id": ticket_id, "form": form},
            context_instance=RequestContext(request),
        )
Ejemplo n.º 4
0
def email_confirm(request, confirm_key):
    try:
        p = Profile.objects.get(confirm_key=confirm_key)
        if p.is_confirmed:
            return render_to_response('system.html', {
                                      'system_message': 'Your account has already been confirmed.',
                                      }, context_instance=RequestContext(request))
        else:
            p.is_confirmed = True
            p.save()
            plaintext = get_template('email/confirmed.txt')
            d = Context({'first_name': p.first_name})
            text_content = plaintext.render(d)
            queue_email(ACCOUNT_CONFIRMED_SUBJECT,
                        text_content, p.email, ACCOUNT_CONFIRMED_EVENT)
            return render_to_response('system.html', {
                                      'system_message': 'Thank you, your account has been confirmed.',
                                      }, context_instance=RequestContext(request))
    except Profile.DoesNotExist:
        return render_to_response('system.html', {
                                  'system_message': 'Confirm Key not recognized.',
                                  }, context_instance=RequestContext(request))
Ejemplo n.º 5
0
def profile_add(request):
    if request.POST:
        system_message = None
        form = ProfileCreateForm(request.POST)
        terms = request.POST.getlist('agree')
        if len(terms) != 1:
            system_message = 'You must agree to our Terms of Service'
        else:

            if form.is_valid() == False:
                system_message = 'Form error'
            else:
                first_name = form.cleaned_data['first_name']
                last_name = form.cleaned_data['last_name']
                email = form.cleaned_data['email']
                password1 = form.cleaned_data['password1']
                password2 = form.cleaned_data['password2']
                if password1 != password2:
                    system_message = 'Passwords must be the same'
                else:
                    try:
                        test_profile = Profile.objects.get(email=email)
                        system_message = 'Email already exists.'
                    except Profile.DoesNotExist:
                        User.objects.create_user(email, email, password1)
                        #p = Profile.objects.create(first_name=first_name, last_name=last_name, email=email)
                        user = authenticate(username=email, password=password1)
                        login(request, user)
                        uid = uuid.uuid4()
                        user_profile = user.profile
                        request.session['profile_id'] = user_profile.id
                        user_profile.first_name = first_name
                        user_profile.last_name = last_name
                        user_profile.email = email
                        user_profile.confirm_key = uid
                        user_profile.save()
                        plaintext = get_template('email/confirm.txt')
                        d = Context({'first_name': first_name, 'uid': uid})
                        text_content = plaintext.render(d)
                        queue_email(
                            CONFIRM_ACCOUNT_SUBJECT,
                            text_content,
                            email,
                            PROFILE_CREATE_EVENT)
                        if 'invite_key' in request.POST:
                            invite_key = request.POST['invite_key']
                            invite = Invitation.objects.get(
                                signup_key=invite_key)
                            invite.profile_id = user_profile.id
                            invite.save()

                        return HttpResponseRedirect(
                            '/support/guide/?new_user=true')
    else:
        form = ProfileCreateForm()
        system_message = 'invalid request'

    return render_to_response('create_profile.html', {
                              'system_message': system_message,
                              'form': form
                              }, context_instance=RequestContext(request))