def edit_media(request):
    recipient = request.user.get_profile().recipient
    substate_menu_items = _organizer_submenu(request, "media", recipient)
    submenu_id = "organizer_submenu"
    
    FormKlass = get_form(Recipient, EDIT_TYPE, includes=('logo',
                                                         'promotional_video',
                                                         'pd_experience_video'))

    if request.POST:
        form = FormKlass(request.POST, request.FILES, instance=recipient)
        if form.is_valid():
            form.save()
            request.user.message_set.create(message='Changes saved')
            arrow_direction = request.POST.get("arrow_direction", None)
            if arrow_direction and arrow_direction == "prev":
                return HttpResponseRedirect(reverse('edit_private_information'))
            elif arrow_direction and arrow_direction == "next":
                return HttpResponseRedirect(reverse('edit_promo_cards'))
            else:
                return HttpResponseRedirect(reverse('edit_media'))
    else:
        form = FormKlass(instance=recipient)

    return render_response(request, 'procrasdonate/recipient_organizer_pages/edit_media.html', locals())
def edit_public_information(request):
    recipient = request.user.get_profile().recipient
    substate_menu_items = _organizer_submenu(request, "public", recipient)
    submenu_id = "organizer_submenu"
        
    FormKlass = get_form(Recipient, EDIT_TYPE, includes=('name',
                                                         'category',
                                                         'mission',
                                                         'description',
                                                         'url'))

    if request.POST:
        form = FormKlass(request.POST, instance=recipient)
        if form.is_valid():
            form.save()
            request.user.message_set.create(message='Changes saved')
            arrow_direction = request.POST.get("arrow_direction", None)
            if arrow_direction and arrow_direction == "prev":
                return HttpResponseRedirect(reverse('payment_registration'))
            elif arrow_direction and arrow_direction == "next":
                return HttpResponseRedirect(reverse('edit_private_information'))
            else:
                return HttpResponseRedirect(reverse('edit_public_information'))
    else:
        form = FormKlass(instance=recipient)

    return render_response(request, 'procrasdonate/recipient_organizer_pages/edit_public_information.html', locals())
def register_organizer(request):
    RecipientUserTaggingForm = get_form(RecipientUserTagging, EDIT_TYPE, excludes=('user',
                                                                                   'is_confirmed',
                                                                                   'confirmation_code'))
    RecipientUserForm = get_form(RecipientUser, EDIT_TYPE, includes=('username',
                                                                     'first_name',
                                                                     'last_name',
                                                                     'email'))
    recipients = Recipient.objects.all()

    if request.POST:
        recipient_user_tagging_form = RecipientUserTaggingForm(request.POST)
        recipient_user_form = RecipientUserForm(request.POST)
        
        if recipient_user_tagging_form.is_valid() and recipient_user_form.is_valid():
            user = recipient_user_form.save()
            user.set_unusable_password()
            user.is_active = False
            user.save()
            
            fake_tagging = recipient_user_tagging_form.save(commit=False)
            tagging = RecipientUserTagging.add(user, fake_tagging.recipient, require_confirmation=True) 
            del fake_tagging

            # send email for recipient user to login
            c = Context({'user': user,
                         'recipient': tagging.recipient,
                         'site_url': "http://ProcrasDonate.com",
                         'confirmation_link': "%s" % (reverse('confirm',
                                                              args=(user.username,
                                                                    tagging.confirmation_code))),
                         'confirmation_code': tagging.confirmation_code,
                         'expiration_days': 14 })
            t = loader.get_template('procrasdonate/recipient_organizer_pages/account/confirmation_email.txt')
            tagging.send_email("Welcome to ProcrasDonate! Please complete registration for %s" % tagging.recipient.name,
                               t.render(c),
                               from_email=settings.EMAIL)
            
            request.user.message_set.create(message='RecipientUser successfully registered')
            return HttpResponseRedirect(reverse('home'))
    else:
        recipient_user_tagging_form = RecipientUserTaggingForm()
        recipient_user_form = RecipientUserForm()

    return render_response(request, 'procrasdonate/recipient_organizer_pages/account/register.html', locals())
def edit_private_information(request):
    recipient = request.user.get_profile().recipient
    substate_menu_items = _organizer_submenu(request, "private", recipient)
    submenu_id = "organizer_submenu"
    
    FormKlass = get_form(Recipient, EDIT_TYPE, includes=('employers_identification_number',
                                                         'tax_exempt_status',
                                                         'sponsoring_organization',
                                                         'office_phone',
                                                         'mailing_address',
                                                         'city',
                                                         'state',
                                                         'country'))
    
    RU_FormKlass = get_form(RecipientUser, EDIT_TYPE, includes=('first_name', 'last_name', 'email'))

    if request.POST:
        form = FormKlass(request.POST, instance=recipient)
        ru_form = RU_FormKlass(request.POST, instance=request.user)
        
        if form.is_valid() and ru_form.is_valid():
            form.save()
            ru_form.save()
            request.user.message_set.create(message='Changes saved')
            arrow_direction = request.POST.get("arrow_direction", None)
            if arrow_direction and arrow_direction == "prev":
                return HttpResponseRedirect(reverse('edit_public_information'))
            elif arrow_direction and arrow_direction == "next":
                return HttpResponseRedirect(reverse('edit_media'))
            else:
                return HttpResponseRedirect(reverse('edit_private_information'))
    else:
        form = FormKlass(instance=recipient)
        ru_form = RU_FormKlass(instance=request.user)

    return render_response(request, 'procrasdonate/recipient_organizer_pages/edit_private_information.html', locals())
def _edit_recipient_something(request, includes, template):
    """
    could use this but.... edit_foo's are likely to become more complicated with amazon auth and video stuff....
    """
    recipient = request.user.get_profile().recipient
        
    FormKlass = get_form(Recipient, EDIT_TYPE, includes=includes)

    if request.POST:
        form = FormKlass(request.POST, instance=recipient)
        if form.is_valid():
            form.save()
            request.user.message_set.create(message='Changes saved')
            return HttpResponseRedirect(reverse('recipient', args=(recipient.slug,)))
    else:
        form = FormKlass(instance=recipient)

    return render_response(request, template, locals())
def register_organizer(request):
    RecipientUserTaggingForm = get_form(RecipientUserTagging,
                                        EDIT_TYPE,
                                        excludes=('user', 'is_confirmed',
                                                  'confirmation_code'))
    RecipientUserForm = get_form(RecipientUser,
                                 EDIT_TYPE,
                                 includes=('username', 'first_name',
                                           'last_name', 'email'))
    recipients = Recipient.objects.all()

    if request.POST:
        recipient_user_tagging_form = RecipientUserTaggingForm(request.POST)
        recipient_user_form = RecipientUserForm(request.POST)

        if recipient_user_tagging_form.is_valid(
        ) and recipient_user_form.is_valid():
            user = recipient_user_form.save()
            user.set_unusable_password()
            user.is_active = False
            user.save()

            fake_tagging = recipient_user_tagging_form.save(commit=False)
            tagging = RecipientUserTagging.add(user,
                                               fake_tagging.recipient,
                                               require_confirmation=True)
            del fake_tagging

            # send email for recipient user to login
            c = Context({
                'user':
                user,
                'recipient':
                tagging.recipient,
                'site_url':
                "http://ProcrasDonate.com",
                'confirmation_link':
                "%s" %
                (reverse('confirm',
                         args=(user.username, tagging.confirmation_code))),
                'confirmation_code':
                tagging.confirmation_code,
                'expiration_days':
                14
            })
            t = loader.get_template(
                'procrasdonate/recipient_organizer_pages/account/confirmation_email.txt'
            )
            tagging.send_email(
                "Welcome to ProcrasDonate! Please complete registration for %s"
                % tagging.recipient.name,
                t.render(c),
                from_email=settings.EMAIL)

            request.user.message_set.create(
                message='RecipientUser successfully registered')
            return HttpResponseRedirect(reverse('home'))
    else:
        recipient_user_tagging_form = RecipientUserTaggingForm()
        recipient_user_form = RecipientUserForm()

    return render_response(
        request,
        'procrasdonate/recipient_organizer_pages/account/register.html',
        locals())