예제 #1
0
def edit_team_page(request, page_id):
    team_page = TeamPage.objects.select_related('image').get(pk=page_id)
    form = EditTeamForm(initial=team_page.__dict__, image=team_page.image)

    if request.method == 'POST':
        form = EditTeamForm(request.POST,
                            team_id=team_page.id,
                            image=team_page.image)

        if form.is_valid():

            upload_form = UploadForm(request.POST, request.FILES)
            uploaded_file_model = None
            if upload_form.is_valid():
                uploaded_file_model = upload_form.save()

            data = form.cleaned_data
            team_page.name = data.get('name')
            team_page.contact_details = data.get('contact_details')
            team_page.free_text = data.get('free_text')
            if uploaded_file_model:
                team_page.image = uploaded_file_model
            team_page.save()
            return HttpResponseRedirect('/team/%s' % page_id)

    return render(
        request, 'spudderspuds/teams/pages/edit_team.html', {
            'page': team_page,
            'form': form,
            'upload_url': blobstore.create_upload_url(
                '/team/%s/edit' % page_id)
        })
예제 #2
0
def edit_team_page(request, page_id):
    team_page = TeamPage.objects.select_related('image').get(pk=page_id)
    form = EditTeamForm(initial=team_page.__dict__, image=team_page.image)

    if request.method == 'POST':
        form = EditTeamForm(request.POST, team_id=team_page.id, image=team_page.image)

        if form.is_valid():

            upload_form = UploadForm(request.POST, request.FILES)
            uploaded_file_model = None
            if upload_form.is_valid():
                uploaded_file_model = upload_form.save()

            data = form.cleaned_data
            team_page.name = data.get('name')
            team_page.contact_details = data.get('contact_details')
            team_page.free_text = data.get('free_text')
            if uploaded_file_model:
                team_page.image = uploaded_file_model
            team_page.save()
            return HttpResponseRedirect('/team/%s' % page_id)

    return render(request, 'spudderspuds/teams/pages/edit_team.html', {
        'page': team_page,
        'form': form,
        'upload_url': blobstore.create_upload_url('/team/%s/edit' % page_id)
    })
예제 #3
0
def fan_profile_edit(request, page_id):
    fan_page = get_object_or_404(FanPage, pk=page_id)
    profile_form = FanPageForm(initial=fan_page.__dict__, image=fan_page.avatar)
    social_accounts_form = BasicSocialMediaForm(initial=fan_page.__dict__)
    if request.method == 'POST':
        profile_form = FanPageForm(request.POST, image=fan_page.avatar)
        social_accounts_form = BasicSocialMediaForm(request.POST)
        if profile_form.is_valid() and social_accounts_form.is_valid():
            for attr in ('name', 'date_of_birth', 'state', ):
                fan_page.__setattr__(attr, profile_form.cleaned_data[attr])

            set_social_media(fan_page, social_accounts_form)

            upload_form = UploadForm(request.POST, request.FILES)
            if upload_form.is_valid():
                fan_page.avatar = upload_form.save()

            fan_page.save()
        redirect_to = request.session.pop('redirect_after_auth', '/fan/%s' % fan_page.id)
        return redirect(redirect_to)
    return render(request, 'spudderspuds/fans/pages/fan_page_edit.html', {
        'profile_form': profile_form,
        'social_accounts_form': social_accounts_form,
        'page': fan_page,
        'new_registration': request.GET.get('new_registration', False),
        'upload_url': blobstore.create_upload_url('/fan/%s/edit' % page_id)
    })
예제 #4
0
def fan_profile_edit(request, page_id):
    fan_page = get_object_or_404(FanPage, pk=page_id)
    profile_form = FanPageForm(initial=fan_page.__dict__,
                               image=fan_page.avatar)
    social_accounts_form = BasicSocialMediaForm(initial=fan_page.__dict__)
    if request.method == 'POST':
        profile_form = FanPageForm(request.POST, image=fan_page.avatar)
        social_accounts_form = BasicSocialMediaForm(request.POST)
        if profile_form.is_valid() and social_accounts_form.is_valid():
            for attr in (
                    'name',
                    'date_of_birth',
                    'state',
            ):
                fan_page.__setattr__(attr, profile_form.cleaned_data[attr])

            set_social_media(fan_page, social_accounts_form)

            upload_form = UploadForm(request.POST, request.FILES)
            if upload_form.is_valid():
                fan_page.avatar = upload_form.save()

            fan_page.save()
        redirect_to = request.session.pop('redirect_after_auth',
                                          '/fan/%s' % fan_page.id)
        return redirect(redirect_to)
    return render(
        request, 'spudderspuds/fans/pages/fan_page_edit.html', {
            'profile_form': profile_form,
            'social_accounts_form': social_accounts_form,
            'page': fan_page,
            'new_registration': request.GET.get('new_registration', False),
            'upload_url': blobstore.create_upload_url('/fan/%s/edit' % page_id)
        })