Пример #1
0
def register(request):
    form = ChallengesRegisterForm(
        initial=request.GET,
        enable_register_club=feature_is_enabled('challenge_register_club'))
    if request.method == "POST":
        form = ChallengesRegisterForm(
            request.POST,
            enable_register_club=feature_is_enabled('challenge_register_club'))
        if form.is_valid():
            username = form.cleaned_data.get('email_address')
            password = form.cleaned_data.get('password')
            user = User.objects.create_user(username, username, password)
            user.save()
            user.spudder_user.mark_password_as_done()
            fan_entity = create_and_activate_fan_role(request, user)
            fan_page = fan_entity.entity
            fan_page.username = form.cleaned_data.get('username')
            fan_page.state = str(
                request.META.get('HTTP_X_APPENGINE_REGION')).upper()
            fan_page.save()
            login(request, authenticate(username=username, password=password))
            if feature_is_enabled('tracking_pixels'):
                EventController.RegisterEvent(
                    request, EventController.CHALLENGER_USER_REGISTERER)
            if form.cleaned_data.get(
                    'account_type') == EntityController.ENTITY_CLUB:
                return redirect('/challenges/register/team?next=%s' %
                                form.cleaned_data.get('next', '/'))
            return redirect(form.cleaned_data.get('next', '/'))
    return render(request, 'spudderspuds/challenges/pages/register.html',
                  {'form': form})
Пример #2
0
def challenge_challenge_accept_notice(request,
                                      state=None,
                                      club_entity_type=None,
                                      club_id=None,
                                      participation_id=None):
    if state and club_entity_type and club_id:
        ccp = ChallengeChallengeParticipation(
            participating_entity_id=request.current_role.entity.id,
            participating_entity_type=request.current_role.entity_type,
            recipient_entity_id=club_id,
            recipient_entity_type=club_entity_type)
        ccp.save()
        return redirect('/challenges/challenge_challenge/%s/upload' % ccp.id)
    participation = get_object_or_404(ChallengeChallengeParticipation,
                                      id=participation_id)
    form = ChallengeChallengeParticipationForm()
    upload_url = '/challenges/challenge_challenge/%s/upload' % participation_id
    if request.method == 'POST':
        form = ChallengeChallengeParticipationForm(request.POST)
        if form.is_valid():
            participation.youtube_video_id = form.cleaned_data.get(
                'youtube_video_id')
            participation.name = form.cleaned_data.get('challenge_name')
            participation.description = form.cleaned_data.get(
                'challenge_description')
            participation.state = ChallengeChallengeParticipation.STATE_COMPLETE
            if request.FILES:
                file = UploadForm(request.POST, request.FILES).save()
                participation.image = file
            participation.save()
            redirect_url = '/challenges/challenge_challenge/%s/thanks?just_submitted=True' % participation_id
            if feature_is_enabled('tracking_pixels'):
                EventController.RegisterEvent(
                    request, EventController.CHALLENGE_ACCEPTED)
            if request.is_ajax():
                return HttpResponse(redirect_url)
            return redirect(redirect_url)
        if request.is_ajax():
            return HttpResponse(
                "%s|%s" %
                (blobstore.create_upload_url(upload_url), '<br/>'.join([
                    '<br/>'.join([_e for _e in e])
                    for e in form.errors.values()
                ])))
    template_data = {
        'form': form,
        'upload_url': blobstore.create_upload_url(upload_url)
    }
    return render(
        request,
        'spudderspuds/challenges/pages/challenge_challenge_accept_upload.html',
        template_data)
Пример #3
0
def _state_engine_process_upload(request, challenge, engine, state,
                                 template_data):
    response = None
    template = challenge.template
    beneficiary = EntityController.GetWrappedEntityByTypeAndId(
        challenge.recipient_entity_type, challenge.recipient_entity_id,
        EntityBase.EntityWrapperByEntityType(challenge.recipient_entity_type))
    participation = ChallengeParticipation.objects.get(
        challenge=challenge,
        participating_entity_id=request.current_role.entity.id,
        participating_entity_type=request.current_role.entity_type)
    redirect_url = '/challenges/%s/%s/4?just_pledged=True' % (challenge.id,
                                                              engine)
    action_upload_image = 'upload_image'
    image_form = UploadImageForm(initial={'action': action_upload_image})
    upload_url = '/challenges/%s/accept' % challenge.id
    if request.method == 'POST':
        action = request.POST.get('action')
        if action == action_upload_image:
            if request.FILES:
                upload_form = UploadForm(request.POST, request.FILES)
                file = upload_form.save()
                participation.image = file
                participation.state = ChallengeParticipation.ACCEPTED_STATE
                participation.state_engine = engine
                participation.save()
                if feature_is_enabled('tracking_pixels'):
                    EventController.RegisterEvent(
                        request, EventController.CHALLENGE_ACCEPTED)
            if request.is_ajax():
                response = HttpResponse(redirect_url)
                return response, state
            response = redirect(redirect_url)
            return response, state
        if request.is_ajax():
            response = HttpResponse(
                "%s|%s" %
                (blobstore.create_upload_url(upload_url), '<br/>'.join([
                    '<br/>'.join([_e for _e in e])
                    for e in image_form.errors.values()
                ])))
            return response, state
    template_data['template'] = template
    template_data['beneficiary'] = beneficiary
    template_data['participation'] = participation
    template_data['redirect_url'] = redirect_url
    template_data['upload_url'] = blobstore.create_upload_url(upload_url)
    response = render(
        request,
        'spudderspuds/challenges/pages_ajax/challenge_accept_upload.html',
        template_data)
    return response, state
Пример #4
0
def dashboard(request):
    club, club_entity = get_club_and_club_entity(request)
    stripe_controller = get_stripe_recipient_controller_for_club(club)
    if not stripe_controller:
        if EventController.PopEvent(request, EventController.CLUB_REGISTERED):
            messages.success(
                request,
                "You are almost finished registering %s, just one more step to go." % club_entity.name)
        return redirect('/club/dashboard/stripe-connect')
    template_data = {
        'stripe': stripe_controller,
        'club_entity': club_entity}
    return render(request, 'spudderspuds/clubs/pages/dashboard.html', template_data)
def tracking_pixel_code_context(request):
    """
    Looks for a TRACKING_PIXEL_CONF dict in the events file
    and if the event (dict key) has a list of template names
    then these are added to the context as {{ tracking_pixel_code }}
    """
    tracking_pixel_code = ""
    if feature_is_enabled('tracking_pixels'):
        for event in TRACKING_PIXEL_CONF.keys():
            if EventController.PopEvent(request, event):
                templates = TRACKING_PIXEL_CONF.get(event, [])
                for template in templates:
                    tracking_pixel_code += render_to_string(template)
    return {'tracking_pixel_code': tracking_pixel_code}
Пример #6
0
def _state_engine_process_register(request, challenge, engine, state,
                                   template_data):
    response = None
    next_state = _StateEngineStates.NOTICE
    if engine == "pledge-only":
        next_state = _StateEngineStates.PLEDGE
    if request.current_role:
        state = next_state
    else:
        form = FanRegisterForm()
        if request.method == "POST":
            form = FanRegisterForm(request.POST)
            if form.is_valid():
                username = form.cleaned_data.get('email_address')
                password = form.cleaned_data.get('password')
                user = User.objects.create_user(username, username, password)
                user.save()
                user.spudder_user.mark_password_as_done()
                fan_entity = create_and_activate_fan_role(request, user)
                request.current_role = fan_entity
                fan_page = fan_entity.entity
                fan_page.username = create_at_name_from_email_address(username)
                fan_page.state = form.cleaned_data.get('state')
                fan_page.save()
                user = authenticate(username=username, password=password)
                login(request, user)
                if feature_is_enabled('tracking_pixels'):
                    EventController.RegisterEvent(
                        request, EventController.CHALLENGER_USER_REGISTERER)
                state = next_state
                response = redirect('/challenges/%s/%s/%s' %
                                    (challenge.id, engine, state))
        if state == _StateEngineStates.REGISTER:
            template_data['form'] = form
            response = render(
                request, 'spudderspuds/challenges/pages_ajax/register.html',
                template_data)
    return response, state
Пример #7
0
def fan_register(request):
    # Should the current_role be here?
    should_be_here, response = should_current_role_be_here(request)
    if not should_be_here:
        return response

    # Extract an invitation if there is one
    invitation = extract_invitation_from_request(request)

    template_data = {'tab': request.GET.get('tab', 'fan')}
    form = FanRegisterForm(initial=request.GET)
    club_form = RegisterClubWithFanForm()

    if request.method == "POST":
        is_valid = True
        tab = request.POST.get('tab')
        template_data['tab'] = tab

        if tab == 'org':
            club_form = RegisterClubWithFanForm(request.POST)
            is_valid = club_form.is_valid()

        form = FanRegisterForm(request.POST)
        if is_valid and form.is_valid():
            # Get the form data
            username = form.cleaned_data.get('email_address')
            password = form.cleaned_data.get('password')
            state = form.cleaned_data.get('state')
            # Create the auth.User
            user = User.objects.create_user(username, username, password)
            user.save()
            user.spudder_user.mark_password_as_done()
            # Create the Fan
            fan_role = create_and_activate_fan_role(request, user)
            request.current_role = fan_role
            fan_page = fan_role.entity
            fan_page.state = state
            at_name = create_at_name_from_email_address(username)
            fan_page.username = at_name
            fan_page.save()
            # Login the user
            login(request, authenticate(username=username, password=password))
            is_signin_claiming_spud(request, fan_role.entity,
                                    form.cleaned_data.get('twitter', None),
                                    form.cleaned_data.get('spud_id', None))
            if invitation:
                if invitation.invitation_type == Invitation.REGISTER_AND_ADMINISTRATE_TEAM_INVITATION:
                    team_admin = TeamAdministrator(
                        entity_type=fan_role.entity_type,
                        entity_id=fan_role.entity.id)
                    team_admin.team_page_id = invitation.target_entity_id
                    team_admin.save()
                    invitation.status = Invitation.ACCEPTED_STATUS
                    invitation.save()
                elif invitation.invitation_type == Invitation.AFFILIATE_INVITE_CLUB_ADMINISTRATOR:
                    fan_role.entity.affiliate = Affiliate.objects.get(
                        name=invitation.extras['affiliate_name'])
                    return HttpResponseRedirect(
                        '/spudderaffiliates/invitation/%s/create_club' %
                        invitation.id)
                return redirect('/fan/follow?origin=invitation')
            if tab == 'org':
                # Get the form data
                club_name = club_form.cleaned_data.get('name')
                # Create the club
                club = Club(name=club_name, state=state)
                club.save()
                # Create the club admin
                club_admin = ClubAdministrator(club=club, admin=user)
                club_admin.save()
                club_admin_role = change_current_role(
                    request, RoleController.ENTITY_CLUB_ADMIN, club_admin.id)
                request.current_role = club_admin_role
                EventController.RegisterEvent(request,
                                              EventController.CLUB_REGISTERED)
            return redirect(request.current_role.home_page_path)

    template_data["form"] = form
    template_data['club_form'] = club_form
    return render(request, 'spudderspuds/pages/user_register.html',
                  template_data)