예제 #1
0
def thankyou(request):
    new_member = get_current_member(request)
    new_circle = get_current_circle(request)

    context = {"member":new_member,
               "circle":new_circle,
               "circle_owner":new_circle.circle_owner_name(),
               "circle_members":new_circle.member_set.all(),
               "circle_members_len":"n" + str(new_circle.member_set.count())}
    return render(request, "circly/thankyou.html", context)
예제 #2
0
def submitcircle(request):
    new_member = get_current_member(request)
    new_circle = get_current_circle(request)

    count = 2
    posted_members = {}

    custom_errors = ""

    while count <= settings.CIRCLE_MAX_SIZE:
        member_contact = {}

        current_name = request.POST.get("name_" + str(count), None)
        current_contact = request.POST.get("contact_" + str(count), None)

        if (current_name):
            if (current_contact):
                # Check to see if current contact info is valid phone or email
                if is_phone(current_contact):
                    member_contact["contact_type"] = "phone"

                if is_email(current_contact):
                    member_contact["contact_type"] = "email"

                if not is_phone(current_contact) and not is_email(current_contact):
                    # Bad data error
                    custom_errors += "<li>contact_" + str(count) + " must be either a valid phone number OR email</li>"

                member_contact["contact_info"] = current_contact

                posted_members[current_name] = member_contact
            else:
                # Missing contact data error
                custom_errors += "<li>name_" + str(count) + " is present but contact_" + str(count) + " is missing</li>"
        else:
            if len(posted_members) < (settings.CIRCLE_MIN_SIZE - 1):
                # Missing name data error
                custom_errors += "<li>name_" + str(count) + " is missing</li>"

        count += 1

    # Check to see if we have minimum more members added
    if len(posted_members) < (settings.CIRCLE_MIN_SIZE - 1):
        custom_errors += "<li>You need at least " + str(settings.CIRCLE_MIN_SIZE) + " members (including yourself) in your circle</li>"

    if custom_errors != "":
        custom_errors = format_html("<p><ul>{}</ul></p>",
                                    mark_safe(custom_errors))

        # If there are any errors, kick out and display them
        context = {"member":new_member, "num_range_str":settings.CONTACT_RANGE_STR, "custom_errors":custom_errors, }
        return render(request, "circly/network.html", context)

    for each_member in posted_members.keys():
        # Create new members and add to the circle
        if (posted_members[each_member]["contact_type"] == "email"):
            next_member = Member(circle=new_circle,
                                 circle_owner=False,
                                 member_name=each_member,
                                 member_email=posted_members[each_member]["contact_info"],
                                 member_created_date=timezone.now(), )
        elif (posted_members[each_member]["contact_type"] == "phone"):
            new_phone = phonenumbers.parse(posted_members[each_member]["contact_info"], "US")
            new_phone = phonenumbers.format_number(new_phone, phonenumbers.PhoneNumberFormat.E164)

            next_member = Member(circle=new_circle,
                                 circle_owner=False,
                                 member_name=each_member,
                                 member_phone=new_phone,
                                 member_created_date=timezone.now(), )

        next_member.save()

        # Create invite code with short link for profile sign up
        invite_code = hash_code(posted_members[each_member]["contact_info"])

        invite_url = "http://www.circly.org/invite/" + invite_code
        new_short_url = random_bitly(invite_url)

        invite = Invitation(member=next_member,
                            invite_code=invite_code, 
                            invite_short_url=new_short_url, 
                            invite_created_date=timezone.now(),
                            invite_send_date=timezone.now())
        invite.save()

        # Create reminders for all new members to join the circle
        remind = Reminder(member=next_member,
                          reminder_subject=new_circle.circle_owner_name() + " would like you to join their circle of support",
                          reminder_message="Hey " + each_member + ", visit " + new_short_url + " to fill in your profile and join a circle of preventive care.",
                          reminder_created_date=timezone.now(),
                          reminder_send_date=timezone.now(), )
        remind.save()

    if new_member.member_email:
        owner_hash = hash_code(new_member.member_email)

    if new_member.member_phone:
        owner_hash = hash_code(new_member.member_phone)

    dashboard_url = "http://www.circly.org/dashboard/" + owner_hash
    new_short_dashboard_url = random_bitly(dashboard_url)

    new_circle.circle_short_url = new_short_dashboard_url
    new_circle.save()

    set_member_and_circle(request, new_circle, new_member)

    return HttpResponseRedirect(reverse("connect:dashboard", 
                                        kwargs={"owner_hash":owner_hash}))