コード例 #1
0
ファイル: views.py プロジェクト: prologin/stechec-2011
def edit_champion(request, champion_id):
    champion = get_object_or_404(Champion, id=champion_id, auteur=request.user)

    if request.method == 'POST':
        form = ChampionUploadForm(request.POST, request.FILES)
        
        if form.is_valid():
            champion.statut = STATUT_CHAMPION_NOUVEAU
            champion.nom = form.cleaned_data['nom']
            champion.comment = form.cleaned_data['commentaire']

            save_champion(request, champion, form.cleaned_data['tarball'])

            champion.save()
            
            return render_to_response('upload-success.html')
    else:
        form = ChampionUploadForm(initial={'nom' : champion.nom, 'commentaire' : champion.comment})

    return render_to_response('upload-champion.html')
コード例 #2
0
ファイル: views.py プロジェクト: prologin/stechec-2011
def new_champion(request):
    if request.method == 'POST':
        form = ChampionUploadForm(request.POST, request.FILES)
        if form.is_valid():
            champion = Champion(
                    nom=form.cleaned_data['nom'],
                    auteur=request.user,
                    comment=form.cleaned_data['commentaire'],
                    statut=STATUT_CHAMPION_NOUVEAU)
            
            champion.save()
            
            try:
                save_champion(request, champion, form.cleaned_data['tarball'])
            except:
                champion.delete()
                raise
            
            return render_to_response('upload-success.html')
    else:
        form = ChampionUploadForm()
    
    return render_to_response('upload-champion.html')