Пример #1
0
def intake_form_answer(request, username):
    if not request.user.is_authenticated():
        return redirect('login_page')

    healer = get_object_or_404(Healer, user__username=username)
    if not is_my_client(healer.user, request.user):
        raise Http404
    intake_form = get_object_or_404(IntakeForm, healer=healer)

    form = IntakeFormAnswerForm(request.POST or None,
                                client=request.user.client,
                                intake_form=intake_form)

    success = False
    if form.is_valid():
        form.save()
        success = True
        if request.session.pop('concierge_request', False):
            return redirect(reverse('concierge_thanks', args=[username]))

    return render_to_response("intake_forms/answer.html", {
        'is_concierge': is_concierge(healer),
        'healer_name': unicode(healer.user.client),
        'form': form,
        'success': success
    },
                              context_instance=RequestContext(request))
Пример #2
0
def friend_bar_processor(request):
	if not request.friend_type:
		return {"other_user": request.other_user}

	context = friend_processor(request)
	other_user = request.other_user

	FriendClass, InvitationClass = get_friend_classes(request.friend_type)

	is_me = False
	is_client = False
	if request.user.is_authenticated():

		if request.friend_type == 'referrals':
			context['referal_to'] = Referrals.objects.refers_to(request.user, other_user)
			context['referal_from'] = Referrals.objects.refers_to(other_user, request.user)
			is_client = context['referal_to'] or is_my_client(request.user, other_user)

		else:
			is_client = is_my_client(other_user, request.user)

			previous_invitation_to = None
			if not is_client:
				previous_invitations_to = InvitationClass.objects.filter(
					to_user=other_user, from_user=request.user, status="2")
				if previous_invitations_to:
					previous_invitation_to = previous_invitations_to[0]

			context["previous_invitation_to"] = previous_invitation_to

		if request.user == other_user:
			is_me = True
		else:
			is_me = False

		#	previous_invitation_from = None
		#	previous_invitations_from = InvitationClass.objects.invitations(to_user=request.user, from_user=other_user, status="2")
		#	if previous_invitations_from:
		#		previous_invitation_from = previous_invitations_from[0].from_user

	context["is_me"] = is_me
	context["is_client"] = is_client
	context["other_user"] = other_user
	#	context["previous_invitation_from"] =  previous_invitation_from

	return context
Пример #3
0
def get_healer_info_context(healer, request):
	client = None
	client_id = ""
	request.friend_type = None
	is_profile_visible = True
	is_client = False
	try:
		client = clients.models.Client.objects.get(user__id=request.user.id)
		request.friend_type = 'referrals' if is_healer(client) else "healers"
		client_id = client.id
		is_client = is_my_client(healer.user, request.user)
	except ObjectDoesNotExist:
		pass

	is_profile_visible = healer.is_visible_to(request.user, is_client)

	if not is_profile_visible and not request.user.is_superuser:
		if request.user != healer.user:
			return is_client, False, {}

	locations = healer.get_locations(user=request.user, is_client=is_client,
		skip_center_locations=True)

	#	referring_users = [o['friend'] for o in Referrals.objects.referrals_to(healer.user)]
	#	healers = Healer.objects.filter(user__in=referring_users)
	#	referrals_to_me = [h.user for h in healers if h.is_visible_to(request.user)]
	referrals_to_me_count = Referrals.objects.referrals_to(healer.user, count=True)

	phones = clients.models.ClientPhoneNumber.objects.filter(client=healer)

	if request.user == healer.user:
		modalities = Modality.objects_approved.get_with_unapproved(healer=healer)
	else:
		modalities = Modality.objects_approved
	modalities = list(modalities.filter(healer=healer, visible=True))
	modalities.reverse()

	request.other_user = healer.user

	return is_client, True, {
		"healer": healer,
		"client": client,
		"client_id": client_id,
		"is_my_client": is_client,
		"locations": locations,
		"referrals_to_me_count": referrals_to_me_count,
		"phone": (phones[0].number if (len(phones) > 0) else ''),
		"modalities": modalities,
		"is_schedule_visible": healer.is_schedule_visible(request.user, is_client),
		"review_exist": healer.reviews.filter(reviewer__user=request.user).count() if request.user.is_authenticated() else False,
		"is_review_permission": healer.is_review_permission(request.user, is_client),
		}
Пример #4
0
        def import_contact(contact):
            user = None
            healer = get_object_or_404(Healer, user=request.user)
            first_name = contact['first name']
            last_name = contact['last name']
            email = contact['email']
            phone = contact.get('phone', None)

            # skip if there is no first name
            if first_name == '':
                return

            email = is_valid_email(email)
            if email:
                user = User.objects.filter(email__iexact=email)
                if user.exists():
                    user = user[0]

            if not user:
                user = create_dummy_user(first_name, last_name, email)

            # if can't find or create user, skip
            if not user:
                return

            is_client = is_my_client(healer.user, user)

            # if client created by healer
            if not is_client:
                friendship = Clients(from_user=healer.user, to_user=user)
                friendship.save()

            try:
                client = Client.objects.get(user=user)
            except ObjectDoesNotExist:
                client = Client(user=user)
                client.approval_rating = 100
                client.save()
            contact_info = client.get_contact_info(healer)
            if not contact_info:
                contact_info = ContactInfo.objects.create(
                    healer=healer,
                    client=client,
                    first_name=user.first_name,
                    last_name=user.last_name)
                contact_info.emails.add(ContactEmail(email=user.email))
            if phone:
                client.phone_numbers.add(ClientPhoneNumber(number=phone))
                contact_info.phone_numbers.add(ContactPhone(number=phone))
Пример #5
0
def client_detail(request, client_username):
    try:
        client = Client.objects.get(user__username__iexact=client_username)
    except Client.DoesNotExist:
        return HttpResponse("<h3>Oops!</h3>Sorry, couldn't find that Client")

    client_info = client.contact_info(separator='<br />', email_link=True)
    if request.user != client.user and not is_my_client(
            request.user, client.user):
        client_info = None

    contact_info = client.get_contact_info(request.user.client)
    contact_info_text = None
    if contact_info:
        contact_info_text = contact_info.text(separator='<br />',
                                              email_link=True)

    healer_link = None
    healer = is_healer(client)
    logged_in_healer = Healer.objects.get(user=request.user)
    if healer:
        healer_link = healer.healer_profile_url()

    c = {
        'has_intake_form':
        logged_in_healer.has_intake_form(),
        'client':
        client,
        'user':
        request.user,
        'client_info':
        client_info,
        'contact_info':
        contact_info,
        'contact_info_text':
        contact_info_text,
        'healer_link':
        healer_link,
        'answered_intake_form':
        client.answered_intake_form(is_healer(request.user)),
    }
    return render_to_response('clients/client_detail.html',
                              c,
                              context_instance=RequestContext(request))
Пример #6
0
def review_form(request, username, template_name="review/review_form.html"):
	healer = get_object_or_404(Healer, user__username__iexact=username)
	if not healer.is_review_permission(request.user):
		raise Http404

	reviewer = get_object_or_404(Client, user=request.user)
	try:
		review = Review.objects.filter(healer=healer, reviewer=reviewer)[0]
		notify = False
		title = 'Edit My Review for '
	except IndexError:
		review = None
		notify = True
		title = 'Write a Review for '
	title += str(healer.user.client)
	prev_rating = review.rating if review else None

	fb = request.GET.get('fb', False)
	if fb:
		template_name = "review/review_fb_form.html"

	form = ReviewForm(request.POST or None, instance=review)
	if form.is_valid():
		review = form.save(commit=False)
		review.healer = healer
		review.reviewer = reviewer
		review.save()
		if notify:
			review.notify()
		healer.update_rating(review.rating, prev_rating)
		if healer.review_permission == Healer.VISIBLE_EVERYONE and not is_my_client(healer.user, request.user):
			friend_process(request, 'clients', healer.user.id, 'invite')

		return redirect(reverse('review_form_success', args=[healer.user.username]) + ('?fb=1' if fb else ''))

	return render_to_response(template_name,
		{
			"title": title,
			"healer": healer,
			"form": form,
			"fb": fb
		},
		context_instance=RequestContext(request))
Пример #7
0
def invite_or_create_client_friendship(client_user, healer_user, send_client_request_email=False):
	#if the person is in my contacts list > auto add them, otherwise require a confirmation

	is_client = is_my_client(healer_user=healer_user, client_user=client_user)

	if is_client:
		return

	healer = is_healer(healer_user)
	if not healer:
		raise Healer.DoesNotExist

	contact = ContactEmail.objects.filter(email=client_user.email, contact__healer=healer).count()

	if healer.client_screening == Healer.SCREEN_ALL or \
		(healer.client_screening == Healer.SCREEN_NOT_CONTACTS and not contact):

		invitation_to = ClientInvitation.objects.filter(from_user=client_user, to_user=healer_user, status="2")

		if not invitation_to:
			invitation = ClientInvitation(from_user=client_user, to_user=healer_user, message="", status="2")
			invitation.save()

		if send_client_request_email:
			ctx = {
				"client_name": str(client_user.client),
				"accept_url": get_full_url('friend_accept', args=['clients', client_user.id]),
				"decline_url": get_full_url('friend_decline', args=['clients', client_user.id])
			}

			subject = render_to_string("friends/client_request_subject.txt", ctx)
			send_hs_mail(subject, "friends/client_request_message.txt", ctx, settings.DEFAULT_FROM_EMAIL, [healer_user.email])

	elif healer.client_screening == Healer.SCREEN_NONE or \
	     (healer.client_screening == Healer.SCREEN_NOT_CONTACTS and contact):

		Clients.objects.create(from_user=healer_user, to_user=client_user)

	else:
		raise Exception
Пример #8
0
    def post(self, request, format=None):
        try:
            data = request.POST['data'].encode('utf-8')
        except:
            return HttpResponseBadRequest()

        form = SendReferralForm(QueryDict(data))

        if not form.is_valid():
            errors = []
            for error in form.errors:
                css_class = '#referral_form #referral_%s'
                errors.append(css_class % error)
            return Response({'errors': errors})

        client_or_healer = form.cleaned_data['client_or_healer']
        from_user = get_object_or_404(
            User, username__iexact=form.cleaned_data['from_username'])
        to_user = form.cleaned_data['to_user']

        if client_or_healer == ReferralsSent.PROVIDER_TO_CLIENT:
            provider = from_user
            client = to_user
        else:
            provider = to_user
            client = from_user

        is_referral_sent = ReferralsSent.objects.filter(
            provider_user=provider,
            client_user=client,
            referring_user=request.user).count()

        if is_my_client(provider, client):
            message = "%s was already a client of %s." % (client.client,
                                                          provider.client)

        elif is_referral_sent:
            message = "You already referred %s to %s before." % (
                client.client, provider.client)

        else:
            mail_message = form.cleaned_data['message']

            ReferralsSent.objects.create(referring_user=request.user,
                                         provider_user=provider,
                                         client_user=client,
                                         message=mail_message)

            if client_or_healer == ReferralsSent.CLIENT_TO_PROVIDER:
                ctx = {
                    "SITE_NAME": settings.SITE_NAME,
                    "client": client,
                    "client_info": client.client.contact_info(),
                    "referer": request.user,
                    "mail_message": mail_message
                }
                subject = render_to_string(
                    "friends/refer_client_to_provider_subject.txt", ctx)
                send_hs_mail(subject,
                             "friends/refer_client_to_provider_message.txt",
                             ctx, settings.DEFAULT_FROM_EMAIL,
                             [provider.email])

                if not Referrals.objects.refers_to(provider, client):
                    Clients.objects.filter(from_user=request.user,
                                           to_user=provider).delete()
                    if not Referrals.objects.filter(from_user=request.user,
                                                    to_user=provider).exists():
                        friendship = Referrals.objects.create(
                            from_user=request.user, to_user=provider)
                        friendship.save()
            else:
                provider_profile = provider.client.healer
                friendship, is_profile_visible, ctx = get_healer_info_context(
                    provider_profile, request)
                ctx["info_only"] = True

                ctx.update({
                    "SITE_NAME": settings.SITE_NAME,
                    "STATIC_URL": settings.STATIC_URL,
                    "provider": provider_profile,
                    "referer": request.user,
                    "mail_message": mail_message
                })
                subject = render_to_string(
                    "friends/refer_provider_to_client_subject.txt", ctx)
                send_hs_mail(subject,
                             "friends/refer_provider_to_client_message.txt",
                             ctx,
                             settings.DEFAULT_FROM_EMAIL, [client.email],
                             html_template_name=
                             "friends/refer_provider_to_client_message.html")

            #update refers model

            message = "You refered %s to %s." % (client.client,
                                                 provider.client)

        return Response(message)